Conversation
| @@ -0,0 +1,46 @@ | |||
| """Base error type supported by an Emitter.""" | |||
|
|
|||
| class CraftError(BaseException): | |||
There was a problem hiding this comment.
These are slightly reworked doc strings, and the reportable field was removed as the only time it was ever accessed in downstream code was to set it to False.
| Ok(()) | ||
| } | ||
|
|
||
| fn error(&mut self, error: &Bound<'_, CraftError>) -> PyResult<()> { |
There was a problem hiding this comment.
&Bound<'_, CraftError> is a Python object that is "bound" to the GIL. The type argument of CraftError asserts at runtime that the Python object is mappable to a CraftError. This is how to access types that were instantiated in Python therefore cannot become owned by Rust.
| }; | ||
|
|
||
| #[derive(PartialEq)] | ||
| #[pyclass(extends = PyBaseException, subclass, get_all, set_all, eq)] |
There was a problem hiding this comment.
This reads: "this class extends BaseException, is subclassable in Python, has getters & setters for each field, and is comparable with __eq__."
| // See https://pyo3.rs/main/class.html#initializer for an explanation on why this method | ||
| // needs to exist. |
There was a problem hiding this comment.
The TL;DR of this link is that because we extended a base Python type (PyBaseException) instead of a type we defined ourselves in Rust with #[pyclass], the __init__ method of the base class was fighting against us.
It seems like PyO3 was inserting the exact same arguments given to __new__ into BaseException.__init__(), which was failing since it takes no kwargs. This explicitly calls it with no arguments at all.
| /// Send a message to the `InnerPrinter` for displaying | ||
| pub fn send(&mut self, event: Event) -> PyResult<()> { | ||
| if self.stopped { | ||
| return Err(PyRuntimeError::new_err( |
There was a problem hiding this comment.
@medubelko look for this pattern of "return Err(" when reviewing these PRs, any instance of this in Rust has the potential to be shown to the user if not caught (and many aren't caught right now, heh).
But this is the only one in this PR anyways
make lint && make test?Adds back
errorandreport_errorto the Rust Emitter.Here's a script for easy testing: