[error] Improve display of error messages (colours, auto-inferred file name and line number)#195
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors Decimo’s error handling to produce Python-style tracebacks with ANSI coloring, and updates many call sites to raise typed DecimoError[...] variants (e.g., ValueError, OverflowError) with consistent metadata (message/function/previous error).
Changes:
- Reworked
DecimoErrorformatting to mimic Python tracebacks, including chained errors and ANSI colors. - Updated many modules to raise structured
DecimoErrorvariants instead of raw stringError(...)messages. - Removed explicit
file=parameters at many raise sites in favor of auto-captured file/line viacall_location().
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/decimo/toml/parser.mojo | Uses structured ValueError for parse errors (duplicate keys, invalid syntax). |
| src/decimo/tests.mojo | Wraps TOML parse failures in DecimoError with chaining. |
| src/decimo/str.mojo | Converts numeric parsing errors from strings to ValueError. |
| src/decimo/errors.mojo | Implements colored, Python-style traceback formatting and auto-captures file/line. |
| src/decimo/decimal128/special.mojo | Replaces string errors with ValueError/OverflowError for factorial operations. |
| src/decimo/decimal128/rounding.mojo | Uses OverflowError with improved messages for rounding overflow. |
| src/decimo/decimal128/exponential.mojo | Standardizes errors and chaining in power/root/exp/ln/log operations. |
| src/decimo/decimal128/decimal128.mojo | Updates constructors/conversions to use typed errors with chaining and clearer messages. |
| src/decimo/decimal128/constants.mojo | Uses ValueError for invalid constant selection inputs. |
| src/decimo/decimal128/arithmetics.mojo | Uses typed errors for overflow/div-by-zero and operation failures. |
| src/decimo/biguint/biguint.mojo | Removes manual file= fields and aligns exceptions to new auto-location behavior. |
| src/decimo/biguint/arithmetics.mojo | Updates div-by-zero and validation errors to typed errors. |
| src/decimo/bigint10/bigint10.mojo | Switches several conversion/overflow conditions to typed errors. |
| src/decimo/bigint10/arithmetics.mojo | Removes manual file= fields from chained DecimoError wrappers. |
| src/decimo/bigint/number_theory.mojo | Removes manual file= fields from DecimoError usage. |
| src/decimo/bigint/exponential.mojo | Removes manual file= fields from DecimoError usage. |
| src/decimo/bigint/bigint.mojo | Uses typed OverflowError/ValueError in conversions and power validation. |
| src/decimo/bigint/arithmetics.mojo | Uses ZeroDivisionError in division-by-zero path and removes manual file metadata. |
| src/decimo/bigfloat/bigfloat.mojo | Migrates MPFR-related failures to DecimoError/ConversionError. |
| src/decimo/bigdecimal/trigonometric.mojo | Uses ValueError for undefined trig edge cases. |
| src/decimo/bigdecimal/exponential.mojo | Uses typed errors for invalid power/root/log inputs and overflow cases. |
| src/decimo/bigdecimal/constants.mojo | Uses ValueError for invalid precision input. |
| src/decimo/bigdecimal/bigdecimal.mojo | Uses ValueError/ConversionError for scalar/Python Decimal conversion failures. |
| src/decimo/bigdecimal/arithmetics.mojo | Uses ZeroDivisionError for division/modulo-by-zero conditions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors Decimo’s error handling to produce Python-style tracebacks with ANSI coloring, and updates many call sites to raise typed
DecimoError[...]variants (e.g.,ValueError,OverflowError) with consistent metadata (message/function/previous error).Changes:
DecimoErrorformatting to mimic Python tracebacks, including chained errors and ANSI colors.DecimoErrorvariants instead of raw stringError(...)messages.file=parameters at many raise sites in favor of auto-captured file/line viacall_location().