Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: report missing import properly in loadSync #1960

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

alexander-fenster
Copy link
Contributor

Fixes #1954.

The finish function can be called in two modes, sync (when it throws an exception), or async (when it calls the callback). It makes sure the callback won't be called twice, but it makes one extra step and clean up the callback even it was called in sync mode. It causes problems such as in #1954 where instead of reporting "file not found" when parsing a proto, it jumps over that error and only reports the next error–or no error if the parsing happens to succeed without a bunch of imports being skipped as a result of the first exception.

Let's avoid clearing the callback if we haven't used it yet.

The problem actually occurs when loading a proto file in sync mode (e.g. by running root.loadSync(filename), which is what pbjs does), hence the PR title.

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused, is callback called elsewhere when using loadSync, rather than line 105?

if (sync)
throw err;
var cb = callback;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style is internally consistent, so LGTM. But, it would be an improvement to use let / const to protect us from weird scope issues.

@alexander-fenster
Copy link
Contributor Author

I'm a little confused, is callback called elsewhere when using loadSync, rather than line 105?

Only in line 105, but finish is called twice: one from the catch block on line 140, but before that, also from the fetch function called on line 133. The invocation from line 133 throws an exception that is caught by the catch block and is supposed to call the callback, but it was already set to null.

@alexander-fenster alexander-fenster merged commit af3ff83 into master Jan 16, 2024
6 checks passed
@alexander-fenster alexander-fenster deleted the import-order branch January 16, 2024 06:43
@github-actions github-actions bot mentioned this pull request Jan 16, 2024
vchudnov-g added a commit to googleapis/disco-to-proto3-converter that referenced this pull request Jul 31, 2024
This commit restores proto imports in the intended order, undoing the
workaround in #108 due
to protobufjs/protobuf.js#1954 now that the
solution protobufjs/protobuf.js#1960 is
implemented.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

order of imports matters?
2 participants