Skip to content

fix: use typed NamespaceError::TableNotFound in DirectoryNamespace instead of plain strings#6267

Open
LuciferYang wants to merge 5 commits intolance-format:mainfrom
LuciferYang:fix-use-typed-namespace-errors-for-table-not-found
Open

fix: use typed NamespaceError::TableNotFound in DirectoryNamespace instead of plain strings#6267
LuciferYang wants to merge 5 commits intolance-format:mainfrom
LuciferYang:fix-use-typed-namespace-errors-for-table-not-found

Conversation

@LuciferYang
Copy link
Contributor

Summary

Replace Error::namespace_source(String) with NamespaceError::TableNotFound in dir.rs and dir/manifest.rs so that the JNI bridge can produce typed Java TableNotFoundException instead of raw RuntimeException.

Problem

When a table doesn't exist, dir.rs and dir/manifest.rs construct errors like:

Error::namespace_source(format!("Table does not exist: {}", table_name).into())

This wraps a plain String as Box<dyn Error>. The JNI bridge (java/lance-jni/src/error.rs) tries to downcast the source to NamespaceError to throw a typed LanceNamespaceException(TABLE_NOT_FOUND), but the downcast fails on a String and falls back to RuntimeException.

The full typed error plumbing already exists — NamespaceError::TableNotFoundlance_core::Error::Namespace (preserves the NamespaceError) → JNI downcast → Java TableNotFoundException. Only the error construction at the call sites was missing it.

This causes issues in the Spark connector (lance-format/lance-spark#217) where Spark 4.0+ expects NoSuchTableException from loadTable() but gets RuntimeException, making tableExists() crash instead of returning false.

Fix

  • dir.rs: 3 occurrences — "Table does not exist: {table_name}"NamespaceError::TableNotFound { message: table_name }
  • dir/manifest.rs: 4 occurrences — "Table '{name}' not found"NamespaceError::TableNotFound { message: name }
  • Updated 2 test assertions in dir.rs to match the new display format ("Table not found: ...")

Test plan

  • test_describe_nonexistent_table — passes with updated assertion
  • test_table_exists — passes with updated assertion
  • test_table_exists_fails_for_deregistered_v1 — passes (unchanged)
  • test_convert_to_lance_error in lance-namespace — confirms downcast chain works
  • cargo check -p lance-namespace-impls — compiles cleanly

@github-actions github-actions bot added the bug Something isn't working label Mar 24, 2026
@github-actions
Copy link
Contributor

Review

Clean, well-scoped bugfix. The error conversion chain (NamespaceError::TableNotFoundlance_core::Error::Namespace → JNI downcast) is correctly wired and already tested in test_convert_to_lance_error. No issues found.

LGTM.

🤖 Generated with Claude Code

@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 95.12195% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance-namespace-impls/src/dir.rs 96.87% 1 Missing ⚠️
rust/lance-namespace-impls/src/dir/manifest.rs 88.88% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant