Skip to content

Commit 49190d1

Browse files
alecthomasclaude
andcommitted
fix: panic loudly if the fallback style is missing
Fallback was a raw map index: if swapoff.xml were ever renamed or removed it would silently become nil and GetForMode would nil-panic at first use. Fail at init with a clear message instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 1ccaeea commit 49190d1

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

styles/api.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ var registry = func() map[string]*chroma.Style {
3838
}()
3939

4040
// Fallback style. Reassign to change the default fallback style.
41-
var Fallback = registry["swapoff"]
41+
var Fallback = func() *chroma.Style {
42+
fallback := registry["swapoff"]
43+
if fallback == nil {
44+
panic(`chroma/styles: default fallback style "swapoff" is missing`)
45+
}
46+
return fallback
47+
}()
4248

4349
// Register a chroma.Style.
4450
//

0 commit comments

Comments
 (0)