Commit f0e1def
authored
Quality: Unsafe type assertion in panic recovery will re-panic for non-error values (#1295)
## Problem
Both `FormatterFunc.Format` and `recoveringFormatter.Format` use
`perr.(error)` to
convert the recovered panic value to an error. This is a bare type
assertion (no comma-ok),
so if the panic value is not an `error` (e.g., `panic("something")`,
`panic(42)` — both
common idioms in Go and in third-party code), the type assertion itself
panics with
"interface conversion: interface is string, not error". This completely
defeats the purpose
of the panic-recovery wrapper, crashing the caller instead of converting
the panic to an error.
This affects both recover sites (FormatterFunc at ~line 18 and
recoveringFormatter at ~line 30).
**Severity**: `high`
**File**: `formatter.go`
## Solution
Replace the bare type assertion with a type switch or comma-ok pattern
at both sites:
In FormatterFunc.Format (line ~18):
## Changes
- `formatter.go` (modified)
## Testing
- [ ] Existing tests pass
- [ ] Manual review completed
- [ ] No new warnings/errors introduced
Signed-off-by: kumburovicbranko682-boop <295886834+kumburovicbranko682-boop@users.noreply.github.com>1 parent 4224e71 commit f0e1def
1 file changed
Lines changed: 11 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
| |||
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
37 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
| |||
0 commit comments