Skip to content

Commit

Permalink
Merge pull request #914 from wakatime/feature/chroma-panic
Browse files Browse the repository at this point in the history
Catch panic for Chroma analyze text
  • Loading branch information
gandarez authored Aug 17, 2023
2 parents e1cd975 + aa92b42 commit 5c6f222
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/language/chroma.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
fp "path/filepath"
"runtime/debug"
"sort"
"strings"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5c6f222

Please sign in to comment.