GithubHelp home page GithubHelp logo

Comments (1)

alexander-fenster avatar alexander-fenster commented on June 11, 2024

Luckily, it turns out it's not actually about the import order, but about the fact that pbjs uses loadSync internally, and the "file not found" error gets swallowed in the sync mode, so the parsing continues and fails on another, seemingly unrelated, error.

The culprit in the example above was google/api/field_info.proto, which originally was the second import to load. It did not exist (for an unrelated reason), the error was thrown and the import processing loop was terminated on line 133 in the following snippet:

protobuf.js/src/root.js

Lines 120 to 141 in 4436cc7

try {
if (util.isString(source) && source.charAt(0) === "{")
source = JSON.parse(source);
if (!util.isString(source))
self.setOptions(source.options).addJSON(source.nested);
else {
parse.filename = filename;
var parsed = parse(source, self, options),
resolved,
i = 0;
if (parsed.imports)
for (; i < parsed.imports.length; ++i)
if (resolved = getBundledFileName(parsed.imports[i]) || self.resolvePath(filename, parsed.imports[i]))
fetch(resolved);
if (parsed.weakImports)
for (i = 0; i < parsed.weakImports.length; ++i)
if (resolved = getBundledFileName(parsed.weakImports[i]) || self.resolvePath(filename, parsed.weakImports[i]))
fetch(resolved, true);
}
} catch (err) {
finish(err);
}

The failed invocation of fetch already called finish once, that first invocation of finish cleared the callback, so when finish was called the second time from the catch block, it did not do anything, and the parsing continued (until the next failure).

Reordering the imports so that the missing one goes last actually helped because the missing proto only provided some options which, being missing, apparently did not break the parsing.

Uh oh, that was a fun problem to debug.

from protobuf.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.