mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-04-28 11:59:29 +00:00
fix(cli): use tryCatch for JSON.parse in loadPreferredModel (#2782)
tryCatchIf(isFileError) only catches filesystem errors (ENOENT, EACCES),
but JSON.parse throws SyntaxError on corrupted preferences.json. This
was the same bug fixed in 16a2f180 across 4 files, but orchestrate.ts
was missed. A corrupted ~/.spawn/preferences.json would crash the CLI
instead of gracefully falling back to no preferred model.
Agent: code-health
Co-authored-by: B <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b0ecb3a139
commit
15a62a9ad0
2 changed files with 3 additions and 3 deletions
|
|
@ -15,7 +15,7 @@ import { tryTarballInstall } from "./agent-tarball";
|
|||
import { generateEnvConfig } from "./agents";
|
||||
import { getOrPromptApiKey } from "./oauth";
|
||||
import { getSpawnPreferencesPath } from "./paths";
|
||||
import { asyncTryCatch, asyncTryCatchIf, isFileError, isOperationalError, tryCatchIf } from "./result.js";
|
||||
import { asyncTryCatch, asyncTryCatchIf, isOperationalError, tryCatch } from "./result.js";
|
||||
import { isWindows } from "./shell";
|
||||
import { startSshTunnel } from "./ssh";
|
||||
import { ensureSshKeys, getSshKeyOpts } from "./ssh-keys";
|
||||
|
|
@ -94,7 +94,7 @@ const PreferencesSchema = v.object({
|
|||
});
|
||||
|
||||
function loadPreferredModel(agentName: string): string | null {
|
||||
const result = tryCatchIf(isFileError, () => {
|
||||
const result = tryCatch(() => {
|
||||
const raw = JSON.parse(readFileSync(getSpawnPreferencesPath(), "utf-8"));
|
||||
const parsed = v.safeParse(PreferencesSchema, raw);
|
||||
if (!parsed.success) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue