Skip to content

add getter for error's name when available #24

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

Merged
merged 1 commit into from
Jul 27, 2017

Conversation

KtorZ
Copy link
Contributor

@KtorZ KtorZ commented Jul 20, 2017

Hi folks!

I've added a small accessor which retrieves the name of an error when available. The property is specified by the ECMAScript spec 5.1 and is quite useful to perform pattern matching in a relatively reliable way.

In some cases and for some browsers though, the property name remains undefined in which case I chose to fallback to the initial name of 'Error' (instead of going for a Error -> Maybe String as I find the former approach more practical).

Let me know 👍

@paf31
Copy link
Contributor

paf31 commented Jul 20, 2017

Looks good, but "Error" seems like maybe not the best default, since throw new Error(...) will be indistinguishable from throw "error!".

Maybe something like "Unknown error", what do you think?

@KtorZ
Copy link
Contributor Author

KtorZ commented Jul 20, 2017

Well, I have picked "Error" exactly for that purpose. Here's my rational:

(Almost) any type can be thrown in JavaScript; yet it's not the case in PureScript (so far). Therefore every error which is going to be manipulated from PureScript is actually going to be an instance of Error. Hence the default.

@paf31
Copy link
Contributor

paf31 commented Jul 27, 2017

@garyb Any thoughts before I merge this one?

@garyb
Copy link
Member

garyb commented Jul 27, 2017

Looks fine to me, I think "Error" is a good default value too given the description in the spec.

@paf31 paf31 merged commit 740d3f9 into purescript:master Jul 27, 2017
@paf31
Copy link
Contributor

paf31 commented Jul 27, 2017

Thanks!

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.

3 participants