From 3cb2a8fc8e66d573da9eb21f31f514db7ea260df Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Mon, 23 Oct 2023 10:36:47 +0900 Subject: [PATCH 1/2] Refactor error handling to use error.As --- main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index d1acc1f..2e18560 100644 --- a/main.go +++ b/main.go @@ -473,8 +473,9 @@ func initConfig() { // If a config file is found, read it in. if err := viper.ReadInConfig(); err != nil { - if _, ok := err.(viper.ConfigFileNotFoundError); !ok { - fmt.Fprintln(os.Stderr, err) + var configNotFoundError *viper.ConfigFileNotFoundError + if !errors.As(err, &configNotFoundError) { + fmt.Fprintln(os.Stderr, "failed to read config file:", err) return } } From 7435a44939ee53506af353bf1a952627b1818a19 Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Mon, 23 Oct 2023 10:38:54 +0900 Subject: [PATCH 2/2] Fixed unnecessary mutex definition --- oviewer/input_test.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/oviewer/input_test.go b/oviewer/input_test.go index 5e68b12..bb2447c 100644 --- a/oviewer/input_test.go +++ b/oviewer/input_test.go @@ -1,7 +1,6 @@ package oviewer import ( - "sync" "testing" "github.com/gdamore/tcell/v2" @@ -117,7 +116,6 @@ func TestInput_keyEvent(t *testing.T) { func Test_candidate_up(t *testing.T) { type fields struct { - mux sync.Mutex list []string p int } @@ -145,11 +143,9 @@ func Test_candidate_up(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - c := &candidate{ - mux: tt.fields.mux, - list: tt.fields.list, - p: tt.fields.p, - } + c := searchCandidate() + c.list = tt.fields.list + c.p = tt.fields.p if got := c.up(); got != tt.want { t.Errorf("candidate.up() = %v, want %v", got, tt.want) } @@ -159,7 +155,6 @@ func Test_candidate_up(t *testing.T) { func Test_candidate_down(t *testing.T) { type fields struct { - mux sync.Mutex list []string p int } @@ -187,11 +182,9 @@ func Test_candidate_down(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - c := &candidate{ - mux: tt.fields.mux, - list: tt.fields.list, - p: tt.fields.p, - } + c := searchCandidate() + c.list = tt.fields.list + c.p = tt.fields.p if got := c.down(); got != tt.want { t.Errorf("candidate.down() = %v, want %v", got, tt.want) }