{"record":{"id":"9ab72bb358c3f593","repo":"can1357/oh-my-pi","slug":"trusted-extension-failed-to-load-extensionsresu","errorCode":null,"errorMessage":"Trusted extension failed to load: ${extensionsResult.errors.map(item => item.error).join(\"; \")}","messagePattern":"Trusted extension failed to load: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/main.ts","lineNumber":1894,"sourceCode":"\t\t\t// `preloadedExtensions` so the discovery work is not repeated.\n\t\t\tif (isInteractive && !parsedArgs.trustedExtensions?.length) {\n\t\t\t\tsessionOptions.extensions = [...(sessionOptions.extensions ?? []), createWarpEventBridgeExtension()];\n\t\t\t}\n\n\t\t\tconst eventBus = new EventBus();\n\t\t\tconst subagentEventBus = new EventBus();\n\t\t\tconst extensionsResult = parsedArgs.trustedExtensions?.length\n\t\t\t\t? await loadTrustedSessionExtensions(sessionOptions, cwd, eventBus)\n\t\t\t\t: await loadSessionExtensions(sessionOptions, cwd, settingsInstance, eventBus);\n\t\t\tconst extensionFlagSink: ExtensionFlagSink = {\n\t\t\t\tgetFlags: () => ExtensionRunner.aggregateFlags(extensionsResult.extensions),\n\t\t\t\tsetFlagValue: (name, value) => {\n\t\t\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\t\t},\n\t\t\t};\n\t\t\tconst initialArgs = applyExtensionFlags(extensionFlagSink, rawArgs) ?? parsedArgs;\n\t\t\tnormalizeContinueSessionArgs(initialArgs, rawArgs);\n\t\t\tif ((parsedArgs.trustedExtensions?.length ?? 0) > 0 && extensionsResult.errors.length > 0) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Trusted extension failed to load: ${extensionsResult.errors.map(item => item.error).join(\"; \")}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (const message of formatExtensionLoadNotifications(extensionsResult.errors)) {\n\t\t\t\tif (isInteractive) {\n\t\t\t\t\tnotifs.push({ kind: \"warn\", message });\n\t\t\t\t} else {\n\t\t\t\t\tprocess.stderr.write(`${chalk.yellow(`${message}\\n`)}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Fail fast on stale/typo flags (e.g. `omp --list-models`) now that we\n\t\t\t// know the real extension flag set. Without this check the unrecognized\n\t\t\t// token gets silently consumed and any following positional leaks as the\n\t\t\t// initial prompt — kicking off a real LLM session, MCP connection, and\n\t\t\t// tool calls (issue #2459). Exit code 2 matches the conventional\n\t\t\t// \"command line usage error\" convention.\n\t\t\tif (reportUnrecognizedFlags(initialArgs)) {","sourceCodeStart":1876,"sourceCodeEnd":1912,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/main.ts#L1876-L1912","documentation":"When the CLI is started with explicit trusted extensions, any extension that fails to load is fatal. After extension discovery, if parsedArgs.trustedExtensions is non-empty and extensionsResult.errors has entries, main() throws an Error whose message joins each failure's error text with '; '. This is deliberate fail-fast behavior: the user explicitly asked for these extensions, so silently degrading is not acceptable.","triggerScenarios":"Running the CLI with one or more trusted extensions listed while at least one of them throws during discovery/load (bad entry point, syntax error in the extension module, incompatible plugin API, unreadable path), so extensionsResult.errors.length > 0.","commonSituations":"Typo'd or stale extension path after a rename/move; extension written against an older plugin API that now throws on import; extension pointing at a directory without a valid entrypoint; permissions problem reading the extension file.","solutions":["Fix the underlying extension error shown after the prefix — the joined messages name each failing extension.","Verify each trusted extension path exists and points to a loadable module entrypoint.","Remove the broken extension from the trustedExtensions list (or drop the flag) to start without it.","Update or reinstall the extension to a version compatible with the current CLI."],"exampleFix":"// before\nconst initialArgs = { ...rawArgs, trustedExtensions: [\"./ext/old-entry.ts\"] };\n// after\nconst initialArgs = { ...rawArgs, trustedExtensions: [\"./ext/entry.ts\"] }; // path fixed / valid module","handlingStrategy":"try-catch","validationCode":"import * as fs from \"node:fs\";\nfunction trustedExtensionPathsLookLoadable(args: string[]): string | null {\n  for (const p of args) {\n    if (!fs.existsSync(p)) return `trusted extension path not found: ${p}`;\n  }\n  return null;\n}","typeGuard":"function hasTrustedExtensionErrors(r: { errors: { error: unknown }[] }): boolean {\n  return r.errors.length > 0;\n}","tryCatchPattern":"try {\n  await startCli(rawArgs);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"Trusted extension failed to load:\")) {\n    console.error(err.message);\n    console.error(\"Fix or remove the extension from --trusted-ext, or start without it.\");\n    process.exitCode = 1;\n    return;\n  }\n  throw err;\n}","preventionTips":["Pin trusted extension paths and verify they exist in CI before launch.","Keep extensions updated to the CLI's plugin API version.","Run the CLI once without the trusted-ext flag to isolate which extension fails.","Lint/test extension modules as part of your repo."],"tags":["cli","extensions","startup","fail-fast"],"backgroundTag":"extension-load-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}