Skip to content

Commit af3ff83

Browse files
fix: report missing import properly in loadSync (#1960)
1 parent 4436cc7 commit af3ff83

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/root.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ Root.prototype.load = function load(filename, options, callback) {
9898
/* istanbul ignore if */
9999
if (!callback)
100100
return;
101-
var cb = callback;
102-
callback = null;
103101
if (sync)
104102
throw err;
103+
var cb = callback;
104+
callback = null;
105105
cb(err, root);
106106
}
107107

tests/api_root.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ tape.test("reflected roots", function(test) {
6767
});
6868
});
6969

70+
test.test(test.name + " - missing import", function(test) {
71+
var root = new Root();
72+
test.plan(2);
73+
root.load("tests/data/badimport.proto", function(err) {
74+
test.ok(err, "should return an error when an imported file does not exist");
75+
test.match(err.toString(), /nonexistent\.proto/, "should mention the file name which was not found");
76+
test.end();
77+
});
78+
});
79+
80+
test.test(test.name + " - missing import, sync load", function(test) {
81+
var root = new Root();
82+
test.plan(2);
83+
try {
84+
root.loadSync("tests/data/badimport.proto");
85+
root.resolveAll();
86+
} catch (err) {
87+
test.ok(err, "should return an error when an imported file does not exist");
88+
test.match(err.toString(), /nonexistent\.proto/, "should mention the file name which was not found");
89+
}
90+
test.end();
91+
});
92+
7093
test.test(test.name + " - skipped", function(test) {
7194
var root = new Root();
7295
root.resolvePath = function() {

tests/data/badimport.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
syntax = "proto3";
2+
3+
import "nonexistent.proto";
4+
5+
message Message {
6+
NonExistent field = 1;
7+
}

0 commit comments

Comments
 (0)