Skip to content

Commit 1fafc43

Browse files
Fix error message on parse failure
1 parent 9467abe commit 1fafc43

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/root.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ Root.prototype.load = function load(filename, options, callback) {
110110

111111
// Finishes loading by calling the callback (exactly once)
112112
function finish(err, root) {
113-
if (root) {
114-
root.resolveAll();
115-
}
116113
/* istanbul ignore if */
117114
if (!callback) {
118115
return;
119116
}
120117
if (sync) {
121118
throw err;
122119
}
120+
if (root) {
121+
root.resolveAll();
122+
}
123123
var cb = callback;
124124
callback = null;
125125
cb(err, root);

tests/comp_parse-uncommon.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@ function traverseTypes(current, fn) {
3434
traverseTypes(nested, fn);
3535
});
3636
}
37+
38+
tape.test("invalid lookup", async function(test) {
39+
try {
40+
await protobuf.load("tests/data/invalid-lookup.proto");
41+
test.fail("should have thrown");
42+
} catch(err) {
43+
test.match(err.message, /illegal token 'required'/, "failed to parse");
44+
}
45+
});
46+

tests/data/invalid-lookup.proto

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
syntax = "proto3";
2+
3+
package test;
4+
5+
service MyService {
6+
rpc MyMethod (InvalidMessage) returns (stream InvalidMessage) {};
7+
}
8+
9+
message InvalidMessage {
10+
required bad_field = 1;
11+
}

0 commit comments

Comments
 (0)