Skip to content

[error] Improve display of error messages (colours, auto-inferred file name and line number)#195

Merged
forfudan merged 3 commits intodevfrom
error
Apr 9, 2026
Merged

[error] Improve display of error messages (colours, auto-inferred file name and line number)#195
forfudan merged 3 commits intodevfrom
error

Conversation

@forfudan
Copy link
Copy Markdown
Owner

@forfudan forfudan commented Apr 8, 2026

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 DecimoError formatting to mimic Python tracebacks, including chained errors and ANSI colors.
  • Updated many modules to raise structured DecimoError variants instead of raw string Error(...) messages.
  • Removed explicit file= parameters at many raise sites in favor of auto-captured file/line via call_location().

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 DecimoError formatting to mimic Python tracebacks, including chained errors and ANSI colors.
  • Updated many modules to raise structured DecimoError variants instead of raw string Error(...) messages.
  • Removed explicit file= parameters at many raise sites in favor of auto-captured file/line via call_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.

Comment thread src/decimo/errors.mojo Outdated
Comment thread src/decimo/bigfloat/bigfloat.mojo Outdated
Comment thread src/decimo/bigdecimal/arithmetics.mojo Outdated
Comment thread src/decimo/decimal128/decimal128.mojo Outdated
Comment thread src/decimo/decimal128/arithmetics.mojo Outdated
Comment thread src/decimo/decimal128/arithmetics.mojo Outdated
Comment thread src/decimo/decimal128/arithmetics.mojo Outdated
Comment thread src/decimo/decimal128/arithmetics.mojo Outdated
@forfudan forfudan merged commit dc682be into dev Apr 9, 2026
11 checks passed
@forfudan forfudan deleted the error branch April 9, 2026 17:13
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.

2 participants