Skip to content
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

throwing template strings shows as an error #1229

Closed
codebam opened this issue Nov 13, 2018 · 2 comments

Comments

@codebam
Copy link

commented Nov 13, 2018

What version of standard?
12.0.1
What operating system, Node.js, and npm version?
Arch Linux, v11.1.0, 6.4.1
What did you expect to happen?
I expected to not see an error
What actually happened?
I saw an error

Example:

throw `Insufficient memory loading job ${job[0]}.`

This displays the message:

[standard] Expected an object to be thrown. [E]

However this is completely valid code in Node.js, and it runs just fine.

@codebam

This comment has been minimized.

Copy link
Author

commented Nov 13, 2018

@LinusU

This comment has been minimized.

Copy link
Member

commented Nov 14, 2018

This is expected behavior. It's best practice to only throw Error derivatives...

There are a number of drawbacks with throwing strings, most notably you don't get any stack traces. It's also unexpected e.g. when catching to just get a string, and not be able to look at e.g. .stack, .name, etc.

@LinusU LinusU closed this Nov 14, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Feb 12, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
2 participants
You can’t perform that action at this time.