refactor: fix all remaining inline error ternaries across 20 files
Used perl regex to replace all patterns of the form X instanceof Error ? X.message : String(X) with getErrorMessage(X) for any variable name. Added getErrorMessage imports to 6 files that lacked it. Leaves only 2 intentional .stack || .message variants unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
dac14043cd
commit
aa6ecce384
18 changed files with 59 additions and 53 deletions
|
|
@ -8,6 +8,7 @@ import {
|
||||||
} from "node:fs";
|
} from "node:fs";
|
||||||
import { dirname } from "node:path";
|
import { dirname } from "node:path";
|
||||||
import { isMainThread } from "node:worker_threads";
|
import { isMainThread } from "node:worker_threads";
|
||||||
|
import { getErrorMessage } from "./error-utils.js";
|
||||||
|
|
||||||
const TRANSIENT_LOCK_ERROR_CODES = new Set(["EBUSY", "EPERM", "EACCES"]);
|
const TRANSIENT_LOCK_ERROR_CODES = new Set(["EBUSY", "EPERM", "EACCES"]);
|
||||||
const MAX_RENAME_ATTEMPTS = 5;
|
const MAX_RENAME_ATTEMPTS = 5;
|
||||||
|
|
@ -57,7 +58,7 @@ function buildAtomicWriteError(filePath, attempts, errors) {
|
||||||
const code = normalizeErrnoCode(lastError) ?? "UNKNOWN";
|
const code = normalizeErrnoCode(lastError) ?? "UNKNOWN";
|
||||||
const messages = errors.map(
|
const messages = errors.map(
|
||||||
(e, i) =>
|
(e, i) =>
|
||||||
` attempt ${i + 1}: [${normalizeErrnoCode(e) ?? "UNKNOWN"}] ${e instanceof Error ? e.message : String(e)}`,
|
` attempt ${i + 1}: [${normalizeErrnoCode(e) ?? "UNKNOWN"}] ${getErrorMessage(e)}`,
|
||||||
);
|
);
|
||||||
const wrapped = new Error(
|
const wrapped = new Error(
|
||||||
`Atomic write to ${filePath} failed after ${attempts} attempts:\n${messages.join("\n")}`,
|
`Atomic write to ${filePath} failed after ${attempts} attempts:\n${messages.join("\n")}`,
|
||||||
|
|
|
||||||
|
|
@ -540,7 +540,7 @@ export async function postUnitPreVerification(pctx, opts) {
|
||||||
s.lastGitActionStatus = "ok";
|
s.lastGitActionStatus = "ok";
|
||||||
} catch (stageErr) {
|
} catch (stageErr) {
|
||||||
const stageErrMsg =
|
const stageErrMsg =
|
||||||
stageErr instanceof Error ? stageErr.message : String(stageErr);
|
getErrorMessage(stageErr);
|
||||||
s.lastGitActionFailure = stageErrMsg;
|
s.lastGitActionFailure = stageErrMsg;
|
||||||
s.lastGitActionStatus = "failed";
|
s.lastGitActionStatus = "failed";
|
||||||
debugLog("postUnit", {
|
debugLog("postUnit", {
|
||||||
|
|
@ -653,7 +653,7 @@ export async function postUnitPreVerification(pctx, opts) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = e instanceof Error ? e.message : String(e);
|
const message = getErrorMessage(e);
|
||||||
s.lastGitActionFailure = message;
|
s.lastGitActionFailure = message;
|
||||||
s.lastGitActionStatus = "failed";
|
s.lastGitActionStatus = "failed";
|
||||||
debugLog("postUnit", {
|
debugLog("postUnit", {
|
||||||
|
|
@ -1421,7 +1421,7 @@ export async function postUnitPostVerification(pctx) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("postUnit", {
|
debugLog("postUnit", {
|
||||||
phase: "scaffold-keeper-dispatch",
|
phase: "scaffold-keeper-dispatch",
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -496,7 +496,7 @@ export function writeBlockerPlaceholder(unitType, unitId, base, reason) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logWarning(
|
logWarning(
|
||||||
"recovery",
|
"recovery",
|
||||||
`updateTaskStatus failed during context exhaustion: ${e instanceof Error ? e.message : String(e)}`,
|
`updateTaskStatus failed during context exhaustion: ${getErrorMessage(e)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Append event so worktree reconciliation can replay this recovery completion
|
// Append event so worktree reconciliation can replay this recovery completion
|
||||||
|
|
@ -511,7 +511,7 @@ export function writeBlockerPlaceholder(unitType, unitId, base, reason) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logWarning(
|
logWarning(
|
||||||
"recovery",
|
"recovery",
|
||||||
`appendEvent failed for task recovery: ${e instanceof Error ? e.message : String(e)}`,
|
`appendEvent failed for task recovery: ${getErrorMessage(e)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -521,7 +521,7 @@ export function writeBlockerPlaceholder(unitType, unitId, base, reason) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logWarning(
|
logWarning(
|
||||||
"recovery",
|
"recovery",
|
||||||
`updateSliceStatus failed during context exhaustion: ${e instanceof Error ? e.message : String(e)}`,
|
`updateSliceStatus failed during context exhaustion: ${getErrorMessage(e)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
@ -535,7 +535,7 @@ export function writeBlockerPlaceholder(unitType, unitId, base, reason) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logWarning(
|
logWarning(
|
||||||
"recovery",
|
"recovery",
|
||||||
`appendEvent failed for slice recovery: ${e instanceof Error ? e.message : String(e)}`,
|
`appendEvent failed for slice recovery: ${getErrorMessage(e)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,7 @@ export function auditOrphanedMilestoneBranches(basePath, isolationMode) {
|
||||||
// Not a registered worktree — expected for orphaned dirs
|
// Not a registered worktree — expected for orphaned dirs
|
||||||
logWarning(
|
logWarning(
|
||||||
"engine",
|
"engine",
|
||||||
`worktree remove failed (expected for orphaned dirs): ${e instanceof Error ? e.message : String(e)}`,
|
`worktree remove failed (expected for orphaned dirs): ${getErrorMessage(e)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// If the directory still exists after git worktree remove (either it
|
// If the directory still exists after git worktree remove (either it
|
||||||
|
|
@ -290,7 +290,7 @@ export function auditOrphanedMilestoneBranches(basePath, isolationMode) {
|
||||||
);
|
);
|
||||||
} catch (err2) {
|
} catch (err2) {
|
||||||
warnings.push(
|
warnings.push(
|
||||||
`Failed to remove worktree directory for ${milestoneId}: ${err2 instanceof Error ? err2.message : String(err2)}`,
|
`Failed to remove worktree directory for ${milestoneId}: ${getErrorMessage(err2)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1210,7 +1210,7 @@ export async function bootstrapAutoSession(
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("git-lock-cleanup-failed", {
|
debugLog("git-lock-cleanup-failed", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Pre-flight: validate milestone queue
|
// Pre-flight: validate milestone queue
|
||||||
|
|
|
||||||
|
|
@ -788,7 +788,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
if (lockBase()) releaseSessionLock(lockBase());
|
if (lockBase()) releaseSessionLock(lockBase());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-locks", {
|
debugLog("stop-cleanup-locks", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 1b: Flush queued follow-up messages (#3512) ──
|
// ── Step 1b: Flush queued follow-up messages (#3512) ──
|
||||||
|
|
@ -801,7 +801,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-queue", {
|
debugLog("stop-cleanup-queue", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 2: Skill state ──
|
// ── Step 2: Skill state ──
|
||||||
|
|
@ -810,7 +810,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
resetSkillTelemetry();
|
resetSkillTelemetry();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-skills", {
|
debugLog("stop-cleanup-skills", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 3: SIGTERM handler ──
|
// ── Step 3: SIGTERM handler ──
|
||||||
|
|
@ -818,7 +818,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
deregisterSigtermHandler();
|
deregisterSigtermHandler();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-sigterm", {
|
debugLog("stop-cleanup-sigterm", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 4: Auto-worktree exit ──
|
// ── Step 4: Auto-worktree exit ──
|
||||||
|
|
@ -885,7 +885,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-worktree", {
|
debugLog("stop-cleanup-worktree", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 5: Rebuild state while DB is still open (#3599) ──
|
// ── Step 5: Rebuild state while DB is still open (#3599) ──
|
||||||
|
|
@ -898,7 +898,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
await rebuildState(s.basePath);
|
await rebuildState(s.basePath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-rebuild-state-failed", {
|
debugLog("stop-rebuild-state-failed", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -909,7 +909,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
closeDatabase();
|
closeDatabase();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("db-close-failed", {
|
debugLog("db-close-failed", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -930,7 +930,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-basepath", {
|
debugLog("stop-cleanup-basepath", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 7b: Scaffold-keeper dispatch (ADR-021 Phase D) ──
|
// ── Step 7b: Scaffold-keeper dispatch (ADR-021 Phase D) ──
|
||||||
|
|
@ -946,7 +946,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-scaffold-keeper", {
|
debugLog("stop-cleanup-scaffold-keeper", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 7c: Record-promoter dispatch (ADR-021 Phase D) ──
|
// ── Step 7c: Record-promoter dispatch (ADR-021 Phase D) ──
|
||||||
|
|
@ -962,7 +962,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-record-promoter", {
|
debugLog("stop-cleanup-record-promoter", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 8: Ledger notification ──
|
// ── Step 8: Ledger notification ──
|
||||||
|
|
@ -996,7 +996,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-ledger", {
|
debugLog("stop-cleanup-ledger", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 9: Cmux sidebar / event log ──
|
// ── Step 9: Cmux sidebar / event log ──
|
||||||
|
|
@ -1009,7 +1009,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-cmux", {
|
debugLog("stop-cleanup-cmux", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 10: Debug summary ──
|
// ── Step 10: Debug summary ──
|
||||||
|
|
@ -1025,7 +1025,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-debug", {
|
debugLog("stop-cleanup-debug", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 11: Reset metrics, routing, hooks ──
|
// ── Step 11: Reset metrics, routing, hooks ──
|
||||||
|
|
@ -1036,7 +1036,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
if (s.basePath) clearPersistedHookState(s.basePath);
|
if (s.basePath) clearPersistedHookState(s.basePath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-metrics", {
|
debugLog("stop-cleanup-metrics", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 12: Remove paused-session metadata (#1383) ──
|
// ── Step 12: Remove paused-session metadata (#1383) ──
|
||||||
|
|
@ -1066,7 +1066,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-model", {
|
debugLog("stop-cleanup-model", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// ── Step 14: Unblock pending unitPromise (#1799) ──
|
// ── Step 14: Unblock pending unitPromise (#1799) ──
|
||||||
|
|
@ -1078,7 +1078,7 @@ export async function stopAuto(ctx, pi, reason) {
|
||||||
_resetPendingResolve();
|
_resetPendingResolve();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("stop-cleanup-pending-resolve", {
|
debugLog("stop-cleanup-pending-resolve", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -1181,7 +1181,7 @@ export async function pauseAuto(ctx, _pi, _errorContext) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("pause-cleanup-queue", {
|
debugLog("pause-cleanup-queue", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Unblock any pending unit promise so the auto-loop is not orphaned.
|
// Unblock any pending unit promise so the auto-loop is not orphaned.
|
||||||
|
|
@ -1431,7 +1431,7 @@ async function runStartupDoctorFix(ctx, basePath) {
|
||||||
return report;
|
return report;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("startup-doctor-failed", {
|
debugLog("startup-doctor-failed", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -1563,7 +1563,7 @@ export async function startAuto(ctx, pi, base, verboseMode, options) {
|
||||||
if (e.code !== "ENOENT") {
|
if (e.code !== "ENOENT") {
|
||||||
logWarning(
|
logWarning(
|
||||||
"session",
|
"session",
|
||||||
`pause file cleanup failed: ${e instanceof Error ? e.message : String(e)}`,
|
`pause file cleanup failed: ${getErrorMessage(e)}`,
|
||||||
{ file: "auto.ts" },
|
{ file: "auto.ts" },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -1620,7 +1620,7 @@ export async function startAuto(ctx, pi, base, verboseMode, options) {
|
||||||
if (e.code !== "ENOENT") {
|
if (e.code !== "ENOENT") {
|
||||||
logWarning(
|
logWarning(
|
||||||
"session",
|
"session",
|
||||||
`pause file cleanup failed: ${e instanceof Error ? e.message : String(e)}`,
|
`pause file cleanup failed: ${getErrorMessage(e)}`,
|
||||||
{ file: "auto.ts" },
|
{ file: "auto.ts" },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -1654,7 +1654,7 @@ export async function startAuto(ctx, pi, base, verboseMode, options) {
|
||||||
if (e.code !== "ENOENT") {
|
if (e.code !== "ENOENT") {
|
||||||
logWarning(
|
logWarning(
|
||||||
"session",
|
"session",
|
||||||
`stale pause file cleanup failed: ${e instanceof Error ? e.message : String(e)}`,
|
`stale pause file cleanup failed: ${getErrorMessage(e)}`,
|
||||||
{ file: "auto.ts" },
|
{ file: "auto.ts" },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -1793,7 +1793,7 @@ export async function startAuto(ctx, pi, base, verboseMode, options) {
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("resume-rebuild-state-failed", {
|
debugLog("resume-rebuild-state-failed", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
@ -1806,7 +1806,7 @@ export async function startAuto(ctx, pi, base, verboseMode, options) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("resume-doctor-failed", {
|
debugLog("resume-doctor-failed", {
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
invalidateAllCaches();
|
invalidateAllCaches();
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import { join } from "node:path";
|
||||||
import { debugLog } from "../debug-logger.js";
|
import { debugLog } from "../debug-logger.js";
|
||||||
import { formatDocSyncProposal, getDocSyncProposal } from "../doc-sync.js";
|
import { formatDocSyncProposal, getDocSyncProposal } from "../doc-sync.js";
|
||||||
import { runGit } from "../git-service.js";
|
import { runGit } from "../git-service.js";
|
||||||
|
import { getErrorMessage } from "../error-utils.js";
|
||||||
|
|
||||||
/** Unit types that mutate code — doc-sync only runs after these. */
|
/** Unit types that mutate code — doc-sync only runs after these. */
|
||||||
const CODE_MUTATING_UNITS = new Set(["execute-task", "complete-slice"]);
|
const CODE_MUTATING_UNITS = new Set(["execute-task", "complete-slice"]);
|
||||||
|
|
@ -80,7 +81,7 @@ export async function runDocSyncStagingCheck(basePath, unitType, ctx) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("postUnit", {
|
debugLog("postUnit", {
|
||||||
phase: "doc-sync",
|
phase: "doc-sync",
|
||||||
error: e instanceof Error ? e.message : String(e),
|
error: getErrorMessage(e),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1113,7 +1113,7 @@ export async function autoLoop(ctx, pi, s, deps) {
|
||||||
finishTurn("completed");
|
finishTurn("completed");
|
||||||
} catch (loopErr) {
|
} catch (loopErr) {
|
||||||
// ── Blanket catch: absorb unexpected exceptions, apply graduated recovery ──
|
// ── Blanket catch: absorb unexpected exceptions, apply graduated recovery ──
|
||||||
const msg = loopErr instanceof Error ? loopErr.message : String(loopErr);
|
const msg = getErrorMessage(loopErr);
|
||||||
debugLog("autoLoop", {
|
debugLog("autoLoop", {
|
||||||
phase: "iteration-error",
|
phase: "iteration-error",
|
||||||
message: msg,
|
message: msg,
|
||||||
|
|
|
||||||
|
|
@ -731,7 +731,7 @@ export async function runPreDispatch(ic, loopState) {
|
||||||
error: String(mergeErr),
|
error: String(mergeErr),
|
||||||
});
|
});
|
||||||
ctx.ui.notify(
|
ctx.ui.notify(
|
||||||
`Merge failed: ${mergeErr instanceof Error ? mergeErr.message : String(mergeErr)}. Resolve and run /autonomous to resume.`,
|
`Merge failed: ${getErrorMessage(mergeErr)}. Resolve and run /autonomous to resume.`,
|
||||||
"error",
|
"error",
|
||||||
);
|
);
|
||||||
await deps.stopAuto(
|
await deps.stopAuto(
|
||||||
|
|
@ -841,7 +841,7 @@ export async function runPreDispatch(ic, loopState) {
|
||||||
error: String(mergeErr),
|
error: String(mergeErr),
|
||||||
});
|
});
|
||||||
ctx.ui.notify(
|
ctx.ui.notify(
|
||||||
`Merge failed: ${mergeErr instanceof Error ? mergeErr.message : String(mergeErr)}. Resolve and run /autonomous to resume.`,
|
`Merge failed: ${getErrorMessage(mergeErr)}. Resolve and run /autonomous to resume.`,
|
||||||
"error",
|
"error",
|
||||||
);
|
);
|
||||||
await deps.stopAuto(
|
await deps.stopAuto(
|
||||||
|
|
@ -977,7 +977,7 @@ export async function runPreDispatch(ic, loopState) {
|
||||||
error: String(mergeErr),
|
error: String(mergeErr),
|
||||||
});
|
});
|
||||||
ctx.ui.notify(
|
ctx.ui.notify(
|
||||||
`Merge failed: ${mergeErr instanceof Error ? mergeErr.message : String(mergeErr)}. Resolve and run /autonomous to resume.`,
|
`Merge failed: ${getErrorMessage(mergeErr)}. Resolve and run /autonomous to resume.`,
|
||||||
"error",
|
"error",
|
||||||
);
|
);
|
||||||
await deps.stopAuto(
|
await deps.stopAuto(
|
||||||
|
|
@ -2049,7 +2049,7 @@ export async function runUnitPhase(ic, iterData, loopState, sidecarItem) {
|
||||||
});
|
});
|
||||||
} catch (solverErr) {
|
} catch (solverErr) {
|
||||||
logWarning("engine", "Autonomous solver prompt injection failed", {
|
logWarning("engine", "Autonomous solver prompt injection failed", {
|
||||||
error: solverErr instanceof Error ? solverErr.message : String(solverErr),
|
error: getErrorMessage(solverErr),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
s.lastPromptCharCount = finalPrompt.length;
|
s.lastPromptCharCount = finalPrompt.length;
|
||||||
|
|
@ -2081,7 +2081,7 @@ export async function runUnitPhase(ic, iterData, loopState, sidecarItem) {
|
||||||
finalPrompt = deps.reorderForCaching(finalPrompt);
|
finalPrompt = deps.reorderForCaching(finalPrompt);
|
||||||
} catch (reorderErr) {
|
} catch (reorderErr) {
|
||||||
const msg =
|
const msg =
|
||||||
reorderErr instanceof Error ? reorderErr.message : String(reorderErr);
|
getErrorMessage(reorderErr);
|
||||||
logWarning("engine", "Prompt reorder failed", { error: msg });
|
logWarning("engine", "Prompt reorder failed", { error: msg });
|
||||||
}
|
}
|
||||||
// Select and apply model (with tier escalation on retry — normal units only)
|
// Select and apply model (with tier escalation on retry — normal units only)
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import {
|
||||||
getCurrentTurnGeneration,
|
getCurrentTurnGeneration,
|
||||||
runWithTurnGeneration,
|
runWithTurnGeneration,
|
||||||
} from "./turn-epoch.js";
|
} from "./turn-epoch.js";
|
||||||
|
import { getErrorMessage } from "../error-utils.js";
|
||||||
|
|
||||||
// Tracks the latest session-switch attempt so a late timeout settlement from an
|
// Tracks the latest session-switch attempt so a late timeout settlement from an
|
||||||
// older runUnit() call cannot clear the guard for a newer one.
|
// older runUnit() call cannot clear the guard for a newer one.
|
||||||
|
|
@ -118,7 +119,7 @@ export async function runUnit(ctx, pi, s, unitType, unitId, prompt, options) {
|
||||||
} catch (sessionErr) {
|
} catch (sessionErr) {
|
||||||
if (sessionTimeoutHandle) clearTimeout(sessionTimeoutHandle);
|
if (sessionTimeoutHandle) clearTimeout(sessionTimeoutHandle);
|
||||||
const msg =
|
const msg =
|
||||||
sessionErr instanceof Error ? sessionErr.message : String(sessionErr);
|
getErrorMessage(sessionErr);
|
||||||
debugLog("runUnit", {
|
debugLog("runUnit", {
|
||||||
phase: "session-error",
|
phase: "session-error",
|
||||||
unitType,
|
unitType,
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ async function runSessionStartupDoctorFix(ctx) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const msg = error instanceof Error ? error.message : String(error);
|
const msg = getErrorMessage(error);
|
||||||
safetyLogWarning("startup-doctor", msg);
|
safetyLogWarning("startup-doctor", msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import {
|
||||||
supersedeMemory,
|
supersedeMemory,
|
||||||
} from "./memory-store.js";
|
} from "./memory-store.js";
|
||||||
import { _getAdapter, isDbAvailable } from "./sf-db.js";
|
import { _getAdapter, isDbAvailable } from "./sf-db.js";
|
||||||
|
import { getErrorMessage } from "./error-utils.js";
|
||||||
|
|
||||||
function parseArgs(raw) {
|
function parseArgs(raw) {
|
||||||
const tokens = splitArgs(raw);
|
const tokens = splitArgs(raw);
|
||||||
|
|
@ -533,7 +534,7 @@ function formatProbe(probe) {
|
||||||
return `${probe.ok ? "ok" : "not ok"} (${probe.status}${suffix})`;
|
return `${probe.ok ? "ok" : "not ok"} (${probe.status}${suffix})`;
|
||||||
}
|
}
|
||||||
function sanitizeProbeError(error) {
|
function sanitizeProbeError(error) {
|
||||||
const message = error instanceof Error ? error.message : String(error);
|
const message = getErrorMessage(error);
|
||||||
return message.replace(/Bearer\s+[A-Za-z0-9._~+/=-]+/g, "Bearer [redacted]");
|
return message.replace(/Bearer\s+[A-Za-z0-9._~+/=-]+/g, "Bearer [redacted]");
|
||||||
}
|
}
|
||||||
function handleExport(ctx, target) {
|
function handleExport(ctx, target) {
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ export async function handlePrBranch(args, ctx) {
|
||||||
gitAllowFail(basePath, ["cherry-pick", "--abort"]);
|
gitAllowFail(basePath, ["cherry-pick", "--abort"]);
|
||||||
gitAllowFail(basePath, ["reset", "--hard", "HEAD"]);
|
gitAllowFail(basePath, ["reset", "--hard", "HEAD"]);
|
||||||
const detail =
|
const detail =
|
||||||
pickErr instanceof Error ? pickErr.message : String(pickErr);
|
getErrorMessage(pickErr);
|
||||||
ctx.ui.notify(
|
ctx.ui.notify(
|
||||||
`Cherry-pick conflict at ${sha.slice(0, 8)}. Picked ${picked}/${commits.length} commits. Resolve manually.\n${detail}`,
|
`Cherry-pick conflict at ${sha.slice(0, 8)}. Picked ${picked}/${commits.length} commits. Resolve manually.\n${detail}`,
|
||||||
"warning",
|
"warning",
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
import { existsSync, readFileSync } from "node:fs";
|
import { existsSync, readFileSync } from "node:fs";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { parse } from "yaml";
|
import { parse } from "yaml";
|
||||||
|
import { getErrorMessage } from "./error-utils.js";
|
||||||
// ─── Validation ──────────────────────────────────────────────────────────
|
// ─── Validation ──────────────────────────────────────────────────────────
|
||||||
/**
|
/**
|
||||||
* Validate a parsed (but untyped) YAML object against the V1 workflow schema.
|
* Validate a parsed (but untyped) YAML object against the V1 workflow schema.
|
||||||
|
|
@ -290,7 +291,7 @@ export function loadDefinition(defsDir, name) {
|
||||||
try {
|
try {
|
||||||
parsed = parse(raw);
|
parsed = parse(raw);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = e instanceof Error ? e.message : String(e);
|
const msg = getErrorMessage(e);
|
||||||
throw new Error(`Failed to parse YAML in ${filePath}: ${msg}`);
|
throw new Error(`Failed to parse YAML in ${filePath}: ${msg}`);
|
||||||
}
|
}
|
||||||
const { valid, errors } = validateDefinition(parsed);
|
const { valid, errors } = validateDefinition(parsed);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { importExtensionModule } from "@singularity-forge/coding-agent";
|
import { importExtensionModule } from "@singularity-forge/coding-agent";
|
||||||
|
import { getErrorMessage } from "./error-utils.js";
|
||||||
export function registerExitCommand(pi, deps = {}) {
|
export function registerExitCommand(pi, deps = {}) {
|
||||||
pi.registerCommand("exit", {
|
pi.registerCommand("exit", {
|
||||||
description: "Exit SF gracefully",
|
description: "Exit SF gracefully",
|
||||||
|
|
@ -14,7 +15,7 @@ export function registerExitCommand(pi, deps = {}) {
|
||||||
(await importExtensionModule(import.meta.url, "./auto.js")).stopAuto;
|
(await importExtensionModule(import.meta.url, "./auto.js")).stopAuto;
|
||||||
await stopAuto(ctx, pi, "Graceful exit");
|
await stopAuto(ctx, pi, "Graceful exit");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const msg = e instanceof Error ? e.message : String(e);
|
const msg = getErrorMessage(e);
|
||||||
ctx.ui?.notify?.(
|
ctx.ui?.notify?.(
|
||||||
`Autonomous mode cleanup skipped (module version mismatch): ${msg}`,
|
`Autonomous mode cleanup skipped (module version mismatch): ${msg}`,
|
||||||
"warning",
|
"warning",
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ export function migrateToExternalState(basePath) {
|
||||||
} catch (copyErr) {
|
} catch (copyErr) {
|
||||||
return {
|
return {
|
||||||
migrated: false,
|
migrated: false,
|
||||||
error: `Migration rename/copy failed: ${copyErr instanceof Error ? copyErr.message : String(copyErr)}`,
|
error: `Migration rename/copy failed: ${getErrorMessage(copyErr)}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1769,7 +1769,7 @@ function migrateSchema(db) {
|
||||||
// schema version permanently on read-only or full filesystems.
|
// schema version permanently on read-only or full filesystems.
|
||||||
logWarning(
|
logWarning(
|
||||||
"db",
|
"db",
|
||||||
`Pre-migration backup failed: ${backupErr instanceof Error ? backupErr.message : String(backupErr)}`,
|
`Pre-migration backup failed: ${getErrorMessage(backupErr)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3401,7 +3401,7 @@ export function checkpointWal() {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logWarning(
|
logWarning(
|
||||||
"db",
|
"db",
|
||||||
`WAL checkpoint failed: ${e instanceof Error ? e.message : String(e)}`,
|
`WAL checkpoint failed: ${getErrorMessage(e)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -682,7 +682,7 @@ async function handleMerge(basePath, name, ctx, pi, targetBranch) {
|
||||||
return;
|
return;
|
||||||
} catch (mergeErr) {
|
} catch (mergeErr) {
|
||||||
const mergeMsg =
|
const mergeMsg =
|
||||||
mergeErr instanceof Error ? mergeErr.message : String(mergeErr);
|
getErrorMessage(mergeErr);
|
||||||
const isConflict = /conflict/i.test(mergeMsg);
|
const isConflict = /conflict/i.test(mergeMsg);
|
||||||
if (isConflict) {
|
if (isConflict) {
|
||||||
// Abort the failed merge so the working tree is clean for LLM retry
|
// Abort the failed merge so the working tree is clean for LLM retry
|
||||||
|
|
|
||||||
|
|
@ -460,7 +460,7 @@ export function removeWorktree(basePath, name, opts = {}) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logWarning(
|
logWarning(
|
||||||
"worktree",
|
"worktree",
|
||||||
`non-force worktree remove failed for ${gitReportedPath}: ${e instanceof Error ? e.message : String(e)}`,
|
`non-force worktree remove failed for ${gitReportedPath}: ${getErrorMessage(e)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -637,7 +637,7 @@ export function removeWorktree(basePath, name, opts = {}) {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logWarning(
|
logWarning(
|
||||||
"worktree",
|
"worktree",
|
||||||
`non-force worktree remove failed for ${resolvedWtPath}: ${e instanceof Error ? e.message : String(e)}`,
|
`non-force worktree remove failed for ${resolvedWtPath}: ${getErrorMessage(e)}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue