Have error boundary if simple job cannot be displayed due to the job being advanced

This commit is contained in:
Jaret Burkett
2025-03-27 19:55:40 -06:00
parent 3c95f87a90
commit b94d7aafea
2 changed files with 60 additions and 12 deletions

View File

@@ -19,6 +19,7 @@ import { Button } from '@headlessui/react';
import { FaChevronLeft } from 'react-icons/fa';
import SimpleJob from './SimpleJob';
import AdvancedJob from './AdvancedJob';
import ErrorBoundary from '@/components/ErrorBoundary';
import { apiClient } from '@/utils/api';
const isDev = process.env.NODE_ENV === 'development';
@@ -179,21 +180,27 @@ export default function TrainingForm() {
</div>
) : (
<MainContent>
<SimpleJob
jobConfig={jobConfig}
setJobConfig={setJobConfig}
status={status}
handleSubmit={handleSubmit}
runId={runId}
gpuIDs={gpuIDs}
setGpuIDs={setGpuIDs}
gpuList={gpuList}
datasetOptions={datasetOptions}
/>
<ErrorBoundary fallback={
<div className="flex items-center justify-center h-64 text-lg text-red-600 font-medium bg-red-100 dark:bg-red-900/20 dark:text-red-400 border border-red-300 dark:border-red-700 rounded-lg">
Advanced job detected. Please switch to advanced view to continue.
</div>
}>
<SimpleJob
jobConfig={jobConfig}
setJobConfig={setJobConfig}
status={status}
handleSubmit={handleSubmit}
runId={runId}
gpuIDs={gpuIDs}
setGpuIDs={setGpuIDs}
gpuList={gpuList}
datasetOptions={datasetOptions}
/>
</ErrorBoundary>
<div className="pt-20"></div>
</MainContent>
)}
</>
);
}
}

View File

@@ -0,0 +1,41 @@
// ErrorBoundary.tsx
'use client';
import React, { ReactNode, ErrorInfo, Component } from 'react';
interface ErrorBoundaryProps {
children: ReactNode;
fallback?: ReactNode;
}
interface ErrorBoundaryState {
hasError: boolean;
}
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
constructor(props: ErrorBoundaryProps) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(_: Error): ErrorBoundaryState {
// Update state so the next render will show the fallback UI
return { hasError: true };
}
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
// You can log the error to an error reporting service
console.error("Error caught by ErrorBoundary:", error, errorInfo);
}
render(): ReactNode {
if (this.state.hasError) {
// You can render any custom fallback UI
return this.props.fallback || <div>Something went wrong.</div>;
}
return this.props.children;
}
}
export default ErrorBoundary;