Meteor.Error message

Curious, is there any reason why the message in the Meteor Error class is wrapped in brackets?

I’m using it like this:

throw new Meteor.Error("the error message")

And when I retrieve from a method callback, e.g. err.message, it displays [the error message]

Looks like err.error will provide the error string as it was passed in but err.message feels nicer semantically.

It’s because the Meteor.Error constructor is meant to accept a “code” as its first argument, with the human-readable message being the second argument. So, the intended usage is something like:

throw new Meteor.Error('my-code', 'This is my error message');

That will give you an error message like this:

This is my error message [my-code]

And if you use the error’s reason field instead, it doesn’t include the code in brackets:

This is my error message
1 Like

Thanks for your help! I took another look at the meteor docs and source code too. Sounds like I should change how I’m handling errors on the client side.

If anyone has any best practices to share on that, would be interested to learn.