{"record":{"id":"2ad05ba64a1874bc","repo":"coleam00/Archon","slug":"failed-to-load-config-err-message","errorCode":null,"errorMessage":"Failed to load config: ${err.message}","messagePattern":"Failed to load config: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/isolation/src/providers/worktree.ts","lineNumber":168,"sourceCode":"  constructor(private loadConfig: RepoConfigLoader = () => Promise.resolve(null)) {}\n\n  /**\n   * Create an isolated environment using git worktrees.\n   *\n   * Config is loaded exactly once here and threaded through the rest of the\n   * `create()` call. A malformed `.archon/config.yaml` fails loudly at this\n   * boundary rather than being swallowed — see CLAUDE.md \"Fail Fast + Explicit\n   * Errors\". Downstream helpers assume they receive either a valid config\n   * object or `null`, never a second chance to reload.\n   */\n  async create(request: IsolationRequest): Promise<IsolatedEnvironment> {\n    let repoConfig: WorktreeCreateConfig | null;\n    try {\n      repoConfig = await this.loadConfig(request.canonicalRepoPath);\n    } catch (error) {\n      const err = error as Error;\n      getLog().error({ err, repoPath: request.canonicalRepoPath }, 'repo_config_load_failed');\n      throw new Error(`Failed to load config: ${err.message}`);\n    }\n\n    const branchName = toBranchName(this.generateBranchName(request));\n    const worktreePath = this.getWorktreePath(request, branchName, repoConfig);\n    // envId is, by contract, the worktree filesystem path (see `destroy()` docstring).\n    // Assign directly from the resolved path to keep the invariant in sync with\n    // the actual directory created below — computing it via a separate helper would\n    // risk divergence if resolution rules change.\n    const envId = worktreePath;\n\n    // Check for existing worktree (adoption)\n    const existing = await this.findExisting(request, branchName, worktreePath);\n    if (existing) {\n      return existing;\n    }\n\n    // Create new worktree (re-uses the already-loaded repoConfig — no double load).\n    const { warnings } = await this.createWorktree(request, worktreePath, branchName, repoConfig);","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/isolation/src/providers/worktree.ts#L150-L186","documentation":"WorktreeProvider.create loads `.archon/config.yaml` exactly once via the injected RepoConfigLoader. If the loader throws (unreadable file, YAML parse error, schema violation), the error is logged as `repo_config_load_failed` and rethrown wrapped as `Failed to load config: <original message>`. Archon fails loudly here rather than silently ignoring a malformed config.","triggerScenarios":"Calling WorktreeProvider.create(request) where the injected loadConfig for request.canonicalRepoPath throws — typically because `.archon/config.yaml` is unparseable YAML, fails schema validation, or the file cannot be read.","commonSituations":"Hand-edited YAML with indentation/tab errors, wrong types (e.g. `worktree.copyFiles` as a string instead of a list), a partially written config file, or permission problems on `.archon/config.yaml`.","solutions":["Read the inner `err.message` after 'Failed to load config:' — it names the actual YAML/schema problem","Validate the YAML with a linter or parser (e.g. `yamllint`) and fix syntax/indentation","Check that `.archon/config.yaml` matches the expected WorktreeCreateConfig schema (correct keys and types)","Verify file read permissions on `.archon/config.yaml` for the user running Archon"],"exampleFix":"# before (invalid YAML)\nworktree:\n  baseBranch: main\n   copyFiles: [.env]\n# after\nworktree:\n  baseBranch: main\n  copyFiles:\n    - .env","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'node:fs';\nimport { parse } from 'yaml';\nexport function assertConfigParses(path = '.archon/config.yaml'): void {\n  const raw = readFileSync(path, 'utf8');\n  const cfg = parse(raw); // throws with a line/column on bad YAML\n  if (cfg?.worktree != null && typeof cfg.worktree !== 'object') {\n    throw new Error('worktree section must be a mapping');\n  }\n}","typeGuard":"function isWorktreeConfig(v: unknown): v is { baseBranch?: string; remote?: string; copyFiles?: string[] } {\n  if (v == null || typeof v !== 'object') return false;\n  const w = v as Record<string, unknown>;\n  return (w.baseBranch === undefined || typeof w.baseBranch === 'string') &&\n         (w.remote === undefined || typeof w.remote === 'string') &&\n         (w.copyFiles === undefined || (Array.isArray(w.copyFiles) && w.copyFiles.every(f => typeof f === 'string')));\n}","tryCatchPattern":"try {\n  await provider.create(request);\n} catch (e) {\n  const msg = (e as Error).message;\n  if (msg.startsWith('Failed to load config: ')) {\n    console.error('Fix .archon/config.yaml:', msg.slice('Failed to load config: '.length));\n    throw e;\n  }\n  throw e;\n}","preventionTips":["Validate `.archon/config.yaml` with a YAML linter in CI","Avoid tabs and mixed indentation in YAML","Commit a schema/type check for the config shape","Never hand-edit config with a partially written file in place"],"tags":["config","yaml","initialization","fail-fast"],"backgroundTag":"config-load-failed","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}