can1357/oh-my-pi · error · Error

Failed to load share script: ${message}

Error message

Failed to load share script: ${message}

What it means

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.

Source

Thrown at packages/coding-agent/src/export/custom-share.ts:63

 */
export async function loadCustomShare(): Promise<LoadedCustomShare | null> {
	const scriptPath = getCustomSharePath();
	if (!scriptPath) {
		return null;
	}

	try {
		const module = await import(scriptPath);
		const fn = module.default;

		if (typeof fn !== "function") {
			throw new Error("share script must export a default function");
		}

		return { path: scriptPath, fn };
	} catch (err) {
		const message = err instanceof Error ? err.message : String(err);
		throw new Error(`Failed to load share script: ${message}`);
	}
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Read the '<message>' suffix — it contains the real cause; fix that first.
  2. Run the script standalone (bun run ~/.omp/agent/share.ts) to reproduce the import error outside /share.
  3. Install any missing dependencies the script imports, or vendor them locally.
  4. Ensure the script exports a default function.
  5. Temporarily rename the script to fall back to default Gist sharing while debugging.

Example fix

// before
import { render } from "missing-pkg";
export default async () => render();
// after
bun add missing-pkg  # or remove the import
export default async () => { /* ... */ };
Defensive patterns

Strategy: try-catch

Validate before calling

// dry-run the import the same way the loader does
try {
  const mod = await import(scriptPath);
  if (typeof mod.default !== "function") throw new Error("default export must be a function");
} catch (err) {
  console.error(`Share script broken: ${(err as Error).message}`);
}

Type guard

null

Try / catch

try {
  const custom = await loadCustomShare();
} catch (err) {
  logger.warn("Custom share script failed to load; using default Gist sharing", {
    cause: (err as Error).message,
  });
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/b2f8067f4b582d7c. Report an issue: GitHub.