-
Notifications
You must be signed in to change notification settings - Fork 22
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
Piper/convert malformed module error to be exception based #15
Piper/convert malformed module error to be exception based #15
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think at some point we ought to make the exception messages more meaningful. Not in this PR. 👍
wasm/__init__.py
Outdated
len(F) > 1024 | ||
): # TODO: this is not part of spec, but this is required to pass tests. Tests pass with limit 10000, maybe more | ||
return "exhaustion" | ||
if (len(F) > 1024): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outer parens seem unnecessary
return store, "error", e.args[0] | ||
except Exception as err: | ||
if err.args[0] in {"trap", "exhaustion", "invalid", "malformed"}: | ||
raise Exception("Invariant: these exceptions should no longer be using the base exception class") from err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
wasm/__init__.py
Outdated
externtypestar, extertypeprimestar = ret | ||
importstar = module["imports"] | ||
if len(importstar) != len(externtypestar): | ||
return "error: wrong import length" | ||
raise InvalidModule("invalid") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lost a bit of info here: "wrong import length" could be the message for the InvalidModule
message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, though funny enough, this code path isn't currently being excercised at all.
@@ -62,13 +62,8 @@ def instantiate_module_from_wasm_file( | |||
wasmbytes = memoryview(wasm_module_file.read()) | |||
module = wasm.decode_module(wasmbytes) | |||
|
|||
if module == "malformed": | |||
raise MalformedModule(f"Malformed wasm module: {file_path.name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Including the file path that failed would probably be valuable, and the internal malformed exceptions don't have that. It might be worth catching and re-raising MalformedModule
with that info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# validate | ||
ret = wasm.validate_module(module) | ||
if type(ret) == str and ret[:14] == "error: invalid": | ||
raise InvalidModule(f"Invalid wasm module: {file_path.name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here (could re-raise with the file name)
Builds on #14
What was wrong?
The invalid module error was magic string based.
How was it fixed?
Converted all invalid module errors to be exception based.
Cute Animal Picture