{"record":{"id":"b2f8067f4b582d7c","repo":"can1357/oh-my-pi","slug":"failed-to-load-share-script-message","errorCode":null,"errorMessage":"Failed to load share script: ${message}","messagePattern":"Failed to load share script: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/export/custom-share.ts","lineNumber":63,"sourceCode":" */\nexport async function loadCustomShare(): Promise<LoadedCustomShare | null> {\n\tconst scriptPath = getCustomSharePath();\n\tif (!scriptPath) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst module = await import(scriptPath);\n\t\tconst fn = module.default;\n\n\t\tif (typeof fn !== \"function\") {\n\t\t\tthrow new Error(\"share script must export a default function\");\n\t\t}\n\n\t\treturn { path: scriptPath, fn };\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\tthrow new Error(`Failed to load share script: ${message}`);\n\t}\n}\n","sourceCodeStart":45,"sourceCodeEnd":66,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/export/custom-share.ts#L45-L66","documentation":"This is the wrapper error produced by loadCustomShare's catch block: any failure while dynamically importing the share script — syntax errors, missing dependencies, runtime errors at module top level, or the missing-default-export contract check — is rethrown as 'Failed to load share script: <original message>'. The original cause is embedded in the message.","triggerScenarios":"Running /share with a share script present at ~/.omp/agent/share.* that fails to import: syntax error, unresolved import inside the script, thrown module-init error, or no function default export.","commonSituations":"Script imports a package that isn't installed in the agent's context; TS/JS typo causing a parse failure; script reads env/files at top level and throws; missing default export (error 1343 wrapped).","solutions":["Read the '<message>' suffix — it contains the real cause; fix that first.","Run the script standalone (bun run ~/.omp/agent/share.ts) to reproduce the import error outside /share.","Install any missing dependencies the script imports, or vendor them locally.","Ensure the script exports a default function.","Temporarily rename the script to fall back to default Gist sharing while debugging."],"exampleFix":"// before\nimport { render } from \"missing-pkg\";\nexport default async () => render();\n// after\nbun add missing-pkg  # or remove the import\nexport default async () => { /* ... */ };","handlingStrategy":"try-catch","validationCode":"// dry-run the import the same way the loader does\ntry {\n  const mod = await import(scriptPath);\n  if (typeof mod.default !== \"function\") throw new Error(\"default export must be a function\");\n} catch (err) {\n  console.error(`Share script broken: ${(err as Error).message}`);\n}","typeGuard":"null","tryCatchPattern":"try {\n  const custom = await loadCustomShare();\n} catch (err) {\n  logger.warn(\"Custom share script failed to load; using default Gist sharing\", {\n    cause: (err as Error).message,\n  });\n}","preventionTips":["Test the script with `bun run ~/.omp/agent/share.ts` after every edit.","Avoid importing packages that aren't resolvable from the agent's runtime.","Keep module top-level side effects minimal so import never throws.","Read the inner message after 'Failed to load share script:' — it names the true cause."],"tags":["module","dynamic-import","configuration","wrapped-error"],"backgroundTag":"module-load-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}