Skip to content

Commit

Permalink
Catch and surface more errors (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
whscullin authored Oct 30, 2024
1 parent 8287cb7 commit a975e38
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
14 changes: 12 additions & 2 deletions packages/query-composer/src/hooks/use_query_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface UseQueryBuilderResult {
queryModifiers: QueryModifiers;
querySummary: QuerySummary | undefined;
query: string;
error: Error | undefined;
}

export interface QueryModifiers {
Expand Down Expand Up @@ -136,6 +137,7 @@ export function useQueryBuilder(
const [querySummary, setQuerySummary] = useState(
queryBuilder.getQuerySummary()
);
const [error, setError] = useState<Error>();

useEffect(() => {
console.info('> sourceDef changed');
Expand All @@ -146,6 +148,7 @@ export function useQueryBuilder(
const modifyQuery = useCallback(
(modify: (queryBuilder: QueryBuilder) => void, noURLUpdate = false) => {
const backup = JSON.parse(JSON.stringify(queryBuilder.getQuery()));
setError(undefined);
modify(queryBuilder);
if (queryBuilder.canRun()) {
try {
Expand All @@ -158,11 +161,17 @@ export function useQueryBuilder(
}
} catch (error) {
queryBuilder.setQuery(backup);
// eslint-disable-next-line no-console
console.error(error);
setError(error as Error);
}
}
setQuerySummary(queryBuilder.getQuerySummary());
try {
setQuerySummary(queryBuilder.getQuerySummary());
} catch (error) {
queryBuilder.setQuery(backup);
console.error(error);
setError(error as Error);
}
},
[queryBuilder, updateQueryInURL]
);
Expand Down Expand Up @@ -390,5 +399,6 @@ export function useQueryBuilder(
querySummary,
queryModifiers,
query: queryMalloy.notebook,
error,
};
}
32 changes: 25 additions & 7 deletions src/app/Explore/Explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const KEY_MAP = {
const compiler = new DummyCompile();

export const Explore: React.FC = () => {
const [error, setError] = useState<Error>();
const config = useApps();
const {appId} = useParams();
const onlyDefaultDataset =
Expand Down Expand Up @@ -119,14 +120,31 @@ export const Explore: React.FC = () => {
.pathname
: undefined;

const {queryMalloy, queryName, queryModifiers, querySummary} =
useQueryBuilder(modelDef, sourceName, modelPath, updateQueryInURL);
const {
error: builderError,
queryMalloy,
queryName,
queryModifiers,
querySummary,
} = useQueryBuilder(modelDef, sourceName, modelPath, updateQueryInURL);

const {error, result, runQuery, reset, isRunning} = useRunQuery(
modelDef,
modelPath,
runQueryExt
);
const {
error: runnerError,
result,
runQuery,
reset,
isRunning,
} = useRunQuery(modelDef, modelPath, runQueryExt);

useEffect(() => {
if (builderError) {
setError(builderError);
} else if (runnerError) {
setError(runnerError);
} else {
setError(undefined);
}
}, [builderError, runnerError]);

useEffect(() => {
if (loading > 0) {
Expand Down

0 comments on commit a975e38

Please sign in to comment.