{"record":{"id":"bc8d139f9aa58e57","repo":"coleam00/Archon","slug":"failed-to-get-workflow-run-err-message","errorCode":null,"errorMessage":"Failed to get workflow run: ${err.message}","messagePattern":"Failed to get workflow run: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/workflow.ts","lineNumber":3675,"sourceCode":"  json?: boolean,\n  verbose?: boolean,\n  cwd?: string,\n  rawEvents?: boolean\n): Promise<number> {\n  let run: WorkflowRun | null;\n  try {\n    const resolvedId = await resolveRunIdArg(runId, cwd);\n    run = await workflowDb.getWorkflowRun(resolvedId);\n  } catch (error) {\n    const err = error as Error;\n    getLog().error({ err, runId }, 'cli.workflow_get_failed');\n    // In --json mode never throw — emit one parseable {ok:false} line (same\n    // contract as the write commands) so a parsing agent always gets JSON.\n    if (json) {\n      await writeJsonLine({ ok: false, runId, error: err.message });\n      return 1;\n    }\n    throw new Error(`Failed to get workflow run: ${err.message}`);\n  }\n\n  if (!run) {\n    // Not-found exits non-zero so `get <id> && ...` and CI checks see the\n    // failure (the JSON envelope already carries ok:false for parsers).\n    if (json) {\n      await writeJsonLine({ ok: false, runId, error: 'not_found' });\n    } else {\n      console.log(`Workflow run not found: ${runId}`);\n    }\n    return 1;\n  }\n\n  // getWorkflowRun returns the base WorkflowRun (no current_step_name) — derive\n  // per-node detail from the event log, and only when verbose is requested.\n  let events: WorkflowEventRow[] | undefined;\n  let eventsFailed = false;\n  if (verbose) {","sourceCodeStart":3657,"sourceCodeEnd":3693,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/cli/src/commands/workflow.ts#L3657-L3693","documentation":"Thrown by `archon workflow get` when the workflow-run lookup fails for a non-empty reason (DB error, store failure). In --json mode the CLI never throws; it emits a parseable {ok:false} JSON line with exit code 1 so a consuming agent always gets JSON.","triggerScenarios":"Running `archon workflow get <id>` when the workflow database is unavailable, corrupted, or the store throws during getWorkflowRun; any non-Error-unwrappable failure surfaced as err.message.","commonSituations":"SQLite/Postgres connection failure, database file locked or moved, running the CLI outside an initialized Archon workspace where the DB schema is missing.","solutions":["Check the database connection/config (ARCHON_DSN or local workspace DB) and that the workspace is initialized with `archon setup`.","Re-run with --json to get the underlying err.message in the {ok:false} line instead of a thrown error.","Inspect CLI logs for the 'cli.workflow_get_failed'-style event to see the original err object.","If the DB is corrupted, restore from backup or re-create the workspace database."],"exampleFix":"// before\nthrow new Error(`Failed to get workflow run: ${err.message}`);\n// after (consume as caller)\ntry { await cmd(); } catch (e) { console.error(e.message); process.exit(1); }","handlingStrategy":"try-catch","validationCode":"const idOk = /^[0-9a-f-]{36}$/i.test(runId); if (!idOk) throw new Error('pass a full run id or use --json');","typeGuard":"function isErrWithMessage(e: unknown): e is Error { return e instanceof Error && typeof e.message === 'string'; }","tryCatchPattern":"try { await getRun(id, { json: true }); } catch (e) { /* with --json this shouldn't throw; parse the {ok:false} line instead */ }","preventionTips":["Always pass --json when a script/agent consumes output; the CLI then guarantees one parseable {ok:false} line instead of throwing.","Initialize and verify the Archon workspace DB before running get commands.","Check the exit code (1) alongside the JSON envelope's ok:false."],"tags":["cli","database","workflow"],"backgroundTag":"workflow-run-lookup-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}