Skip to content

Commit acdd909

Browse files
committed
🐛 fix error messages
1 parent ae1a805 commit acdd909

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/spf13/cobra"
2121
)
2222

23-
var version = "1.2.3"
23+
var version = "1.2.4"
2424

2525
var rootCmd = &cobra.Command{
2626
Use: "git-profile",

cmd/unset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ func runUnset(cmd *cobra.Command, _ []string) {
4949

5050
err := internal.UnsetUserName(global)
5151
if err != nil {
52-
fmt.Println(err)
52+
fmt.Printf("error: %v\n", err)
5353
}
5454

5555
err = internal.UnsetUserEmail(global)
5656
if err != nil {
57-
fmt.Println(err)
57+
fmt.Printf("error: %v\n\n", err)
5858
}
5959
}
6060

custom_errors/not_set.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ import "fmt"
44

55
type NotSetError struct {
66
ConfigName string
7+
Global bool
78
}
89

910
func (e *NotSetError) Error() string {
10-
return fmt.Sprintf("no local %s set", e.ConfigName)
11+
var configType string
12+
13+
if e.Global {
14+
configType = "global"
15+
} else {
16+
configType = "local"
17+
}
18+
19+
return fmt.Sprintf("no %s %s set", configType, e.ConfigName)
1120
}

internal/git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func GetGlobalUserName() (string, error) {
195195

196196
ok := errors.As(err, &exitError)
197197
if ok && exitError.ExitCode() == 1 && err.Error() == "exit status 1" {
198-
return "", &custom_errors.NotSetError{ConfigName: "global username"}
198+
return "", &custom_errors.NotSetError{ConfigName: "username", Global: true}
199199
} else {
200200
return "", err
201201
}
@@ -215,7 +215,7 @@ func GetGlobalUserEmail() (string, error) {
215215

216216
ok := errors.As(err, &exitError)
217217
if ok && exitError.ExitCode() == 1 && err.Error() == "exit status 1" {
218-
return "", &custom_errors.NotSetError{ConfigName: "global email"}
218+
return "", &custom_errors.NotSetError{ConfigName: "email", Global: true}
219219
} else {
220220
return "", err
221221
}

0 commit comments

Comments
 (0)