Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Parser Async should reject the Promise when parsing errors are found #35

Closed
juancoen opened this issue Nov 23, 2015 · 11 comments
Closed

Comments

@juancoen
Copy link
Contributor

Right now, the promise is fulfilled, returning an invalid API representation and clients must call the errors() method to know if there was an error.

@KonstantinSviridov
Copy link
Contributor

Some users may need even that API representation, which contains errors. That's why we do not reject Promise in this situation.

Is it important for you to have Promise rejected in case of API with errors? If yes, we can introduce a special option for this purpose.

@sichvoge
Copy link
Contributor

Would that change the high-level Parser API?

@KonstantinSviridov
Copy link
Contributor

@juancoen
Copy link
Contributor Author

ok, I agree with having an option for rejecting promises on errors, to cover all possible scenarios

@blakeembrey
Copy link
Contributor

What will the rejected promise look like? Rejections should be error instances, but the parser can return multiple errors. An error will errors on a property, or just the first error instance?

@KonstantinSviridov
Copy link
Contributor

@blakeembrey
For now it's just an error containing a single message. Do you know some Error subclass which can be passed an object (or array) to constructor (just like we pass strings usually)?

@blakeembrey
Copy link
Contributor

There's nothing formal in JavaScript, but you can just do it yourself. You can also subclass Error if you want to do this in a declarative way (with something like https://github.com/julien-f/js-make-error).

var error = new Error('Invalid RAML')
error.errors = errors // Tada, just document the error type.
return error

@KonstantinSviridov
Copy link
Contributor

Ok, thanks. So, there will be a message Api contains errors. and a complete array of errors.

@KonstantinSviridov
Copy link
Contributor

@blakeembrey It appears that Error subclassing is not available in typescript 1.4 microsoft/TypeScript#1168.

Seems like it remains to write parser errors to some field of the newly created error.

@blakeembrey
Copy link
Contributor

@KonstantinSviridov I pointed out how you can do it in the comment above.

@KonstantinSviridov
Copy link
Contributor

For loadApi:
If the 'rejectOnErrors' option is set to true, ApiLoadingError is thrown for Api which contains errors.

For loadApiAsync:
The Promise is rejected with ApiLoadingError if the resulting Api contains errors and the 'rejectOnErrors' option is set to 'true'.

Where ApiLoadingError is
http://raml-org.github.io/raml-js-parser-2/interfaces/_raml1_wrapped_ast_parsercore_.apiloadingerror.html

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants