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

LAZY_IN_SYNC: Uncaught TypeError: Cannot convert a Symbol value to a string #1510

Closed
paul-marechal opened this issue May 26, 2023 · 3 comments

Comments

@paul-marechal
Copy link
Contributor

Expected Behavior

I don't expect the LAZY_IN_SYNC error to fail when displaying symbols.

Current Behavior

LAZY_IN_SYNC fails to display symbols.

Possible Solution

Call .toString() explicitly before printing the symbol.

Steps to Reproduce (for bugs)

  1. Create a binding resolving to a promise.
  2. Resolve said binding synchronously.

Context

We recently migrated to Inversify 6 and had to deal with this error.

Your Environment

  • Version used: 6.0.1
  • Environment name and version (e.g. Chrome 39, node.js 5.4): Firefox 113.0.2 (64-bit)
  • Operating System and version (desktop or mobile): Windows 10
  • Link to your project: https://github.com/eclipse-theia/theia
@paul-marechal
Copy link
Contributor Author

Maybe a different issue but I had this problem while dealing with this error: What's the recommended way to troubleshoot which binding is causing the sync resolution to fail? I ended up editing Inversify's sources in my node modules to print what service identifier caused resolvedRequests.isAsync to become true but that feels like a workaround.

@notaphplover
Copy link
Member

Hey @paul-marechal, calling .get on an async binding results in this LAZY_IN_SYNCerror. This is not related to the use of symbols. I'm closing the issue now, but we can continue discussing this.

Basically, there's no way to get syncronously the resolved async value of a Promise. For such a reason, there's no way to get an async binding calling .get. You can rely on .getAsync.

If you wanted to keep async promise values, maybe you should be relying on a provider.

@paul-marechal
Copy link
Contributor Author

As an attempt to clarify back when I opened this issue (using 6.0.1) I was:

  • Trying to bind a Promise like bind(Symbol.for('cool')).to(Promise.resolve('test'))
  • I was hoping to inject the raw promise, but Inversify intercepted the Promise and considered the binding async
  • It would try to throw the LAZY_IN_SYNC error
  • Creation of this error failed because it didn't properly stringify the symbol representing the binding

The stringification issue was fixed by #1511.

With that being said this issue was resolved and needed to be closed, thanks!

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

No branches or pull requests

2 participants