Skip to content

Commit

Permalink
chore: add some logs for clarification when there are parse errors in…
Browse files Browse the repository at this point in the history
… the CLI (#5328)

* Add some logs for clarification when there are parse errors in the CLI

* more logging

* only log the --ignore-additional-command-line-flags thing if necessary

* disable the GPU in e2e tests

* specify generic desktop environment

* seems like the form field does not immediately update

* print cli errors when caught

* remove logging that seems to fool mocha

* test

* Revert "test"

This reverts commit a8907d3.

* shorten the timeout again
  • Loading branch information
lerouxb committed Jan 11, 2024
1 parent 1df00d7 commit 8c64dee
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
3 changes: 3 additions & 0 deletions packages/compass-e2e-tests/helpers/chrome-startup-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const CI_FLAGS = [
// Evergren RHEL ci runs everything as root, and chrome will not start as
// root without this flag
'--no-sandbox',
// Seeing gpu init related errors on at least RHEL, especially when starting
// the CLI
'--disable-gpu',
];

// These flags are used to start Chrome driver based on the Compass requirements.
Expand Down
8 changes: 7 additions & 1 deletion packages/compass-e2e-tests/helpers/compass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,13 @@ export async function runCompassOnce(args: string[], timeout = 30_000) {
`--user-data-dir=${String(defaultUserDataDir)}`,
...args,
],
{ timeout }
{
timeout,
env: {
...process.env,
DE: 'generic', // for xdg-settings: unknown desktop environment
},
}
);
debug('Ran compass with args', { args, stdout, stderr });
return { stdout, stderr };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ describe('Connection Import / Export', function () {
await browser.selectFavorite(favoriteName);
await browser.clickVisible(Selectors.EditConnectionStringToggle);
await browser.clickVisible(Selectors.ConfirmationModalConfirmButton());
expect(await browser.getConnectFormConnectionString(true)).to.equal(
variant === 'protected'
? connectionStringWithoutCredentials
: connectionString
);
await browser.waitUntil(async () => {
const cs = await browser.getConnectFormConnectionString(true);
const expected =
variant === 'protected'
? connectionStringWithoutCredentials
: connectionString;
return cs === expected;
});
await browser.selectFavorite(favoriteName);
await browser.selectConnectionMenuItem(
favoriteName,
Expand Down Expand Up @@ -203,7 +206,7 @@ describe('Connection Import / Export', function () {
// it takes to save a favorite in e2e tests, and so the result of that
// initial load would override the favorite saving (from the point of view
// of the connection sidebar at least). Add a timeout to make this less flaky. :(
await new Promise((resolve) => setTimeout(resolve, 2000));
await new Promise((resolve) => setTimeout(resolve, 5000));

await browser.saveFavorite(favoriteName, 'color3');
});
Expand Down
27 changes: 22 additions & 5 deletions packages/compass/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ async function main(): Promise<void> {
return app.exit(0);
}

if (preferenceParseErrors.length > 0) {
const errorOutDueToAdditionalCommandLineFlags =
preferenceParseErrors.length > 0 &&
!preferences.ignoreAdditionalCommandLineFlags;

if (errorOutDueToAdditionalCommandLineFlags) {
process.stderr.write(chalk.yellow(preferenceParseErrorsString) + '\n');
process.stderr.write(
'Use --ignore-additional-command-line-flags to allow passing additional options to Chromium/Electron\n'
);
}
const errorOutDueToAdditionalCommandLineFlags =
preferenceParseErrors.length > 0 &&
!preferences.ignoreAdditionalCommandLineFlags;

const importExportOptions = {
exportConnections: preferences.exportConnections,
Expand Down Expand Up @@ -101,9 +102,19 @@ async function main(): Promise<void> {
process.on('uncaughtException', handleUncaughtException);
} else {
if (errorOutDueToAdditionalCommandLineFlags) {
process.stderr.write(
'Exiting because there are parse errors and --ignore-additional-command-line-flags was not set\n'
);
return app.exit(1);
}
process.on('uncaughtException', (err) => {
process.stderr.write('Exiting due to uncaughtException:\n');
// eslint-disable-next-line no-console
console.error(err);
CompassApplication.runExitHandlers().finally(() => app.exit(1));
});
process.on('unhandledRejection', (err) => {
process.stderr.write('Exiting due to unhandledRejection:\n');
// eslint-disable-next-line no-console
console.error(err);
CompassApplication.runExitHandlers().finally(() => app.exit(1));
Expand All @@ -113,7 +124,13 @@ async function main(): Promise<void> {
try {
await CompassApplication.init(mode, globalPreferences);
} catch (e) {
await handleUncaughtException(e as Error);
if (mode === 'CLI') {
process.stderr.write('Exiting due to try/catch:\n');
// eslint-disable-next-line no-console
console.error(e);
} else {
await handleUncaughtException(e as Error);
}
await CompassApplication.runExitHandlers().finally(() => app.exit(1));
return;
}
Expand Down

0 comments on commit 8c64dee

Please sign in to comment.