Skip to content

Commit 067ce12

Browse files
add proper error handling
1 parent 0034fe1 commit 067ce12

File tree

7 files changed

+267
-90
lines changed

7 files changed

+267
-90
lines changed

web/renderer/components/DatabaseNav/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function DatabaseNav(props: Props) {
2626

2727
function Inner(props: Props) {
2828
const { isDolt, isPostgres } = useDatabaseDetails();
29-
29+
3030
return (
3131
<div data-cy="db-page-header-nav" className={css.headerNav}>
3232
<Tooltip id="disabled-database-nav-item" />
@@ -36,7 +36,7 @@ function Inner(props: Props) {
3636
if (tab === "Tests" && isDolt && isPostgres) {
3737
return null;
3838
}
39-
39+
4040
const item = <NavItem {...props} key={tab} name={tab} i={i} />;
4141
if (tab === "Database") {
4242
return item;

web/renderer/components/pageComponents/DatabasePage/ForPulls/PullActions/Merge/index.tsx

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,17 @@ function TestResultsListItem({
275275

276276
function TestResults({ params }: { params: RefParams }) {
277277
const [testResults, setTestResults] = useState<TestResult[]>([]);
278-
const [runTests] = useRunTestsLazyQuery();
279-
const { data } = useTestListQuery({
278+
const [runTestError, setRunTestError] = useState<string | null>(null);
279+
const [runTests, { error: runTestsError }] = useRunTestsLazyQuery();
280+
const { data, loading, error } = useTestListQuery({
280281
variables: {
281282
databaseName: params.databaseName,
282283
refName: params.refName,
283284
},
284285
});
285286

286287
const handleRunTests = useCallback(async () => {
288+
setRunTestError(null);
287289
try {
288290
const result = await runTests({
289291
variables: {
@@ -292,12 +294,50 @@ function TestResults({ params }: { params: RefParams }) {
292294
},
293295
});
294296

297+
if (result.error) {
298+
console.error("Error running tests:", result.error);
299+
setRunTestError(result.error.message);
300+
setTestResults([]);
301+
return;
302+
}
303+
295304
setTestResults(result.data?.runTests.list ?? []);
296-
} catch {
305+
} catch (err) {
306+
console.error("Error running tests:", err);
307+
setRunTestError(
308+
err instanceof Error ? err.message : "Failed to run tests",
309+
);
297310
setTestResults([]);
298311
}
299312
}, [runTests, params.databaseName, params.refName]);
300313

314+
if (loading) {
315+
return (
316+
<div className={css.testResultsOuter}>
317+
<SmallLoader.WithText text="Loading tests..." loaded={false} />
318+
</div>
319+
);
320+
}
321+
322+
if (error) {
323+
console.error("Error loading test list:", error);
324+
return (
325+
<div className={css.testResultsOuter}>
326+
<div className={css.testResultsContainer}>
327+
<div className={css.testResultsTop}>
328+
<span style={{ color: "red" }}>
329+
Failed to load tests: {error.message}
330+
</span>
331+
</div>
332+
</div>
333+
</div>
334+
);
335+
}
336+
337+
if (runTestsError) {
338+
console.error("Run Tests query error:", runTestsError);
339+
}
340+
301341
if (!data?.tests.list || data.tests.list.length === 0) {
302342
return null;
303343
}
@@ -338,6 +378,11 @@ function TestResults({ params }: { params: RefParams }) {
338378
[css.testResultsTestsOrange]: orange,
339379
})}
340380
>
381+
{(runTestError || runTestsError) && (
382+
<div style={{ color: "red", padding: "8px" }}>
383+
Error running tests: {runTestError || runTestsError?.message}
384+
</div>
385+
)}
341386
<ul>
342387
{testResults.length > 0 ? (
343388
testResults.map(test => (

web/renderer/components/pageComponents/DatabasePage/ForTests/TestList/index.module.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@
7474
@apply text-center text-lg m-6;
7575
}
7676

77+
.errorContainer {
78+
@apply text-center m-6;
79+
}
80+
81+
.errorText {
82+
@apply text-red-600 text-lg;
83+
}
84+
7785
.fieldInput {
7886
@apply w-full p-2 border border-stone-100 rounded text-sm;
7987
}

web/renderer/components/pageComponents/DatabasePage/ForTests/TestList/index.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export default function TestList({ params }: Props) {
2626
groupedTests,
2727
sortedGroupEntries,
2828
emptyGroups,
29+
testsLoading,
30+
testsError,
2931
setState,
3032
handleRunAll,
3133
handleHashNavigation,
@@ -66,26 +68,28 @@ export default function TestList({ params }: Props) {
6668
<div className={css.container}>
6769
<div className={css.top}>
6870
<h1>Tests</h1>
69-
<div className={css.actionArea}>
70-
<div className={css.createActions}>
71-
<HideForNoWritesWrapper params={params}>
72-
<CreateDropdown
73-
onCreateGroup={() => setShowNewGroupModal(true)}
74-
/>
75-
</HideForNoWritesWrapper>
76-
<Link {...workingDiff(params)}>
77-
<Button>Commit</Button>
78-
</Link>
79-
</div>
71+
{!testsLoading && !testsError && (
72+
<div className={css.actionArea}>
73+
<div className={css.createActions}>
74+
<HideForNoWritesWrapper params={params}>
75+
<CreateDropdown
76+
onCreateGroup={() => setShowNewGroupModal(true)}
77+
/>
78+
</HideForNoWritesWrapper>
79+
<Link {...workingDiff(params)}>
80+
<Button>Commit</Button>
81+
</Link>
82+
</div>
8083

81-
<div className={css.primaryActions}>
82-
{tests.length > 0 && (
83-
<Button onClick={handleRunAll} className={css.runAllButton}>
84-
Run All
85-
</Button>
86-
)}
84+
<div className={css.primaryActions}>
85+
{tests.length > 0 && (
86+
<Button onClick={handleRunAll} className={css.runAllButton}>
87+
Run All
88+
</Button>
89+
)}
90+
</div>
8791
</div>
88-
</div>
92+
)}
8993
</div>
9094

9195
<NewGroupModal
@@ -125,6 +129,12 @@ export default function TestList({ params }: Props) {
125129
)}
126130
</div>
127131
</div>
132+
) : testsError ? (
133+
<div className={css.errorContainer}>
134+
<p className={css.errorText}>Failed to load tests: {testsError}</p>
135+
</div>
136+
) : testsLoading ? (
137+
<p className={css.loading}>Loading tests...</p>
128138
) : (
129139
<p className={css.noTests}>No tests found</p>
130140
)}

0 commit comments

Comments
 (0)