Skip to content

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

@kate-goldenring

Description

@kate-goldenring

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions