Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Convert VisualizationError utils to TypeScript (#69062)

Fraserb746306e121b
diff --git a/frontend/src/metabase/query_builder/components/VisualizationError/VisualizationError.tsx b/frontend/src/metabase/query_builder/components/VisualizationError/VisualizationError.tsx
index 09525ce0542..9721c12229f 100644
--- a/frontend/src/metabase/query_builder/components/VisualizationError/VisualizationError.tsx
+++ b/frontend/src/metabase/query_builder/components/VisualizationError/VisualizationError.tsx
@@ -116,8 +116,8 @@ export function VisualizationError({
// always show errors for native queries
let processedError = typeof error === "string" ? error : error.data;
const origSql = getIn(via, [(via || "").length - 1, "ex-data", "sql"]);
- if (typeof origSql === "string") {
- processedError = adjustPositions(error, origSql);
+ if (typeof origSql === "string" && processedError) {
+ processedError = adjustPositions(processedError, origSql);
}
processedError = stripRemarks(processedError);
const database = question.database();
diff --git a/frontend/src/metabase/query_builder/components/VisualizationError/utils.jsx b/frontend/src/metabase/query_builder/components/VisualizationError/utils.ts
similarity index 91%
rename from frontend/src/metabase/query_builder/components/VisualizationError/utils.jsx
rename to frontend/src/metabase/query_builder/components/VisualizationError/utils.ts
index 5d763b2ada6..14e2778c31e 100644
--- a/frontend/src/metabase/query_builder/components/VisualizationError/utils.jsx
+++ b/frontend/src/metabase/query_builder/components/VisualizationError/utils.ts
@@ -1,4 +1,4 @@
-export function adjustPositions(error, origSql) {
+export function adjustPositions(error: string, origSql: string): string {
/* Positions in error messages are borked coming in for Postgres errors.
* Previously, you would see "blahblahblah bombed out, Position: 119" in a 10-character invalid query.
* This is because MB shoves in 'remarks' into the original query and we get the exception from the query with remarks.
@@ -33,11 +33,14 @@ export function adjustPositions(error, origSql) {
});
}
-export function stripRemarks(error) {
+export function stripRemarks(error: string | undefined): string {
/* SQL snippets in error messages are borked coming in for errors in many DBs.
* You're expecting something with just your sql in the message,
* but the whole error contains these remarks that MB added in. Confusing!
*/
+ if (!error) {
+ return "";
+ }
return error.replace(
/-- Metabase:: userID: \d+ queryType: native queryHash: \w+\n/,
"",