From aa92b422fc9c59cb171236faa5538022b889e5c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Henrique=20Guard=C3=A3o=20Gandarez?= Date: Thu, 17 Aug 2023 16:51:52 -0300 Subject: [PATCH] Catch panic for Chroma analyze text --- pkg/language/chroma.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/language/chroma.go b/pkg/language/chroma.go index b1233c0f..225ebe4f 100644 --- a/pkg/language/chroma.go +++ b/pkg/language/chroma.go @@ -5,6 +5,7 @@ import ( "io" "os" fp "path/filepath" + "runtime/debug" "sort" "strings" @@ -124,6 +125,12 @@ func detectChromaCustomized(filepath string) (heartbeat.Language, float32, bool) // analyse text content and return the "best" lexer. // This is a copy of chroma.lexers.internal.api:Analyse(). func analyse(text string) chroma.Lexer { + defer func() { + if err := recover(); err != nil { + log.Errorf("panicked: %v. Stack: %s", err, string(debug.Stack())) + } + }() + var picked chroma.Lexer highest := float32(0.0)