Skip to content

Commit

Permalink
customize error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoisaiah committed Oct 11, 2024
1 parent f8b0300 commit 6820ad2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion f2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

var errConflictDetected = &apperr.Error{
Message: "resolve conflicts manually or use -F/--fix-conflicts",
Message: "conflict: resolve manually or use -F/--fix-conflicts",
}

// execute initiates a new renaming operation based on the provided CLI context.
Expand Down
13 changes: 12 additions & 1 deletion report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package report

import (
"os"
"strings"

"github.com/pterm/pterm"

Expand All @@ -15,9 +16,19 @@ import (

func ExitWithErr(err error) {
pterm.EnableOutput()

errPrefix := "error:"
errMessage := err.Error()

s := strings.Split(errMessage, ":")
if len(s) > 1 {
errPrefix = strings.TrimSpace(s[0] + ":")
errMessage = strings.TrimSpace(s[1])
}

pterm.Fprintln(
config.Stderr,
pterm.Sprintf("%s %v", pterm.Red("error:"), err),
pterm.Sprintf("%s %v", pterm.Red(errPrefix), errMessage),
)
os.Exit(int(osutil.ExitError))
}
Expand Down

0 comments on commit 6820ad2

Please sign in to comment.