2022-05-07 07:23:08 +02:00
package app
import (
"strings"
"github.com/jesseduffield/lazygit/pkg/i18n"
2023-07-24 05:06:42 +02:00
"github.com/samber/lo"
2022-05-07 07:23:08 +02:00
)
type errorMapping struct {
originalError string
newError string
}
// knownError takes an error and tells us whether it's an error that we know about where we can print a nicely formatted version of it rather than panicking with a stack trace
func knownError ( tr * i18n . TranslationSet , err error ) ( string , bool ) {
errorMessage := err . Error ( )
knownErrorMessages := [ ] string { tr . MinGitVersionError }
2023-07-24 05:06:42 +02:00
if lo . Contains ( knownErrorMessages , errorMessage ) {
2022-05-07 07:23:08 +02:00
return errorMessage , true
}
mappings := [ ] errorMapping {
{
originalError : "fatal: not a git repository" ,
newError : tr . NotARepository ,
} ,
}
2023-07-24 05:06:42 +02:00
if mapping , ok := lo . Find ( mappings , func ( mapping errorMapping ) bool {
2022-05-07 07:23:08 +02:00
return strings . Contains ( errorMessage , mapping . originalError )
} ) ; ok {
return mapping . newError , true
}
return "" , false
}