Never return an error and a result #142
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BREAKING CHANGE: Asynchronous callbacks will never be called with an error and a parse result anymore.
This changeset aligns with how callbacks work in general in Node, you would never usually expect to see both a result (in our case a parse result element) and an error in a returned callback (https://nodejs.org/dist/latest-v10.x/docs/api/errors.html#errors_error_first_callbacks). This breaks behaviours such as promises and async/await. We do regard a parsing a problematic document (such as one with invalid API Blueprint syntax or one that does not meet validation requirements) a success in terms that we could parse the document and we have returned a valid parse result. Not to mention, the error property of the callback for some of our parsers may not even be an instance of
Error
but an annotation. Going forward, the error field would be used for actual failures to parse the document, for example Drafter had problems allocating memory or some system API failed us and we was not able to parse the document. Another example would be with a remote Fury adapter which hits a HTTP parsing API where the connection could fail, the attempt to parse the document failed.In past we've had to work around these behaviours, such as in https://gist.github.com/kylef/aea36b5992acac4a3782981393e9f998#file-fury-server-js-L11-L30.