Skip to content

Commit

Permalink
fix: wren core raise CoreError instead of pyo3_runtime.PanicException
Browse files Browse the repository at this point in the history
  • Loading branch information
grieve54706 committed Dec 3, 2024
1 parent 1fafd47 commit 6d08aaa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions wren-core-py/src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ pub struct PyExtractor {
#[pymethods]
impl PyExtractor {
#[new]
pub fn new(mdl_base64: &str) -> Self {
let manifest = to_manifest(mdl_base64).unwrap();
pub fn new(mdl_base64: &str) -> Result<Self, CoreError> {
let manifest = to_manifest(mdl_base64)?;
let mdl = WrenMDL::new_ref(manifest);
Self { mdl }
Ok(Self { mdl })
}

/// parse the given SQL and return the list of used table name.
Expand Down
23 changes: 23 additions & 0 deletions wren-core-py/tests/test_modeling_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,29 @@ def test_get_available_functions():
assert max_if["param_types"] is None


@pytest.mark.parametrize(
("value", "expected_error", "error_message"),
[
(
None,
TypeError,
"argument 'mdl_base64': 'NoneType' object cannot be converted to 'PyString'",
),
("xxx", Exception, "Base64 decode error: Invalid padding"),
("{}", Exception, "Base64 decode error: Invalid symbol 123, offset 0."),
(
"",
Exception,
"Serde JSON error: EOF while parsing a value at line 1 column 0",
),
],
)
def test_extractor_with_invalid_manifest(value, expected_error, error_message):
with pytest.raises(expected_error) as e:
Extractor(value)
assert str(e.value) == error_message


@pytest.mark.parametrize(
("sql", "expected"),
[
Expand Down

0 comments on commit 6d08aaa

Please sign in to comment.