Skip to content

Commit 07fb81a

Browse files
authored
fix(launcher): improve error message for missing channel distribution (#6380)
1 parent 018f314 commit 07fb81a

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

src/server/chromium/findChromiumChannel.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@
1717
import path from 'path';
1818
import { canAccessFile } from '../../utils/utils';
1919

20-
function darwin(channel: string): string | undefined {
20+
function darwin(channel: string): string[] | undefined {
2121
switch (channel) {
22-
case 'chrome': return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
23-
case 'chrome-beta': return '/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta';
24-
case 'chrome-dev': return '/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev';
25-
case 'chrome-canary': return '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary';
26-
case 'msedge': return '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge';
27-
case 'msedge-beta': return '/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta';
28-
case 'msedge-dev': return '/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev';
29-
case 'msedge-canary': return '/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary';
22+
case 'chrome': return ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'];
23+
case 'chrome-beta': return ['/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta'];
24+
case 'chrome-dev': return ['/Applications/Google Chrome Dev.app/Contents/MacOS/Google Chrome Dev'];
25+
case 'chrome-canary': return ['/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'];
26+
case 'msedge': return ['/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge'];
27+
case 'msedge-beta': return ['/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta'];
28+
case 'msedge-dev': return ['/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev'];
29+
case 'msedge-canary': return ['/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary'];
3030
}
3131
}
3232

33-
function linux(channel: string): string | undefined {
33+
function linux(channel: string): string[] | undefined {
3434
switch (channel) {
35-
case 'chrome': return '/opt/google/chrome/chrome';
36-
case 'chrome-beta': return '/opt/google/chrome-beta/chrome';
37-
case 'chrome-dev': return '/opt/google/chrome-unstable/chrome';
38-
case 'msedge-dev': return '/opt/microsoft/msedge-dev/msedge';
35+
case 'chrome': return ['/opt/google/chrome/chrome'];
36+
case 'chrome-beta': return ['/opt/google/chrome-beta/chrome'];
37+
case 'chrome-dev': return ['/opt/google/chrome-unstable/chrome'];
38+
case 'msedge-dev': return ['/opt/microsoft/msedge-dev/msedge'];
3939
}
4040
}
4141

42-
function win32(channel: string): string | undefined {
42+
function win32(channel: string): string[] | undefined {
4343
let suffix: string | undefined;
4444
switch (channel) {
4545
case 'chrome': suffix = `\\Google\\Chrome\\Application\\chrome.exe`; break;
@@ -56,29 +56,27 @@ function win32(channel: string): string | undefined {
5656
const prefixes = [
5757
process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']
5858
].filter(Boolean) as string[];
59-
60-
let result: string | undefined;
61-
prefixes.forEach(prefix => {
62-
const chromePath = path.join(prefix, suffix!);
63-
if (canAccessFile(chromePath))
64-
result = chromePath;
65-
});
66-
return result;
59+
return prefixes.map(prefix => path.join(prefix, suffix!));
6760
}
6861

6962
export function findChromiumChannel(channel: string): string {
70-
let result: string | undefined;
63+
let installationPaths: string[] | undefined;
7164
if (process.platform === 'linux')
72-
result = linux(channel);
65+
installationPaths = linux(channel);
7366
else if (process.platform === 'win32')
74-
result = win32(channel);
67+
installationPaths = win32(channel);
7568
else if (process.platform === 'darwin')
76-
result = darwin(channel);
69+
installationPaths = darwin(channel);
7770

78-
if (!result)
71+
if (!installationPaths)
7972
throw new Error(`Chromium distribution '${channel}' is not supported on ${process.platform}`);
8073

81-
if (canAccessFile(result))
74+
let result: string | undefined;
75+
installationPaths.forEach(chromePath => {
76+
if (canAccessFile(chromePath))
77+
result = chromePath;
78+
});
79+
if (result)
8280
return result;
83-
throw new Error(`Chromium distribution was not found: ${channel}`);
81+
throw new Error(`Chromium distribution is not installed on the system: ${channel}`);
8482
}

0 commit comments

Comments
 (0)