Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,19 @@ Root.prototype.load = function load(filename, options, callback) {
var sync = callback === SYNC; // undocumented

// Finishes loading by calling the callback (exactly once)
var throwing = null;
function finish(err, root) {
// If we get here, and we are throwing then something must have
// incorrectly caught the error, so we need to rethrow it.
if (throwing)
throw throwing;
/* istanbul ignore if */
if (!callback)
return;
if (sync)
if (sync) {
throwing = err;
throw err;
}
var cb = callback;
callback = null;
cb(err, root);
Expand Down
7 changes: 7 additions & 0 deletions tests/data/missing-import.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

import "no/such/file.proto";

message Something {
ImportedType field = 1;
}
14 changes: 14 additions & 0 deletions tests/node/api_load-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,17 @@ tape.test("should load bundled definitions even if resolvePath method was overri
test.ok(root.lookup("Something"), "should parse message Something");
test.end();
});

tape.test("should raise error if import is missing", function(test) {
var protoFilePath = "tests/data/missing-import.proto";
var root = new protobuf.Root();

test.throws(
() => {
root.loadSync(protoFilePath);
},
/ENOENT: no such file or directory, open 'tests\/data\/no\/such\/file.proto'/,
"should throw an error with the path to the missing file"
);
test.end();
});