Skip to content
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

Never return an error and a result #142

Merged
merged 1 commit into from Feb 18, 2019
Merged

Conversation

kylef
Copy link
Member

@kylef kylef commented Feb 5, 2019

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.

@kylef kylef added the do not merge PR is blocked for merging label Feb 5, 2019
@kylef kylef force-pushed the kylef/error-handling branch 2 times, most recently from 8c42d03 to 9f34d84 Compare February 5, 2019 12:42
packages/fury/lib/fury.js Outdated Show resolved Hide resolved
packages/fury/lib/fury.js Outdated Show resolved Hide resolved
packages/fury/lib/fury.js Outdated Show resolved Hide resolved
@honzajavorek
Copy link
Contributor

Good! I believe this allows to simplify https://github.com/apiaryio/dredd-transactions as well

BREAKING CHANGE: Asynchronous callbacks will never be called with an
error and a result anymore.
@kylef kylef removed the do not merge PR is blocked for merging label Feb 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants