Skip to content

feat: Add error handling and input validation to Rust core (#82)#88

Open
ada-cinar wants to merge 1 commit into
mainfrom
feature/82-error-handling-input-validation
Open

feat: Add error handling and input validation to Rust core (#82)#88
ada-cinar wants to merge 1 commit into
mainfrom
feature/82-error-handling-input-validation

Conversation

@ada-cinar

Copy link
Copy Markdown
Member

Summary

Adds proper error handling and input validation to all Rust core functions, replacing panics with Pythonic ValueError exceptions.

Changes

Error Handling:

  • Updated all #[pyfunction] signatures to return PyResult<T>
  • Added PyValueError exceptions for invalid input
  • Replaced panics with graceful error messages

Input Validation:

  • Empty string checks in fast_normalize, lookup_lemma, strip_suffixes
  • Zero min_root_length validation in strip_suffixes_validated
  • Graceful handling in tokenize_with_offsets (returns empty list)

Testing:

  • Added 16 comprehensive error handling tests
  • Covers edge cases, error messages, boundary conditions
  • All error handling tests passing (16/16)

Documentation:

  • Updated function docs with error specifications
  • Added Python examples for error handling

Benefits

  1. Pythonic Errors: Clear ValueError messages instead of opaque panics
  2. Better DX: Easier debugging and error tracing
  3. Best Practices: Follows PyO3 recommended patterns
  4. Type Safety: Proper Result propagation

Testing

pytest tests/test_error_handling.py -v
# ✅ 16 passed in 0.64s

pytest tests/ -v
# ✅ 74 passed, 5 skipped, 1 unrelated failure

Closes

Closes #82

Related

- Add PyResult return types to all public functions
- Add input validation (empty strings, zero min_root_length)
- Return Pythonic ValueError exceptions instead of panics
- Add comprehensive error handling tests (16 test cases)
- Improve function documentation with error specifications

Benefits:
- Better debugging experience with clear error messages
- Graceful handling of edge cases
- Follows PyO3 best practices
- Type-safe error propagation

Fixes #82
@ada-cinar ada-cinar self-assigned this Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Add Error Handling and Input Validation to Rust Core

1 participant