fix: namespace_exists/table_exists raise NamespaceNotFoundError/TableNotFoundError#6252
fix: namespace_exists/table_exists raise NamespaceNotFoundError/TableNotFoundError#6252lilei1128 wants to merge 3 commits intolance-format:mainfrom
Conversation
|
ACTION NEEDED The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification. For details on the error please inspect the "PR Title Check" action. |
|
close #6240 |
wjones127
left a comment
There was a problem hiding this comment.
This PR looks good. I have a few non-blocking suggestions, but those are pre-existing issues so I'd be fine addressing them in a different PR.
| Err(NamespaceError::NamespaceNotFound { | ||
| message: format!("Namespace '{}' not found", object_id), | ||
| } | ||
| .into()) |
There was a problem hiding this comment.
suggestion: This message duplicates what is in the Display implementation for this error:
lance/rust/lance-namespace/src/error.rs
Lines 180 to 182 in baa13ab
The error will print as:
Namespace not found: Namespace '{name}' not found
Consider just putting the quoted object id as the message:
| Err(NamespaceError::NamespaceNotFound { | |
| message: format!("Namespace '{}' not found", object_id), | |
| } | |
| .into()) | |
| Err(NamespaceError::NamespaceNotFound { | |
| message: format!("'{}'", object_id) | |
| } | |
| .into()) |
Then the message would be like:
Namespace not found: '{name}'
There was a problem hiding this comment.
Thank you for your correction.
| return Err(NamespaceError::TableNotFound { | ||
| message: format!("Table does not exist: {}", table_name), | ||
| } | ||
| .into()); |
There was a problem hiding this comment.
suggestion: similar to namespace error comment, this message duplicates the same text. Consider shortening it to:
| return Err(NamespaceError::TableNotFound { | |
| message: format!("Table does not exist: {}", table_name), | |
| } | |
| .into()); | |
| return Err(NamespaceError::TableNotFound { | |
| message: format!("'{}'", table_name), | |
| } | |
| .into()); |
| with pytest.raises(Exception): | ||
| with pytest.raises(TableNotFoundError): |
There was a problem hiding this comment.
praise: I'm very happy to see us asserting more specific errors here 😄
There was a problem hiding this comment.
Thanks! Happy to help make our error handling clearer 😊
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
namespace_exists() and table_exists() were raising RuntimeError instead of
the documented NamespaceNotFoundError / TableNotFoundError because the
implementations in dir.rs and manifest.rs used Error::namespace_source(String)
— a plain boxed string — which cannot be downcast to NamespaceError in
infer_error(), triggering the fallback RuntimeError path.
Fix by constructing proper NamespaceError variants:
Also fix rest_adapter.rs error_to_response to dispatch on NamespaceError
error codes instead of fragile string matching, and rest.rs HTTP helpers to
parse the numeric error code from the response body and reconstruct the
correct NamespaceError variant, so the full REST round-trip also raises the
right Python exception.
Update tests to assert TableNotFoundError / NamespaceNotFoundError specifically.