Skip to content

Commit cf399e0

Browse files
authored
Merge pull request #170 from stoplightio/fix/no-plugin-result
Throw when no plugin returned a result
2 parents 71747c9 + ab2ed6a commit cf399e0

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

lib/util/plugins.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ exports.run = function (plugins, method, file, $refs) {
8484
// A synchronous result was returned
8585
onSuccess(result);
8686
}
87-
// else { the callback will be called }
87+
else if (index === plugins.length) {
88+
throw new Error("No promise has been returned or callback has been called.");
89+
}
8890
}
8991
catch (e) {
9092
onError(e);

test/specs/parsers/parsers.spec.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe("References to non-JSON files", () => {
6868
expect(schema).to.deep.equal(dereferencedSchema.binaryParser);
6969
});
7070

71-
it("should throw an error if no no parser can be matched", async () => {
71+
it("should throw an error if no parser can be matched", async () => {
7272
try {
7373
await $RefParser.dereference(path.rel("specs/parsers/parsers.yaml"), {
7474
parse: {
@@ -78,6 +78,7 @@ describe("References to non-JSON files", () => {
7878
binary: false,
7979
},
8080
});
81+
helper.shouldNotGetCalled();
8182
}
8283
catch (err) {
8384
expect(err).to.be.an.instanceOf(SyntaxError);
@@ -86,6 +87,29 @@ describe("References to non-JSON files", () => {
8687
}
8788
});
8889

90+
it("should throw an error if no parser returned a result", async () => {
91+
try {
92+
await $RefParser.dereference(path.rel("specs/parsers/parsers.yaml"), {
93+
parse: {
94+
yaml: {
95+
canParse: true,
96+
parse () {
97+
}
98+
},
99+
json: false,
100+
text: false,
101+
binary: false,
102+
},
103+
});
104+
helper.shouldNotGetCalled();
105+
}
106+
catch (err) {
107+
// would time out otherwise
108+
expect(err).to.be.an.instanceOf(ParserError);
109+
expect(err.message).to.contain("No promise has been returned or callback has been called.");
110+
}
111+
});
112+
89113
it('should throw an error if "parse.text" and "parse.binary" are disabled', async () => {
90114
try {
91115
await $RefParser.dereference(path.rel("specs/parsers/parsers.yaml"), { parse: { text: false, binary: false }});

test/specs/resolvers/resolvers.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,28 @@ describe("options.resolve", () => {
137137
}
138138
});
139139

140+
it("should throw an error if no resolver returned a result", async () => {
141+
try {
142+
await $RefParser.dereference(path.rel("specs/resolvers/resolvers.yaml"), {
143+
resolve: {
144+
http: false,
145+
file: {
146+
order: 1,
147+
canRead: true,
148+
read () {
149+
150+
}
151+
}
152+
}
153+
});
154+
helper.shouldNotGetCalled();
155+
}
156+
catch (err) {
157+
// would time out otherwise
158+
expect(err).to.be.an.instanceOf(ResolverError);
159+
}
160+
});
161+
140162
it("should throw a grouped error if no resolver can be matched and fastFail is false", async () => {
141163
const parser = new $RefParser();
142164
try {

0 commit comments

Comments
 (0)