Skip to content

Commit 41ec1ab

Browse files
authored
storage: include received value in slice-type panic messages (#243)
The mustScmerSlice / decodePerTableInts / normalizePartitionDataset panics previously printed only the parameter name ("filterColumns: expected list"), which forced developers to reverse-engineer which eval'd codegen shape was at fault. Render the received value via scm.String (truncated to 200 chars) so the panic identifies the wrong token directly. Verified: make test green on worktree.
1 parent 814dc78 commit 41ec1ab

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

storage/storage.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func normalizePartitionDataset(arg scm.Scmer) dataset {
147147
for _, item := range raw {
148148
pair := mustScmerSlice(item, "partition column pair")
149149
if len(pair) != 2 {
150-
panic("invalid partition column pair")
150+
panic(fmt.Sprintf("invalid partition column pair: expected (column value), got %s", describeScmerValue(item)))
151151
}
152152
normalized = append(normalized, pair[0], pair[1])
153153
}
@@ -252,11 +252,25 @@ func scmerSlice(v scm.Scmer) ([]scm.Scmer, bool) {
252252
return nil, false
253253
}
254254

255+
// describeScmerValue renders v for use in a panic message. Long values
256+
// (entire codegen'd expressions) are truncated so the panic stays readable.
257+
func describeScmerValue(v scm.Scmer) string {
258+
const maxLen = 200
259+
if v.IsNil() {
260+
return "nil"
261+
}
262+
s := scm.String(v)
263+
if len(s) > maxLen {
264+
return s[:maxLen] + "…"
265+
}
266+
return s
267+
}
268+
255269
func mustScmerSlice(v scm.Scmer, ctx string) []scm.Scmer {
256270
if slice, ok := scmerSlice(v); ok {
257271
return slice
258272
}
259-
panic(ctx + ": expected list")
273+
panic(fmt.Sprintf("%s: expected list, got %s", ctx, describeScmerValue(v)))
260274
}
261275

262276
func scmerSliceToStrings(list []scm.Scmer) []string {
@@ -279,7 +293,7 @@ func decodePerTableInts(v scm.Scmer, n int, ctx string) []int {
279293
}
280294
slice, ok := scmerSlice(v)
281295
if !ok {
282-
panic(ctx + ": expected list or nil")
296+
panic(fmt.Sprintf("%s: expected list or nil, got %s", ctx, describeScmerValue(v)))
283297
}
284298
if len(slice) != n {
285299
panic(fmt.Sprintf("%s: expected length %d, got %d", ctx, n, len(slice)))

0 commit comments

Comments
 (0)