refactor: consolidate remaining error ternaries (error variable)
Replace all remaining inline error ternaries using the 'error' variable name with getErrorMessage(error). Added imports to 3 files that lacked it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
04322f110a
commit
dac14043cd
5 changed files with 21 additions and 19 deletions
|
|
@ -136,7 +136,7 @@ export async function handleDebug(args, ctx, pi) {
|
|||
}
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const message = getErrorMessage(error);
|
||||
ctx.ui.notify(
|
||||
`Unable to create debug session: ${message}\nTry /debug --diagnose for artifact health details.`,
|
||||
"error",
|
||||
|
|
@ -174,7 +174,7 @@ export async function handleDebug(args, ctx, pi) {
|
|||
}
|
||||
ctx.ui.notify(lines.join("\n"), "info");
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const message = getErrorMessage(error);
|
||||
ctx.ui.notify(
|
||||
`Unable to list debug sessions: ${message}\nRun /debug --diagnose for details.`,
|
||||
"warning",
|
||||
|
|
@ -208,7 +208,7 @@ export async function handleDebug(args, ctx, pi) {
|
|||
"info",
|
||||
);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const message = getErrorMessage(error);
|
||||
ctx.ui.notify(
|
||||
`Unable to load debug session '${parsed.slug}': ${message}\nTry /debug --diagnose ${parsed.slug}`,
|
||||
"warning",
|
||||
|
|
@ -373,7 +373,7 @@ export async function handleDebug(args, ctx, pi) {
|
|||
}
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const message = getErrorMessage(error);
|
||||
ctx.ui.notify(
|
||||
`Unable to continue debug session '${parsed.slug}': ${message}\nTry /debug --diagnose ${parsed.slug}`,
|
||||
"warning",
|
||||
|
|
@ -427,7 +427,7 @@ export async function handleDebug(args, ctx, pi) {
|
|||
}
|
||||
}
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const message = getErrorMessage(error);
|
||||
ctx.ui.notify(
|
||||
`Unable to create diagnose session: ${message}\nTry /debug --diagnose for artifact health details.`,
|
||||
"error",
|
||||
|
|
@ -484,7 +484,7 @@ export async function handleDebug(args, ctx, pi) {
|
|||
listed.malformed.length > 0 ? "warning" : "info",
|
||||
);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const message = getErrorMessage(error);
|
||||
ctx.ui.notify(`Diagnose failed: ${message}`, "error");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { existsSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
|
|||
import { join } from "node:path";
|
||||
import { atomicWriteSync } from "./atomic-write.js";
|
||||
import { sfRoot } from "./paths.js";
|
||||
import { getErrorMessage } from "./error-utils.js";
|
||||
|
||||
const DEFAULT_PHASE = "queued";
|
||||
const DEFAULT_STATUS = "active";
|
||||
|
|
@ -126,7 +127,7 @@ function parseDebugSessionArtifact(filePath, raw) {
|
|||
try {
|
||||
parsed = JSON.parse(raw);
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const message = getErrorMessage(error);
|
||||
throw new Error(
|
||||
`Failed to parse debug session artifact ${filePath}: ${message}`,
|
||||
);
|
||||
|
|
@ -218,7 +219,7 @@ export function listDebugSessions(basePath, deps = {}) {
|
|||
} catch (error) {
|
||||
malformed.push({
|
||||
artifactPath,
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
message: getErrorMessage(error),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ function parseJsonl(content) {
|
|||
try {
|
||||
JSON.parse(line);
|
||||
} catch (error) {
|
||||
const msg = error instanceof Error ? error.message : String(error);
|
||||
const msg = getErrorMessage(error);
|
||||
return `line ${i + 1}: ${msg}`;
|
||||
}
|
||||
}
|
||||
|
|
@ -206,7 +206,7 @@ function parseMarkdownFrontmatter(content) {
|
|||
parseYaml(frontmatter);
|
||||
return null;
|
||||
} catch (error) {
|
||||
return error instanceof Error ? error.message : String(error);
|
||||
return getErrorMessage(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -295,7 +295,7 @@ function checkSfFormSyntax(basePath, issues, fixesApplied, shouldFix) {
|
|||
parseError = parseMarkdownFrontmatter(content);
|
||||
}
|
||||
} catch (error) {
|
||||
parseError = error instanceof Error ? error.message : String(error);
|
||||
parseError = getErrorMessage(error);
|
||||
}
|
||||
if (parseError) {
|
||||
const repaired = repairSfFormContent(ext, content);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|||
import { join } from "node:path";
|
||||
import { atomicWriteSync } from "./atomic-write.js";
|
||||
import { sfRoot } from "./paths.js";
|
||||
import { getErrorMessage } from "./error-utils.js";
|
||||
/** Schema version for production mutation approval JSON artifacts. */
|
||||
export const PRODUCTION_MUTATION_APPROVAL_SCHEMA_VERSION = 1;
|
||||
function unitId(unit) {
|
||||
|
|
@ -264,7 +265,7 @@ export function readProductionMutationApprovalStatus(basePath, unit) {
|
|||
const result = validateProductionMutationApproval(data, unit);
|
||||
return { path, approved: result.approved, reasons: result.reasons };
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
const message = getErrorMessage(error);
|
||||
return {
|
||||
path,
|
||||
approved: false,
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ import {
|
|||
getWorktreeOriginalCwd,
|
||||
setWorktreeOriginalCwd,
|
||||
} from "./worktree-session-state.js";
|
||||
// ─── Shared completions and handler (used by both /worktree and /wt) ────────
|
||||
import { getErrorMessage } from "./error-utils.js";
|
||||
function worktreeCompletions(prefix) {
|
||||
const parts = prefix.trim().split(/\s+/);
|
||||
const subcommands = ["list", "merge", "remove", "switch", "create", "return"];
|
||||
|
|
@ -377,7 +377,7 @@ async function handleCreate(basePath, name, ctx) {
|
|||
"info",
|
||||
);
|
||||
} catch (error) {
|
||||
const msg = error instanceof Error ? error.message : String(error);
|
||||
const msg = getErrorMessage(error);
|
||||
ctx.ui.notify(`Failed to create worktree: ${msg}`, "error");
|
||||
}
|
||||
}
|
||||
|
|
@ -421,7 +421,7 @@ async function handleSwitch(basePath, name, ctx) {
|
|||
"info",
|
||||
);
|
||||
} catch (error) {
|
||||
const msg = error instanceof Error ? error.message : String(error);
|
||||
const msg = getErrorMessage(error);
|
||||
ctx.ui.notify(`Failed to switch to worktree: ${msg}`, "error");
|
||||
}
|
||||
}
|
||||
|
|
@ -549,7 +549,7 @@ async function handleList(basePath, ctx) {
|
|||
}
|
||||
ctx.ui.notify(lines.join("\n"), "info");
|
||||
} catch (error) {
|
||||
const msg = error instanceof Error ? error.message : String(error);
|
||||
const msg = getErrorMessage(error);
|
||||
ctx.ui.notify(`Failed to list worktrees: ${msg}`, "error");
|
||||
}
|
||||
}
|
||||
|
|
@ -735,7 +735,7 @@ async function handleMerge(basePath, name, ctx, pi, targetBranch) {
|
|||
"info",
|
||||
);
|
||||
} catch (error) {
|
||||
const msg = error instanceof Error ? error.message : String(error);
|
||||
const msg = getErrorMessage(error);
|
||||
ctx.ui.notify(`Failed to start merge: ${msg}`, "error");
|
||||
}
|
||||
}
|
||||
|
|
@ -774,7 +774,7 @@ async function handleRemove(basePath, name, ctx) {
|
|||
"info",
|
||||
);
|
||||
} catch (error) {
|
||||
const msg = error instanceof Error ? error.message : String(error);
|
||||
const msg = getErrorMessage(error);
|
||||
ctx.ui.notify(`Failed to remove worktree: ${msg}`, "error");
|
||||
}
|
||||
}
|
||||
|
|
@ -824,7 +824,7 @@ async function handleRemoveAll(basePath, ctx) {
|
|||
);
|
||||
ctx.ui.notify(lines.join("\n"), failed.length > 0 ? "warning" : "info");
|
||||
} catch (error) {
|
||||
const msg = error instanceof Error ? error.message : String(error);
|
||||
const msg = getErrorMessage(error);
|
||||
ctx.ui.notify(`Failed to remove worktrees: ${msg}`, "error");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue