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

Error message type naming collision #987

Closed
bgentry opened this issue Jan 20, 2024 · 5 comments · Fixed by #988
Closed

Error message type naming collision #987

bgentry opened this issue Jan 20, 2024 · 5 comments · Fixed by #988
Labels

Comments

@bgentry
Copy link

bgentry commented Jan 20, 2024

Hello, similar to #927, I'm running into an issue because we have a type named Error which gets imported in generated structs, causing a collision with throw new Error(...) calls in the code. The typescript errors appear to go away if I prefix these like throw new globalThis.Error(...).

Looks like this is one more global type which needs such a prefix added throughout?

@stephenh
Copy link
Owner

Yeah, we're probably just missing the prefix; can you paste ~5-10 lines of code that show the throw new Error that's missing the globalThis?

@bgentry
Copy link
Author

bgentry commented Jan 20, 2024

Sure thing! Here's a sample of what gets generated for google/protobuf/wrappers:

export const Int64Value = {
  encode(message: Int64Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.value !== BigInt("0")) {
      if (BigInt.asIntN(64, message.value) !== message.value) {
        throw new Error("value provided for field message.value of type int64 too large");
      }
      writer.uint32(8).int64(message.value.toString());
    }
    return writer;
  },

And here is a sample of the Error proto def:

syntax = "proto3";

package myapp.common.v1;

import "google/protobuf/struct.proto";

message Error {
  string code = 1;
  string message = 2;
  google.protobuf.Struct extra = 3;
}

This simple diff:

       if (BigInt.asUintN(64, message.positiveIntValue) !== message.positiveIntValue) {
-        throw new Error("value provided for field message.positiveIntValue of type uint64 too large");
+        throw new globalThis.Error("value provided for field message.positiveIntValue of type uint64 too large");
       }

Is enough to get rid of tsc errors on these lines.

stephenh added a commit that referenced this issue Jan 20, 2024
stephenh added a commit that referenced this issue Jan 20, 2024
stephenh pushed a commit that referenced this issue Jan 20, 2024
## [1.166.4](v1.166.3...v1.166.4) (2024-01-20)

### Bug Fixes

* Add missing globalThis prefixes. ([#988](#988)) ([86aca54](86aca54)), closes [#987](#987)
@stephenh
Copy link
Owner

🎉 This issue has been resolved in version 1.166.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@bgentry
Copy link
Author

bgentry commented Jan 21, 2024

Thank you so much for the quick fix @stephenh! 🙏 I'll give this a try on Monday and report back if there are any issues.

@bgentry
Copy link
Author

bgentry commented Jan 22, 2024

Works great, thank you again @stephenh 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants