Permalink
Browse files

New: Emit an error on resolveAll() if any extension fields cannot be …

…resolved, see #595 + test case
  • Loading branch information...
dcodeIO committed Dec 30, 2016
1 parent c0ab94c commit 1f18453c7bfcce65c258fa98a3e3d4577d2e550f
Showing with 42 additions and 0 deletions.
  1. +11 −0 src/root.js
  2. +16 −0 tests/data/extend.proto
  3. +15 −0 tests/extend.js
@@ -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
@@ -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;
}
}
}
}
@@ -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.