Commit ad4edb1
authored
Refactor stack traces: named frames, root frame, and builtin collapsing (#635)
## Summary
Rework error stack traces to produce cleaner, more informative output
using the existing Java stack trace mechanism (no custom call stack).
This is an alternative to #633 that avoids the performance regression by
resolving names at parse time and filtering frames during formatting
rather than maintaining a separate call stack.
### Key changes
- **Named frames from AST**: `callTargetName` extracts function names
from `Apply` AST nodes at the expression level (`[foo]`,
`[std.assertEqual]`, `[anonymous]`), replacing opaque node type names
like `[Apply0]`, `[Apply3]`.
- **Frame filtering**: Only `Apply*` and `ApplyBuiltin*` expression
frames are kept in stack traces, filtering out intermediate AST node
types that add noise.
- **Root frame**: Every stack trace now includes a `[<root>]` outermost
frame pointing to the top-level expression, injected by
`Interpreter.evaluateImpl`.
- **Builtin error collapsing**: When an error originates from inside a
builtin's Scala code (e.g., type checking, missing arguments), the
builtin name is collapsed into the error message as a prefix rather than
shown as a separate frame:
- `sjsonnet.Error: [std.manifestTomlEx] Wrong parameter type: expected
Object, got array`
- `sjsonnet.Error: [foo] Too many args, has 2 parameter(s)`
- **Same-position collapsing**: Adjacent frames at the same file
position are collapsed to avoid redundant lines.
- **Caused-by chain**: `formatError` now includes `Caused by:` output
for wrapped exceptions (e.g., native function panics).
- **Removed redundant prefixes**: `"Function "` prefix removed from
error messages since the frame name now provides that context.
### Example outputs
Builtin error (collapsed into message):
```
sjsonnet.Error: [std.assertEqual] assertEqual failed: {"x":1} != {"x":2}
at [<root>].(assert_equal4.jsonnet:1:16)
```
Function parameter error (collapsed):
```
sjsonnet.Error: [anonymous] parameter x not bound in call
at [<root>].(bad_function_call.jsonnet:1:16)
```
Error inside function body (full trace):
```
sjsonnet.Error: xxx
at [foo].(error_in_method.jsonnet:1:23)
at [<root>].(error_in_method.jsonnet:1:7)
```
Native function panic (with caused-by):
```
sjsonnet.Error: [std.nativePanic] Internal Error
at [<root>].(native_panic.jsonnet:1:26)
Caused by: java.lang.RuntimeException: native function panic
```
## Test plan
- [x] All JVM tests pass (140/140)
- [x] Golden files regenerated for test_suite, go_test_suite,
new_test_suite (340 files)
- [x] Unit test expectations updated (EvaluatorTests, StdFlatMapTests,
StdWithKeyFTests, Std0150FunctionsTests)
- [x] Native/extvar golden files manually verified (require special test
harness args)
- [x] JS BaseFileTests updated for new format1 parent d9b631d commit ad4edb1
361 files changed
Lines changed: 4860 additions & 4699 deletions
File tree
- sjsonnet
- src/sjsonnet
- test
- resources
- go_test_suite
- new_test_suite
- test_suite
- src-js/sjsonnet
- src/sjsonnet
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
21 | 26 | | |
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
25 | | - | |
26 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
27 | 34 | | |
28 | | - | |
| 35 | + | |
| 36 | + | |
29 | 37 | | |
30 | | - | |
| 38 | + | |
31 | 39 | | |
32 | 40 | | |
33 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
34 | 45 | | |
35 | 46 | | |
36 | 47 | | |
| |||
40 | 51 | | |
41 | 52 | | |
42 | 53 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
47 | 60 | | |
48 | 61 | | |
49 | 62 | | |
50 | 63 | | |
51 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
52 | 68 | | |
53 | 69 | | |
54 | 70 | | |
| |||
59 | 75 | | |
60 | 76 | | |
61 | 77 | | |
62 | | - | |
| 78 | + | |
| 79 | + | |
63 | 80 | | |
64 | 81 | | |
65 | 82 | | |
| |||
70 | 87 | | |
71 | 88 | | |
72 | 89 | | |
73 | | - | |
| 90 | + | |
74 | 91 | | |
75 | 92 | | |
76 | 93 | | |
77 | 94 | | |
78 | 95 | | |
79 | 96 | | |
80 | 97 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
89 | 174 | | |
90 | 175 | | |
91 | 176 | | |
92 | 177 | | |
93 | 178 | | |
94 | 179 | | |
95 | | - | |
| 180 | + | |
96 | 181 | | |
97 | 182 | | |
98 | 183 | | |
| |||
104 | 189 | | |
105 | 190 | | |
106 | 191 | | |
107 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
108 | 196 | | |
109 | 197 | | |
110 | 198 | | |
| |||
116 | 204 | | |
117 | 205 | | |
118 | 206 | | |
119 | | - | |
| 207 | + | |
120 | 208 | | |
121 | 209 | | |
122 | 210 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
826 | 826 | | |
827 | 827 | | |
828 | 828 | | |
829 | | - | |
| 829 | + | |
830 | 830 | | |
831 | 831 | | |
832 | 832 | | |
833 | | - | |
834 | | - | |
| 833 | + | |
835 | 834 | | |
836 | 835 | | |
837 | 836 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
48 | 59 | | |
49 | 60 | | |
50 | 61 | | |
| |||
212 | 223 | | |
213 | 224 | | |
214 | 225 | | |
| 226 | + | |
215 | 227 | | |
216 | 228 | | |
217 | 229 | | |
218 | 230 | | |
| 231 | + | |
219 | 232 | | |
220 | 233 | | |
221 | 234 | | |
222 | 235 | | |
| 236 | + | |
223 | 237 | | |
224 | 238 | | |
225 | 239 | | |
226 | 240 | | |
| 241 | + | |
227 | 242 | | |
228 | 243 | | |
229 | 244 | | |
| |||
234 | 249 | | |
235 | 250 | | |
236 | 251 | | |
| 252 | + | |
237 | 253 | | |
238 | 254 | | |
239 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
201 | 220 | | |
202 | 221 | | |
203 | 222 | | |
204 | 223 | | |
205 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
206 | 236 | | |
207 | 237 | | |
208 | 238 | | |
| |||
226 | 256 | | |
227 | 257 | | |
228 | 258 | | |
229 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
230 | 276 | | |
231 | 277 | | |
232 | 278 | | |
| |||
0 commit comments