Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions docs/src/guide/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ CTBase.Exceptions.ParsingError <: CTBase.Exceptions.CTException
- `msg::String`: Error message
- `location::Union{String,Nothing}`: Where in the input the error occurred (optional)
- `suggestion::Union{String,Nothing}`: How to fix the syntax (optional)
- `context::Union{String,Nothing}`: What was being parsed (optional)

**Example**:

Expand All @@ -245,8 +244,7 @@ using CTBase
throw(CTBase.Exceptions.ParsingError(
"unexpected token 'end'",
location="line 42, column 10",
suggestion="Check for unmatched 'begin' or remove extra 'end'",
context="control flow parsing"
suggestion="Check for unmatched 'begin' or remove extra 'end'"
))
```

Expand Down Expand Up @@ -282,9 +280,14 @@ end
The enriched display automatically suggests:

```text
❌ Error: ExtensionError, missing dependencies
📦 Missing dependencies: Plots
💡 Suggestion: julia> using Plots
ExtensionError
│ missing dependencies
│ Missing Plots
│ Hint Run: using Plots
└─
```

**Use this exception** when:
Expand Down Expand Up @@ -331,10 +334,15 @@ end
The enriched display shows the solver-specific return code:

```text
❌ Error: SolverFailure, ODE integration failed
🔧 Return code: :Unstable
📂 Context: SciML integrator
💡 Suggestion: Reduce time step or check initial conditions
SolverFailure
│ ODE integration failed
│ Retcode :Unstable
│ Context SciML integrator
│ Hint Reduce time step or check initial conditions
└─
```

**Common return codes**:
Expand Down Expand Up @@ -372,23 +380,24 @@ The enriched display shows the solver-specific return code:

All CTBase exceptions provide an enriched, user-friendly display with:

- **🎯 Clear error type and message**
- **📋 Contextual information** (got/expected, reason, location)
- **💡 Actionable suggestions** for fixing the problem
- **📍 User code location** tracking
- **🎨 Emoji-based visual hierarchy**
- **Type name** on line 1, with caller location when available
- **Pipe-box layout** using `│` separators for visual structure
- **Aligned labels** (Got, Expected, Reason, Hint, Context, …) padded to a common width
- **Color coding**: red for type name, yellow for warnings, green for hints
- **Dynamic Hint** for `ExtensionError` generated from `weakdeps`

Example of enriched display:

```text
Control Toolbox Error

❌ Error: PreconditionError, System must be initialized before configuration
❓ Reason: initialize! not called yet
📂 Context: system configuration
💡 Suggestion: Call initialize!(state) before configure!
📍 In your code:
configure! at MyModule.jl:42
PreconditionError → configure! MyModule.jl:42
│ System must be initialized before configuration
│ Reason initialize! not called yet
│ Context system configuration
│ Hint Call initialize!(state) before configure!
└─
```

This makes debugging faster by providing all the information needed to understand and fix the problem.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CTBase.Descriptions.complete(:euler, :explicit; descriptions=descs)
try
throw(CTBase.Exceptions.IncorrectArgument("n must be positive"; got="-1"))
catch e
println(e)
showerror(stdout, e)
end
```

Expand Down
Loading