Skip to content

Commit

Permalink
New: Emit an error on resolveAll() if any extension fields cannot be …
Browse files Browse the repository at this point in the history
…resolved, see #595 + test case
  • Loading branch information
dcodeIO committed Dec 30, 2016
1 parent c0ab94c commit 1f18453
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ RootPrototype.loadSync = function loadSync(filename, options) {
return this.load(filename, options, SYNC);
};

/**
* @override
*/
RootPrototype.resolveAll = function resolveAll() {
if (this.deferred.length)
throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
return "'extend " + field.extend + "' in " + field.parent.getFullName();
}).join(", "));
return Namespace.prototype.resolveAll.call(this);
};

/**
* Handles a deferred declaring extension field by creating a sister field to represent it within its extended type.
* @param {Field} field Declaring extension field witin the declaring type
Expand Down
16 changes: 16 additions & 0 deletions tests/data/extend.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

message A {
message B {
message One {
extensions 1000 to max;
}
}
message C {
message Two {
extend B.One {
Two two = 1000;
}
}
}
}
15 changes: 15 additions & 0 deletions tests/extend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var tape = require("tape");

var protobuf = require("..");

tape.test("extensions", function(test) {

protobuf.load("tests/data/extend.proto", function(err, root) {
if (err)
return test.fail(err.message);
root.resolveAll();
test.pass("should parse and resolve without errors");
test.end();
});

});

0 comments on commit 1f18453

Please sign in to comment.