-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extracting errors during build does not support string templates #320
Comments
we can at least document this as a first measure. PR welcome. i agree supporting string templates will be tricky. |
Wow TIL!! Background Thoughts |
Definitely agree on adding some documentation on the limitation. In order to support this with minimal dev work, we could only allow Template Literals with 2 conditions:
I can see myself combining string error messages together and others might do the same too. Supporting other interpolated values like Functions or Arrays/Objects could get tricky since we'd have to do some extra work (e.g. awaiting an async function? Or JSON.stringify arrays/objects which could have circular deps?). What do you think? |
Somewhat unrelated, but could this feature be split out of core and into its own library? AFAIK, it seems like it can be, there's only a handful of internal references. It's a very advanced feature and would be easier to maintain that way as well as usable outside of TSDX. #184 would probably be easier that way too. |
Current Behavior
Running
--extractErrors
on the build script will fail if you use a string template as the invariant message instead of normal string quotes.Example index.ts:
Results in:
I think this has to do with the
evalToString
method insrc/errors/evalToString.ts
. It fails to evaluateTemplateLiteral
expressions and thus fails to extract any errors.Expected behavior
I expected this to extract the errors as it normally would if I were to use plain string quotes.
Suggested solution(s)
Having to support string templates in the invariant message might be tricky. This is due to not knowing the literal values for the template variables that needs to be interpolated during runtime.
For example,
^ Impossible to guess what
query
is when extracting the error message.I see two possible solutions to this:
Highlight in the docs that string templates as the message for the
invariant
function is not supported. Rather, use plain string quotes.Evaluate string templates, but fail if we cannot properly interpret the literal values of any template variables.
Having support for string templates and error extraction is nice because I use them for ease of use with multi-line comments. But, if the work required to support string templates is too much then I do think the next best thing is to go with option 1 and highlight the limitations of error extraction in the docs.
Your environment
The text was updated successfully, but these errors were encountered: