Implement TransformError
/TemplateError
subclasses
#89
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ok! Here's the PR for the
errors.ts
file. I tried to be as conservative as possible with my edits and did a lot of research on the best way to implement 'default' properties inclass
declarations in TypeScript. I'm still pretty new to coding in TypeScript so I'm happy to make any corrections or edits if you would prefer things be handled differently.Some quick notes to summarize things we discussed previously:
I opted not to expose a
code
property onTemplateError
instances since I think good error tracing can help identify the problem.Likewise, I removed redundant logging of the
cause
message fromTemplateError
implementations, instead only including a short message withcause.name
if it's defined. TheTransformError
message only adds context about the compiled JS function so I think it's better left in the stack.A `TransformError` now looks like this:
I added an argument to the Environment
Function
constructor to exposeTemplateError
class to the compiled template. I tried adding it to the Environment class (new this.error
) but sinceTemplateError
is hoisted it seemed cleaner to use it as a global.Moved
errorLine
toerrors.ts
and exported it so it can be used elsewhere. Not sure if you wanterrors.ts
to be included as a module entrypoint.Let me know if there's any corrections I can make! Thanks for taking a look.