-
-
Notifications
You must be signed in to change notification settings - Fork 236
Introduce failFast option #153
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
Introduce failFast option #153
Conversation
Pull Request Test Coverage Report for Build 383
💛 - Coveralls |
758e36f
to
c9c11b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really good job on this PR. I haven't 100% finished reviewing it yet, so there may be a few more comments from me tomorrow. But so far I like everything I see 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@P0lip - Thanks for making all those changes. The PR looks good, but I'd like to discuss a design change and get you and @philsturgeon's opinions....
I'm thinking that whenever there's an error — whether it's one error or many, and whether failFast
is true
or false
— it should result in a throw
, not a return
. The only time the library should return
a normal result is when there were no errors. This leaves no ambiguity about whether the operation was successful or not.
To me, this seems like the most intuitive, idiomatic, and consistent behavior. But I'd like to hear what you guys think.
My proposal is that we remove the $RefParser.errors
property and instead when failFast
is true
and one or more errors occur, we throw a JSONParserErrorGroup
error, with its errors
property set to the error(s) that occurred. The JSONParserErrorGroup.message
property should be something like "3 errors occurred while reading my-schema.yaml". In addition, we'd add a JSONParserErrorGroup.files
property, which is the $RefParser
object that contains whatever was parsed successfully.
Thoughts?
I like the sound of this, but in the interest of not marching along to a v9.0 release 3 days after a v8.0 release, perhaps we could sling this in as part of a v8.1 and get a TODO issue made up for getting this done later? Generally I try and balance great new changes with reducing major release rampage but YMMV. |
@philsturgeon - I don't think this PR (as-is, or with my proposed changes) requires a major version bump. It's fully backward-compatible and opt-in behavior. The |
OH Sorry I misread things, you are trying to change how the PR is working, it sounded like "oh I have an idea, let's change something bigger!" and I was trying to punt that. 😆 Yeah your thing sounds good. Exceptions for problems might be better than good and bad results coming back. |
@JamesMessinger Frankly speaking, I don't have any strong preference Both seems fairly similar and the potential change won't be difficult to implement, so I will the call up to you. |
Ok, cool. Sounds like we're all in agreement then. @P0lip - can you make the changes to the PR? To recap:
|
@JamesMessinger my apologies for a tad delayed answer. |
I believe I've addressed everything. |
Hey guys (@P0lip and @philsturgeon). Just wanted to let y'all know that I haven't forgotten about this PR. I'm just crazy super insanely busy at work, and don't have any time to look at it yet. I'll review it this weekend, and hopefully merge and publish it. 🎉 |
This would be super useful for our https://playground.asyncapi.io. I came here to make this proposal but you guys figured out already 👏 Thanks a lot! |
@JamesMessinger could you try and get to it this weekend? Otherwise I'll have to hit that big green button and I'm on highly questionable home-made mead. 🥴 |
@philsturgeon - I'm on it. Sorry for the delay. I've been working 80-hour weeks for the past month and have had zero time for anything else |
@JamesMessinger oh of course! Thank you so much, you’re a champion. Hope everything settles down soon that sounds rough 😫 |
I've declared this weekend a vacation from work. Which means that instead of coding on work stuff all weekend, I'll be coding on APIDevTools stuff all weekend! 😁 Hooray for quarantine! |
@P0lip and @philsturgeon - two things:
|
This PR implements
fastFail
that is supposed to define how lenient the processing is.Currently, json-schema-ref-parser bails upon the the first exception, regardless of it type - whether it's caused by resolver, parser, missing pointer, etc.
This is fine for the most of the time, yet there might cases where errors should be allowed.
fastFail=false
meets that demand.Key changes:
fastFail
- true by default for backwards compatibilityerrors
on each$RefParser
instance@stoplight/yaml
replacedjs-yaml
@stoplight/json
replacedJSON.parse
None of these changes should be considered as breaking.
I tried to stay reasonable about errors and limit the scope to the user-related ones, therefore I didn't cover all spots.
If there is something really nasty happening in our own code, we should throw.
I'm not quite sure about the source of the error we set. At the moment, as stated in docs, it's equal to the uri of document where the faulty document was referenced.
The alternative option is simply set it to the uri of the document that caused the error.