Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a better error message when Chromium isn't found #1137

Merged
merged 8 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add ErrChromeNotFoundAtPath
  • Loading branch information
inancgumus committed Dec 15, 2023
commit d04dbeca865081a3ee9dcb94a6ca707d541fdd74
11 changes: 8 additions & 3 deletions chromium/browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions chromium/browser_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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,
Expand All @@ -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: "",
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
Loading