Skip to content

Commit ad2c065

Browse files
author
Dave Bartolomeo
committed
Better error message UI for bad debug configuration
1 parent 55644d5 commit ad2c065

File tree

1 file changed

+46
-41
lines changed

1 file changed

+46
-41
lines changed

extensions/ql-vscode/src/debugger/debug-configuration.ts

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getOnDiskWorkspaceFolders, showAndLogErrorMessage } from "../helpers";
88
import { LocalQueries } from "../local-queries";
99
import { getQuickEvalContext, validateQueryPath } from "../run-queries-shared";
1010
import * as CodeQLProtocol from "./debug-protocol";
11+
import { getErrorMessage } from "../pure/helpers-pure";
1112

1213
/**
1314
* The CodeQL launch arguments, as specified in "launch.json".
@@ -76,52 +77,56 @@ export class QLDebugConfigurationProvider
7677
debugConfiguration: DebugConfiguration,
7778
_token?: CancellationToken,
7879
): Promise<DebugConfiguration | null> {
79-
const qlConfiguration = debugConfiguration as QLDebugConfiguration;
80-
if (qlConfiguration.query === undefined) {
81-
void showAndLogErrorMessage(
82-
"No query was specified in the debug configuration.",
83-
);
84-
return null;
85-
}
86-
if (qlConfiguration.database === undefined) {
87-
void showAndLogErrorMessage(
88-
"No database was specified in the debug configuration.",
89-
);
90-
return null;
91-
}
80+
try {
81+
const qlConfiguration = debugConfiguration as QLDebugConfiguration;
82+
if (qlConfiguration.query === undefined) {
83+
throw new Error("No query was specified in the debug configuration.");
84+
}
85+
if (qlConfiguration.database === undefined) {
86+
throw new Error(
87+
"No database was specified in the debug configuration.",
88+
);
89+
}
9290

93-
// Fill in defaults here, instead of in `resolveDebugConfiguration`, to avoid the highly
94-
// unusual case where one of the computed default values looks like a variable substitution.
95-
const additionalPacks = makeArray(
96-
qlConfiguration.additionalPacks ?? getOnDiskWorkspaceFolders(),
97-
);
91+
// Fill in defaults here, instead of in `resolveDebugConfiguration`, to avoid the highly
92+
// unusual case where one of the computed default values looks like a variable substitution.
93+
const additionalPacks = makeArray(
94+
qlConfiguration.additionalPacks ?? getOnDiskWorkspaceFolders(),
95+
);
9896

99-
// Default to computing the extension packs based on the extension configuration and the search
100-
// path.
101-
const extensionPacks = makeArray(
102-
qlConfiguration.extensionPacks ??
103-
(await this.localQueries.getDefaultExtensionPacks(additionalPacks)),
104-
);
97+
// Default to computing the extension packs based on the extension configuration and the search
98+
// path.
99+
const extensionPacks = makeArray(
100+
qlConfiguration.extensionPacks ??
101+
(await this.localQueries.getDefaultExtensionPacks(additionalPacks)),
102+
);
105103

106-
const quickEval = qlConfiguration.quickEval ?? false;
107-
validateQueryPath(qlConfiguration.query, quickEval);
104+
const quickEval = qlConfiguration.quickEval ?? false;
105+
validateQueryPath(qlConfiguration.query, quickEval);
108106

109-
const quickEvalContext = quickEval
110-
? await getQuickEvalContext(undefined)
111-
: undefined;
107+
const quickEvalContext = quickEval
108+
? await getQuickEvalContext(undefined)
109+
: undefined;
112110

113-
const resultConfiguration: QLResolvedDebugConfiguration = {
114-
name: qlConfiguration.name,
115-
request: qlConfiguration.request,
116-
type: qlConfiguration.type,
117-
query: qlConfiguration.query,
118-
database: qlConfiguration.database,
119-
additionalPacks,
120-
extensionPacks,
121-
quickEvalContext,
122-
noDebug: qlConfiguration.noDebug ?? false,
123-
};
111+
const resultConfiguration: QLResolvedDebugConfiguration = {
112+
name: qlConfiguration.name,
113+
request: qlConfiguration.request,
114+
type: qlConfiguration.type,
115+
query: qlConfiguration.query,
116+
database: qlConfiguration.database,
117+
additionalPacks,
118+
extensionPacks,
119+
quickEvalContext,
120+
noDebug: qlConfiguration.noDebug ?? false,
121+
};
124122

125-
return resultConfiguration;
123+
return resultConfiguration;
124+
} catch (e) {
125+
// Any unhandled exception will result in an OS-native error message box, which seems ugly.
126+
// We'll just show a real VS Code error message, then return null to prevent the debug session
127+
// from starting.
128+
void showAndLogErrorMessage(getErrorMessage(e));
129+
return null;
130+
}
126131
}
127132
}

0 commit comments

Comments
 (0)