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

Unexpected error porting ROS Jibo blocks to new extension framework #296

Open
randi-c-dubs opened this issue Jun 22, 2023 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@randi-c-dubs
Copy link
Collaborator

Description

I was trying to port the Jibo extension, which uses ROSLIB to the new extension framework (with the @blocks decorator). I discovered an issue I could not get around where importing roslib and trying to use it seems to break the ts-compiler and causes the extension to fail compiling.
I am unsure of the cause but importing and using roslib works perfectly in the old version of the extension famework (with defineBlocks). The issue may have something to do with how these different functions are defined.

Priority level: Low. At some point Jibo blocks will use firebase instead of roslib. It's just a weird bug.

Recreating the error

  1. Go to a working example that uses the latest extension format (e.g. complex-example).
  2. In the terminal, install roslib npm i roslib
  3. At the top of the code, install roslib import ROSLIB from "roslib"
  4. Somewhere in the code, make a call to ROSLIB. For example, place the following in init()
    let rosbridgeIP = "ws://localhost:9090"; let ros = new ROSLIB.Ros({ url: rosbridgeIP, }); console.log(ros);
  5. In the terminal, compile and run the extension. npm run dev.
    Note: if you already had npm run dev running, stop it and restart it. Otherwise the error will not appear.

Expected behavior

The extension compiles successfully and everything works.

Actual behavior

During compile you get a ReferenceError about Websocket. Roslib uses websocket under the hood.
websocket_error

The overall compile fails.
compile_fail_error

Attempted fixes

  1. Installied and imported Websocket. But since there's no direct Websocket call this didn't do anything.
  2. Stopped using the newest style of the extension framework. Works, but a band-aid.
@randi-c-dubs randi-c-dubs added the bug Something isn't working label Jun 22, 2023
@p-buddy
Copy link
Collaborator

p-buddy commented Jun 22, 2023

A beautiful bug report, thanks, @randi-c-dubs !

The error is definitely due to the fact that, with the new extensions, we actually try to 'execute' the bundled up code (as the error suggests) because this forces all of the decorators to run allowing us to collect all the metadata about extensions and their blocks and do the necessary codegen. (but note the extension class is not actually instantiated, so the init function will not be ran).

It's certainly a little sketchy (as we are seeing here), but I think it's an improvement over how it worked with the 'old' extensions, which leveraged the typescript compiler to pull out these details -- unfortunately the typescript compiler is very undocumented, and I found it very difficult to work with, and didn't want to force anyone to work with it.

So, with all that preamble out of the way, what must be happening here is that ROSLIB references WebSocket within it's code that executes immediately so upon importing it, it immediately tries to interact with WebSocket (which is a little unexpected, since you'd expect it to likely reference it in a function definition instead, which would not trigger this error). Depending on where/how this is, there should be some easy workarounds, like by "stubbing" the WebSocket.

Is there a branch somewhere I could play around with this?

Thanks again for the clear and comprehensive report, @randi-c-dubs !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants