Skip to content

Handle _.context syntax/import failures without crashing startup#1920

Merged
pmcelhaney merged 4 commits intomainfrom
copilot/fix-syntax-error-in-context-module
Apr 16, 2026
Merged

Handle _.context syntax/import failures without crashing startup#1920
pmcelhaney merged 4 commits intomainfrom
copilot/fix-syntax-error-in-context-module

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 16, 2026

Summary

A broken _.context.ts (syntax/import error) previously bubbled into startup failure paths. This change makes context-module load failures non-fatal: Counterfact now warns and skips that context module, while continuing to load routes.

  • Context load error handling
    • In ModuleLoader.loadEndpoint, context files (_.context.*) now take a dedicated error path on import failure.
    • Instead of registering route-style 500 handlers or throwing, loader writes a warning and returns.
  • Route error behavior unchanged
    • Non-context route modules still keep existing behavior (500 responder registration for import/syntax failures).
  • Docs update
    • Added explicit note in state docs that invalid _.context.ts is skipped with a warning.
  • Release metadata
    • Added a patch changeset describing the behavior change.
if (this.isContextFile(pathName)) {
  const warning = isSyntaxError
    ? `Warning: There is a syntax error in the context file: ${displayPath}`
    : `Warning: There was an error loading the context file: ${displayPath}`;

  process.stdout.write(`\n${warning}\n`);
  return;
}
Original Prompt

Issue title: App should not crash due to syntax error in _.context.ts

Issue description: A syntax error in _.context.ts should not cause the app to crash. Instead it should print a warning and not load the context module.

Manual acceptance tests

  • Start Counterfact with a project whose routes/_.context.ts contains invalid syntax; verify startup continues and a warning is printed mentioning the context file.
  • With the same invalid _.context.ts, call a normal route module in that tree and verify it still responds (app remains operational).
  • Confirm the broken context is not applied (state/methods from that context are unavailable) until the file is fixed.
  • Introduce a syntax error in a route file (not _.context.ts) and verify existing route-error behavior is unchanged (generated 500 response path still applies).

Tasks

  • Added context-specific import-error handling in src/server/module-loader.ts to warn + skip for _.context.*.
  • Added focused regression test in test/server/module-loader.test.ts for invalid _.context.js behavior (warning emitted, route still loaded, context not registered).
  • Updated docs in docs/features/state.md to document warning-and-skip behavior for invalid context files.
  • Added patch changeset in .changeset/free-numbers-relate.md.

Copilot AI linked an issue Apr 16, 2026 that may be closed by this pull request
@pmcelhaney pmcelhaney marked this pull request as ready for review April 16, 2026 16:57
Copilot AI changed the title [WIP] Fix app crash caused by syntax error in _.context.ts Handle _.context syntax/import failures without crashing startup Apr 16, 2026
Copilot AI requested a review from pmcelhaney April 16, 2026 17:09
@pmcelhaney pmcelhaney enabled auto-merge April 16, 2026 17:11
@pmcelhaney pmcelhaney added this pull request to the merge queue Apr 16, 2026
Merged via the queue into main with commit 2f996fe Apr 16, 2026
8 of 9 checks passed
@pmcelhaney pmcelhaney deleted the copilot/fix-syntax-error-in-context-module branch April 16, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App should not crash due to syntax error in _.context.ts

2 participants