Skip to content

add getter for error's name when available#24

Merged
paf31 merged 1 commit intopurescript:masterfrom
truqu:feature/error.name
Jul 27, 2017
Merged

add getter for error's name when available#24
paf31 merged 1 commit intopurescript:masterfrom
truqu:feature/error.name

Conversation

@KtorZ
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

paf31 commented Jul 27, 2017

@garyb Any thoughts before I merge this one?

@garyb
Copy link
Copy Markdown
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
Copy Markdown
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