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

Create more actionable error for disallowed name for a Python module #78

Open
kate-goldenring opened this issue Mar 15, 2024 · 0 comments

Comments

@kate-goldenring
Copy link

Error

I ran into the following error:

$ componentize-py --wit-path add.wit --world example componentize example -o add.wasm
Traceback (most recent call last):
  File "/opt/homebrew/bin/componentize-py", line 8, in <module>
    sys.exit(script())
             ^^^^^^^^
AssertionError:

Caused by:
    TypeError: Can't instantiate abstract class Example without an implementation for abstract method 'add'

Repro

My set up was the following:

// WIT
package example:component;

world example {
    export add: func(x: s32, y: s32) -> s32;
}

App:

$ cat<<EOT >> example.py
import example

class Example(example.Example):
    def add(self, x: int, y: int) -> int:
        return x + y
EOT

Now when i go to componentize I get the TypeError:

$ componentize-py --wit-path /path/to/examples/example-host/add.wit --world example componentize example -o add.wasm
Traceback (most recent call last):
...

Workaround

@dicej pointed out that the issue is that you cannot name the Python module (example.py) the same as the world name (example), since componentize-py will generate a module using the world name and only use one of them. Renaming example.py to app.py resolved the issue.

The error thrown should be more descriptive and actionable. It was not clear from the TypeError how to resolve the issue.

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

No branches or pull requests

1 participant