Skip to content

Commit c9d8438

Browse files
committed
chore: source generate fix
1 parent 1d5531f commit c9d8438

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

internal/hclparse/generate.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,19 @@ func quotedStringTokens(value string) hclwrite.Tokens {
254254
}
255255

256256
// resolvedSourceFile extracts the originating HCL filename from a resolved
257-
// autoinclude, used to enrich panic messages with file context. Returns ""
258-
// when resolved or its body is nil.
257+
// autoinclude, used to enrich panic messages with file context. Reads the
258+
// SrcRange struct field on the known concrete body type so no interface
259+
// method is invoked — this keeps the helper panic-safe even when called
260+
// from inside a panic formatter.
259261
func resolvedSourceFile(resolved *AutoIncludeResolved) string {
260-
if resolved == nil || resolved.RawBody == nil {
262+
if resolved == nil {
263+
return ""
264+
}
265+
266+
body, ok := resolved.RawBody.(*hclsyntax.Body)
267+
if !ok || body == nil {
261268
return ""
262269
}
263270

264-
return resolved.RawBody.MissingItemRange().Filename
271+
return body.SrcRange.Filename
265272
}

0 commit comments

Comments
 (0)