Skip to content

fix: throw Error instead of raw array for TypeScript compilation fail…#128

Open
Sup-ri-tha wants to merge 1 commit intoaccordproject:mainfrom
Sup-ri-tha:fix/compiler-error-surfacing
Open

fix: throw Error instead of raw array for TypeScript compilation fail…#128
Sup-ri-tha wants to merge 1 commit intoaccordproject:mainfrom
Sup-ri-tha:fix/compiler-error-surfacing

Conversation

@Sup-ri-tha
Copy link
Copy Markdown

Fixes #127

Problem

When a template formula contains invalid TypeScript, TemplateMarkToJavaScriptCompiler throws a raw Array instead of an Error object. This means callers get no .message, no stack trace just [object Object].

Fix

Wrap the compilation errors into a proper Error with a human-readable message including the node ID, error description, line and column number.

Notes

  • 2 pre-existing test failures unrelated to this change: optional-nested and JavaScriptEvaluator stress test. Verified both fail on main without this fix.
  • TemplateArchiveProcessor has a related issue where result.errors is not checked after compilation. Will address this in a follow-up PR once this is merged.

Copilot AI review requested due to automatic review settings March 28, 2026 08:08
…ures

Signed-off-by: Supritha Rajashekar <supritharajashekar10@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes error handling for TypeScript compilation failures in TemplateMarkToJavaScriptCompiler by throwing a proper Error (with a human-readable message) instead of throwing a raw Array<CompilerError>, improving debuggability for callers and aligning with Issue #127.

Changes:

  • Wrap TypeScript compilation diagnostics into a single Error message including node id + line/column details.
  • Update Jest snapshots to reflect the new thrown Error shape/message.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/TemplateMarkToJavaScriptCompiler.ts Wraps collected compilation diagnostics into an Error instead of throwing the raw diagnostics array.
test/__snapshots__/TemplateMarkInterpreter.test.ts.snap Updates expected snapshots from raw diagnostics arrays to error message snapshots.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const errorList = e.errors.map(d => `${d.renderedMessage} (line ${d.line}, col ${d.character})`);
return `In '${e.nodeId}': ${errorList.join(', ')}`;
});
throw new Error(messages.join('\n'));
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing an Error here fixes the raw-array issue, but it also drops the structured compilation details (nodeId/code/diagnostics) that callers may want to inspect programmatically. Consider attaching the original errors array onto the Error object (similar to TemplateMarkInterpreter.checkTypes, which sets (error as any).errors = errors) or using ErrorOptions.cause where supported, so consumers can access rich data without parsing the message string.

Suggested change
throw new Error(messages.join('\n'));
const error = new Error(messages.join('\n'));
(error as any).errors = errors;
throw error;

Copilot uses AI. Check for mistakes.
@Sup-ri-tha Sup-ri-tha force-pushed the fix/compiler-error-surfacing branch from 6a42103 to 18048b3 Compare March 28, 2026 08:11
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.

fix: TypeScript compilation errors thrown as raw array instead of Error object

2 participants