From 8f9fddb23a563f2b78f7f1a4fb782a092809ab3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 14 Dec 2023 16:38:33 +0300 Subject: [PATCH] Add ErrChromeNotFoundAtPath --- chromium/browser_type.go | 11 ++++++++--- chromium/browser_type_test.go | 18 +++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/chromium/browser_type.go b/chromium/browser_type.go index 50c48b5b8..c51441c6c 100644 --- a/chromium/browser_type.go +++ b/chromium/browser_type.go @@ -247,8 +247,13 @@ func (b *BrowserType) allocate( return common.NewLocalBrowserProcess(bProcCtx, path, args, dataDir, bProcCtxCancel, logger) //nolint: wrapcheck } -// ErrChromeNotInstalled is returned when the Chrome executable is not found. -var ErrChromeNotInstalled = errors.New("neither chrome nor chromium is installed on this system") +var ( + // ErrChromeNotInstalled is returned when the Chrome executable is not found. + ErrChromeNotInstalled = errors.New("neither chrome nor chromium is installed on this system") + + // ErrChromeNotFoundAtPath is returned when the Chrome executable is not found at the given path. + ErrChromeNotFoundAtPath = errors.New("neither chrome nor chromium found on the path") +) // executablePath returns the path where the extension expects to find the browser executable. func executablePath( @@ -261,7 +266,7 @@ func executablePath( if _, err := lookPath(path); err == nil { return path, nil } - return "", ErrChromeNotInstalled + return "", fmt.Errorf("%w: %s", ErrChromeNotFoundAtPath, path) } // find the browser executable in the default paths below diff --git a/chromium/browser_type_test.go b/chromium/browser_type_test.go index 66aabe2b1..9ad6fcb76 100644 --- a/chromium/browser_type_test.go +++ b/chromium/browser_type_test.go @@ -174,14 +174,14 @@ func TestExecutablePath(t *testing.T) { userProfile env.LookupFunc // user profile folder lookup wantPath string - wantErr bool + wantErr error }{ "without_chromium": { userProvidedPath: "", lookPath: fileNotExists, userProfile: env.EmptyLookup, wantPath: "", - wantErr: true, + wantErr: ErrChromeNotInstalled, }, "with_chromium": { userProvidedPath: "", @@ -193,14 +193,14 @@ func TestExecutablePath(t *testing.T) { }, userProfile: env.EmptyLookup, wantPath: chromiumExecutable, - wantErr: false, + wantErr: nil, }, "without_chromium_in_user_path": { userProvidedPath: userProvidedPath, lookPath: fileNotExists, userProfile: env.EmptyLookup, wantPath: "", - wantErr: true, + wantErr: ErrChromeNotFoundAtPath, }, "with_chromium_in_user_path": { userProvidedPath: userProvidedPath, @@ -212,14 +212,14 @@ func TestExecutablePath(t *testing.T) { }, userProfile: env.EmptyLookup, wantPath: userProvidedPath, - wantErr: false, + wantErr: nil, }, "without_chromium_in_user_profile": { userProvidedPath: "", lookPath: fileNotExists, userProfile: env.ConstLookup("USERPROFILE", `home`), wantPath: "", - wantErr: true, + wantErr: ErrChromeNotInstalled, }, "with_chromium_in_user_profile": { userProvidedPath: "", @@ -231,7 +231,7 @@ func TestExecutablePath(t *testing.T) { }, userProfile: env.ConstLookup("USERPROFILE", `home`), wantPath: filepath.Join("home", `AppData\Local\Google\Chrome\Application\chrome.exe`), - wantErr: false, + wantErr: nil, }, } for name, tt := range tests { @@ -243,8 +243,8 @@ func TestExecutablePath(t *testing.T) { assert.Equal(t, tt.wantPath, path) - if tt.wantErr { - assert.Error(t, err) + if tt.wantErr != nil { + assert.ErrorIs(t, err, tt.wantErr) return } assert.NoError(t, err)