Skip to content

Commit d29535a

Browse files
authored
Merge pull request #444 from control-toolbox/feat/exception-display-redesign
Redesign exception display with improved formatting and structure
2 parents 43ccfb6 + 40fbfcc commit d29535a

5 files changed

Lines changed: 461 additions & 272 deletions

File tree

docs/src/guide/exceptions.md

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ CTBase.Exceptions.ParsingError <: CTBase.Exceptions.CTException
236236
- `msg::String`: Error message
237237
- `location::Union{String,Nothing}`: Where in the input the error occurred (optional)
238238
- `suggestion::Union{String,Nothing}`: How to fix the syntax (optional)
239-
- `context::Union{String,Nothing}`: What was being parsed (optional)
240239

241240
**Example**:
242241

@@ -245,8 +244,7 @@ using CTBase
245244
throw(CTBase.Exceptions.ParsingError(
246245
"unexpected token 'end'",
247246
location="line 42, column 10",
248-
suggestion="Check for unmatched 'begin' or remove extra 'end'",
249-
context="control flow parsing"
247+
suggestion="Check for unmatched 'begin' or remove extra 'end'"
250248
))
251249
```
252250

@@ -282,9 +280,14 @@ end
282280
The enriched display automatically suggests:
283281

284282
```text
285-
❌ Error: ExtensionError, missing dependencies
286-
📦 Missing dependencies: Plots
287-
💡 Suggestion: julia> using Plots
283+
ExtensionError
284+
285+
│ missing dependencies
286+
287+
│ Missing Plots
288+
289+
│ Hint Run: using Plots
290+
└─
288291
```
289292

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

333336
```text
334-
❌ Error: SolverFailure, ODE integration failed
335-
🔧 Return code: :Unstable
336-
📂 Context: SciML integrator
337-
💡 Suggestion: Reduce time step or check initial conditions
337+
SolverFailure
338+
339+
│ ODE integration failed
340+
341+
│ Retcode :Unstable
342+
343+
│ Context SciML integrator
344+
│ Hint Reduce time step or check initial conditions
345+
└─
338346
```
339347

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

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

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

381389
Example of enriched display:
382390

383391
```text
384-
Control Toolbox Error
385-
386-
❌ Error: PreconditionError, System must be initialized before configuration
387-
❓ Reason: initialize! not called yet
388-
📂 Context: system configuration
389-
💡 Suggestion: Call initialize!(state) before configure!
390-
📍 In your code:
391-
configure! at MyModule.jl:42
392+
PreconditionError → configure! MyModule.jl:42
393+
394+
│ System must be initialized before configuration
395+
396+
│ Reason initialize! not called yet
397+
398+
│ Context system configuration
399+
│ Hint Call initialize!(state) before configure!
400+
└─
392401
```
393402

394403
This makes debugging faster by providing all the information needed to understand and fix the problem.

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CTBase.Descriptions.complete(:euler, :explicit; descriptions=descs)
4444
try
4545
throw(CTBase.Exceptions.IncorrectArgument("n must be positive"; got="-1"))
4646
catch e
47-
println(e)
47+
showerror(stdout, e)
4848
end
4949
```
5050

0 commit comments

Comments
 (0)