mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-04-24 20:56:17 +02:00
05b27c390d
This way we don't have to update the text and all translations every time we bump the version. Remove the year from the error text, it's cumbersome to update and I don't find it very important to have in the message. Also remove the invitation to file an issue; I don't find it very likely that we are going to relax the minimum git requirement again.
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
|
"github.com/samber/lo"
|
|
)
|
|
|
|
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{minGitVersionErrorMessage(tr)}
|
|
|
|
if lo.Contains(knownErrorMessages, errorMessage) {
|
|
return errorMessage, true
|
|
}
|
|
|
|
mappings := []errorMapping{
|
|
{
|
|
originalError: "fatal: not a git repository",
|
|
newError: tr.NotARepository,
|
|
},
|
|
{
|
|
originalError: "getwd: no such file or directory",
|
|
newError: tr.WorkingDirectoryDoesNotExist,
|
|
},
|
|
}
|
|
|
|
if mapping, ok := lo.Find(mappings, func(mapping errorMapping) bool {
|
|
return strings.Contains(errorMessage, mapping.originalError)
|
|
}); ok {
|
|
return mapping.newError, true
|
|
}
|
|
|
|
return "", false
|
|
}
|