Skip to content

Commit 806b870

Browse files
Renamed the "fastFail" option to "continueOnError"
1 parent 5831fc3 commit 806b870

File tree

12 files changed

+34
-32
lines changed

12 files changed

+34
-32
lines changed

docs/options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $RefParser.dereference("my-schema.yaml", {
2727
withCredentials: true, // Include auth credentials when resolving HTTP references
2828
}
2929
},
30-
failFast: true, // Abort upon first exception
30+
continueOnError: true, // Don't throw on the first error
3131
dereference: {
3232
circular: false // Don't allow circular $refs
3333
}

lib/index.d.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,11 @@ declare namespace $RefParser {
211211
}
212212

213213
/**
214-
* Determines how lenient the processing should be.
215-
* If this option is enable, the processing will be performed in a bail mode - will abort upon the first exception.
214+
* By default, JSON Schema $Ref Parser throws the first error it encounters. Setting `continueOnError` to `true`
215+
* causes it to keep processing as much as possible and then throw a single error that contains all errors
216+
* that were encountered.
216217
*/
217-
failFast?: boolean;
218+
continueOnError?: boolean;
218219

219220
/**
220221
* The `dereference` options control how JSON Schema `$Ref` Parser will dereference `$ref` pointers within the JSON schema.

lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ $RefParser.prototype.parse = async function parse (path, schema, options, callba
122122
me.schema = result;
123123
return maybe(args.callback, Promise.resolve(me.schema));
124124
}
125-
else if (!args.options.failFast) {
125+
else if (args.options.continueOnError) {
126126
me.schema = null; // it's already set to null at line 79, but let's set it again for the sake of readability
127127
return maybe(args.callback, Promise.resolve(me.schema));
128128
}
@@ -131,7 +131,7 @@ $RefParser.prototype.parse = async function parse (path, schema, options, callba
131131
}
132132
}
133133
catch (err) {
134-
if (args.options.failFast || !isHandledError(err)) {
134+
if (!args.options.continueOnError || !isHandledError(err)) {
135135
return maybe(args.callback, Promise.reject(err));
136136
}
137137

lib/options.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ $RefParserOptions.defaults = {
5656
},
5757

5858
/**
59-
* Determines how lenient the processing should be.
60-
* If this option is enable, the processing will be performed in a bail mode - will abort upon the first exception.
59+
* By default, JSON Schema $Ref Parser throws the first error it encounters. Setting `continueOnError` to `true`
60+
* causes it to keep processing as much as possible and then throw a single error that contains all errors
61+
* that were encountered.
6162
*/
62-
failFast: true,
63+
continueOnError: false,
6364

6465
/**
6566
* Determines the types of JSON references that are allowed.

lib/parse.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function readFile (file, options, $refs) {
7676
.then(resolve, onError);
7777

7878
function onError (err) {
79-
if (!err && !options.failFast) {
79+
if (!err && options.continueOnError) {
8080
// No resolver could be matched
8181
reject(new UnmatchedResolverError(file.url));
8282
}
@@ -124,7 +124,7 @@ function parseFile (file, options, $refs) {
124124
.then(onParsed, onError);
125125

126126
function onParsed (parser) {
127-
if ((!options.failFast || !parser.plugin.allowEmpty) && isEmpty(parser.result)) {
127+
if ((options.continueOnError || !parser.plugin.allowEmpty) && isEmpty(parser.result)) {
128128
reject(ono.syntax(`Error parsing "${file.url}" as ${parser.plugin.name}. \nParsed value is empty`));
129129
}
130130
else {
@@ -133,7 +133,7 @@ function parseFile (file, options, $refs) {
133133
}
134134

135135
function onError (err) {
136-
if (!err && !options.failFast) {
136+
if (!err && options.continueOnError) {
137137
// No resolver could be matched
138138
reject(new UnmatchedParserError(file.url));
139139
}

lib/ref.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ $Ref.prototype.resolve = function (path, options, friendlyPath, pathFromRoot) {
113113
return pointer.resolve(this.value, options);
114114
}
115115
catch (err) {
116-
if (!options || options.failFast || !isHandledError(err)) {
116+
if (!options || !options.continueOnError || !isHandledError(err)) {
117117
throw err;
118118
}
119119

lib/resolve-external.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async function resolve$Ref ($ref, path, $refs, options) {
112112
return Promise.all(promises);
113113
}
114114
catch (err) {
115-
if (options.failFast || !isHandledError(err)) {
115+
if (!options.continueOnError || !isHandledError(err)) {
116116
throw err;
117117
}
118118

test/specs/invalid-pointers/invalid-pointers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ describe("Schema with invalid pointers", () => {
2121
}
2222
});
2323

24-
it("should throw a grouped error for an invalid pointer if failFast is false", async () => {
24+
it("should throw a grouped error for an invalid pointer if continueOnError is true", async () => {
2525
const parser = new $RefParser();
2626
try {
27-
await parser.dereference(path.rel("specs/invalid-pointers/invalid.json"), { failFast: false });
27+
await parser.dereference(path.rel("specs/invalid-pointers/invalid.json"), { continueOnError: true });
2828
helper.shouldNotGetCalled();
2929
}
3030
catch (err) {

test/specs/invalid/invalid.spec.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ describe("Invalid syntax", () => {
7373
}
7474
});
7575

76-
describe("when failFast is false", () => {
76+
describe("when continueOnError is true", () => {
7777
it("should throw a grouped error for an invalid file path", async () => {
7878
const parser = new $RefParser();
7979
try {
80-
await parser.dereference("this file does not exist", { failFast: false });
80+
await parser.dereference("this file does not exist", { continueOnError: true });
8181
helper.shouldNotGetCalled();
8282
}
8383
catch (err) {
@@ -100,7 +100,7 @@ describe("Invalid syntax", () => {
100100
it("should throw a grouped error for an invalid YAML file", async () => {
101101
const parser = new $RefParser();
102102
try {
103-
await parser.dereference(path.rel("specs/invalid/invalid.yaml"), { failFast: false });
103+
await parser.dereference(path.rel("specs/invalid/invalid.yaml"), { continueOnError: true });
104104
helper.shouldNotGetCalled();
105105
}
106106
catch (err) {
@@ -122,7 +122,7 @@ describe("Invalid syntax", () => {
122122
it("should throw a grouped error for an invalid JSON file", async () => {
123123
const parser = new $RefParser();
124124
try {
125-
await parser.dereference(path.rel("specs/invalid/invalid.json"), { failFast: false });
125+
await parser.dereference(path.rel("specs/invalid/invalid.json"), { continueOnError: true });
126126
helper.shouldNotGetCalled();
127127
}
128128
catch (err) {
@@ -144,7 +144,7 @@ describe("Invalid syntax", () => {
144144
it("should throw a grouped error for an invalid JSON file with YAML disabled", async () => {
145145
const parser = new $RefParser();
146146
try {
147-
await parser.dereference(path.rel("specs/invalid/invalid.json"), { failFast: false, parse: { yaml: false }});
147+
await parser.dereference(path.rel("specs/invalid/invalid.json"), { continueOnError: true, parse: { yaml: false }});
148148
helper.shouldNotGetCalled();
149149
}
150150
catch (err) {
@@ -165,7 +165,7 @@ describe("Invalid syntax", () => {
165165

166166
it("should not throw an error for an invalid YAML file with JSON and YAML disabled", async () => {
167167
const parser = new $RefParser();
168-
const result = await parser.dereference(path.rel("specs/invalid/invalid.yaml"), { failFast: false, parse: { yaml: false, json: false }});
168+
const result = await parser.dereference(path.rel("specs/invalid/invalid.yaml"), { continueOnError: true, parse: { yaml: false, json: false }});
169169
expect(result).to.be.null;
170170
});
171171
});
@@ -222,11 +222,11 @@ describe("Invalid syntax", () => {
222222
});
223223
});
224224

225-
describe("when failFast is false", () => {
225+
describe("when continueOnError is true", () => {
226226
it("should throw a grouped error for an invalid file path", async () => {
227227
try {
228228
const parser = new $RefParser();
229-
await parser.dereference({ foo: { $ref: "this file does not exist" }}, { failFast: false });
229+
await parser.dereference({ foo: { $ref: "this file does not exist" }}, { continueOnError: true });
230230
helper.shouldNotGetCalled();
231231
}
232232
catch (err) {
@@ -247,7 +247,7 @@ describe("Invalid syntax", () => {
247247
it("should throw a grouped error for an invalid YAML file", async () => {
248248
try {
249249
const parser = new $RefParser();
250-
await parser.dereference({ foo: { $ref: path.rel("specs/invalid/invalid.yaml") }}, { failFast: false });
250+
await parser.dereference({ foo: { $ref: path.rel("specs/invalid/invalid.yaml") }}, { continueOnError: true });
251251
helper.shouldNotGetCalled();
252252
}
253253
catch (err) {
@@ -268,7 +268,7 @@ describe("Invalid syntax", () => {
268268
it("should throw a grouped error for an invalid JSON file", async () => {
269269
try {
270270
const parser = new $RefParser();
271-
await parser.dereference({ foo: { $ref: path.rel("specs/invalid/invalid.json") }}, { failFast: false });
271+
await parser.dereference({ foo: { $ref: path.rel("specs/invalid/invalid.json") }}, { continueOnError: true });
272272
helper.shouldNotGetCalled();
273273
}
274274
catch (err) {
@@ -289,7 +289,7 @@ describe("Invalid syntax", () => {
289289
it("should throw a grouped error for an invalid JSON file with YAML disabled", async () => {
290290
try {
291291
const parser = new $RefParser();
292-
await parser.dereference({ foo: { $ref: path.rel("specs/invalid/invalid.json") }}, { failFast: false, parse: { yaml: false }});
292+
await parser.dereference({ foo: { $ref: path.rel("specs/invalid/invalid.json") }}, { continueOnError: true, parse: { yaml: false }});
293293
helper.shouldNotGetCalled();
294294
}
295295
catch (err) {
@@ -309,7 +309,7 @@ describe("Invalid syntax", () => {
309309

310310
it("should not throw an error for an invalid YAML file with JSON and YAML disabled", async () => {
311311
const parser = new $RefParser();
312-
const result = await parser.dereference({ foo: { $ref: path.rel("specs/invalid/invalid.yaml") }}, { failFast: false, parse: { yaml: false, json: false }});
312+
const result = await parser.dereference({ foo: { $ref: path.rel("specs/invalid/invalid.yaml") }}, { continueOnError: true, parse: { yaml: false, json: false }});
313313
expect(result).to.deep.equal({ foo: ":\n" });
314314
});
315315
});

test/specs/missing-pointers/missing-pointers.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ describe("Schema with missing pointers", () => {
2121
}
2222
});
2323

24-
it("should throw a grouped error for missing pointer if failFast is false", async () => {
24+
it("should throw a grouped error for missing pointer if continueOnError is true", async () => {
2525
const parser = new $RefParser();
2626
try {
27-
await parser.dereference({ foo: { $ref: "#/baz" }}, { failFast: false });
27+
await parser.dereference({ foo: { $ref: "#/baz" }}, { continueOnError: true });
2828
helper.shouldNotGetCalled();
2929
}
3030
catch (err) {

test/specs/parsers/parsers.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ describe("References to non-JSON files", () => {
216216
text: false,
217217
binary: false,
218218
},
219-
failFast: false,
219+
continueOnError: true,
220220
});
221221
helper.shouldNotGetCalled();
222222
}

test/specs/resolvers/resolvers.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe("options.resolve", () => {
145145
file: false,
146146
http: false,
147147
},
148-
failFast: false,
148+
continueOnError: true,
149149
});
150150
helper.shouldNotGetCalled();
151151
}

0 commit comments

Comments
 (0)