Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds error reporting #277

Merged
merged 5 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/components/error-boundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Alert, AlertTitle, Stack, Typography } from '@mui/material';

import React from 'react';

interface IErrorBoundaryProps {
alertTitle: string;
alertMessage: string;
detailTitle: string;
}

interface IErrorBoundaryState {
hasError: boolean;
error?: unknown;
}

export class ErrorBoundary extends React.Component<
React.PropsWithChildren<IErrorBoundaryProps>,
IErrorBoundaryState
> {
constructor(props: IErrorBoundaryProps) {
super(props);
this.state = { hasError: false };
}

static getDerivedStateFromError(error: unknown): IErrorBoundaryState {
// Update state so the next render will show the fallback UI.
return { hasError: true, error: error };
}
JasonWeill marked this conversation as resolved.
Show resolved Hide resolved

componentDidCatch(error: unknown, errorInfo: React.ErrorInfo): void {
// You can also log the error to an error reporting service
// errorInfo has full stack trace, which we are not using
this.setState({ hasError: true, error });
}

render(): React.ReactNode {
let errorDetail;
if (typeof this.state.error === 'string') {
errorDetail = this.state.error;
} else if (this.state.error instanceof Error) {
errorDetail = this.state.error.message;
}
JasonWeill marked this conversation as resolved.
Show resolved Hide resolved

let infoSection;
if (errorDetail !== undefined) {
infoSection = (
<>
<Typography variant="h1">{this.props.detailTitle}</Typography>
<pre>{errorDetail}</pre>
</>
);
}
if (this.state.hasError) {
return (
<div className="jp-error-boundary">
<Stack spacing={4}>
<Alert severity="error">
<AlertTitle>{this.props.alertTitle}</AlertTitle>
{this.props.alertMessage}
</Alert>
{infoSection}
JasonWeill marked this conversation as resolved.
Show resolved Hide resolved
</Stack>
</div>
);
}
return this.props.children;
}
}
143 changes: 80 additions & 63 deletions src/notebook-jobs-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import { VDomRenderer } from '@jupyterlab/apputils';
import { ITranslator } from '@jupyterlab/translation';
import { LabIcon } from '@jupyterlab/ui-components';

import { ErrorBoundary } from './components/error-boundary';
import { calendarMonthIcon } from './components/icons';
import TranslatorContext from './context';

import { CreateJob } from './mainviews/create-job';
import { DetailView } from './mainviews/detail-view';
import { CreateJobFromDefinition } from './mainviews/create-job-from-definition';
import { EditJobDefinition } from './mainviews/edit-job-definition';
import { NotebookJobsList } from './mainviews/list-jobs';

import TranslatorContext from './context';
import {
defaultScheduleFields,
ICreateJobModel,
Expand All @@ -20,9 +26,6 @@ import {
} from './model';
import { getJupyterLabTheme } from './theme-provider';
import { Scheduler } from './tokens';
import { DetailView } from './mainviews/detail-view';
import { CreateJobFromDefinition } from './mainviews/create-job-from-definition';
import { EditJobDefinition } from './mainviews/edit-job-definition';

export class NotebookJobsPanel extends VDomRenderer<JobsModel> {
readonly _title?: string;
Expand Down Expand Up @@ -90,68 +93,82 @@ export class NotebookJobsPanel extends VDomRenderer<JobsModel> {
this.model.jobsView = JobsView.CreateForm;
};

const trans = this._translator.load('jupyterlab');

JasonWeill marked this conversation as resolved.
Show resolved Hide resolved
return (
<ThemeProvider theme={getJupyterLabTheme()}>
<TranslatorContext.Provider value={this._translator}>
{this.model.jobsView === JobsView.CreateForm && (
<CreateJob
key={this.model.createJobModel.key}
model={this.model.createJobModel}
handleModelChange={newModel =>
(this.model.createJobModel = newModel)
}
showListView={this.showListView.bind(this)}
advancedOptions={this._advancedOptions}
/>
)}
{this.model.jobsView === JobsView.CreateFromJobDescriptionForm && (
<CreateJobFromDefinition
key={this.model.createJobModel.key}
model={this.model.createJobModel}
handleModelChange={newModel =>
(this.model.createJobModel = newModel)
}
showListView={this.showListView.bind(this)}
advancedOptions={this._advancedOptions}
/>
)}
{(this.model.jobsView === JobsView.ListJobs ||
this.model.jobsView === JobsView.ListJobDefinitions) && (
<NotebookJobsList
app={this._app}
listView={this.model.jobsView}
showListView={this.showListView.bind(this)}
showCreateJob={showCreateJob}
showJobDetail={this.showDetailView.bind(this)}
showJobDefinitionDetail={this.showJobDefinitionDetail.bind(this)}
/>
)}
{(this.model.jobsView === JobsView.JobDetail ||
this.model.jobsView === JobsView.JobDefinitionDetail) && (
<DetailView
app={this._app}
model={this.model.jobDetailModel}
setCreateJobModel={newModel =>
(this.model.createJobModel = newModel)
}
jobsView={this.model.jobsView}
setJobsView={view => (this.model.jobsView = view)}
showCreateJob={showCreateJob}
showJobDetail={this.showDetailView.bind(this)}
editJobDefinition={this.editJobDefinition.bind(this)}
advancedOptions={this._advancedOptions}
/>
)}
{this.model.jobsView === JobsView.EditJobDefinition && (
<EditJobDefinition
model={this.model.updateJobDefinitionModel}
handleModelChange={newModel =>
(this.model.updateJobDefinitionModel = newModel)
}
showListView={this.showListView.bind(this)}
showJobDefinitionDetail={this.showJobDefinitionDetail.bind(this)}
/>
)}
<ErrorBoundary
alertTitle={trans.__('Internal error')}
alertMessage={trans.__(
'We encountered an internal error. Please try your command again.'
)}
detailTitle={trans.__('Error details')}
>
{this.model.jobsView === JobsView.CreateForm && (
<CreateJob
key={this.model.createJobModel.key}
model={this.model.createJobModel}
handleModelChange={newModel =>
(this.model.createJobModel = newModel)
}
showListView={this.showListView.bind(this)}
advancedOptions={this._advancedOptions}
/>
)}
{this.model.jobsView === JobsView.CreateFromJobDescriptionForm && (
<CreateJobFromDefinition
key={this.model.createJobModel.key}
model={this.model.createJobModel}
handleModelChange={newModel =>
(this.model.createJobModel = newModel)
}
showListView={this.showListView.bind(this)}
advancedOptions={this._advancedOptions}
/>
)}
{(this.model.jobsView === JobsView.ListJobs ||
this.model.jobsView === JobsView.ListJobDefinitions) && (
<NotebookJobsList
app={this._app}
listView={this.model.jobsView}
showListView={this.showListView.bind(this)}
showCreateJob={showCreateJob}
showJobDetail={this.showDetailView.bind(this)}
showJobDefinitionDetail={this.showJobDefinitionDetail.bind(
this
)}
/>
)}
{(this.model.jobsView === JobsView.JobDetail ||
this.model.jobsView === JobsView.JobDefinitionDetail) && (
<DetailView
app={this._app}
model={this.model.jobDetailModel}
setCreateJobModel={newModel =>
(this.model.createJobModel = newModel)
}
jobsView={this.model.jobsView}
setJobsView={view => (this.model.jobsView = view)}
showCreateJob={showCreateJob}
showJobDetail={this.showDetailView.bind(this)}
editJobDefinition={this.editJobDefinition.bind(this)}
advancedOptions={this._advancedOptions}
/>
)}
{this.model.jobsView === JobsView.EditJobDefinition && (
<EditJobDefinition
model={this.model.updateJobDefinitionModel}
handleModelChange={newModel =>
(this.model.updateJobDefinitionModel = newModel)
}
showListView={this.showListView.bind(this)}
showJobDefinitionDetail={this.showJobDefinitionDetail.bind(
this
)}
/>
)}
</ErrorBoundary>
</TranslatorContext.Provider>
</ThemeProvider>
);
Expand Down
11 changes: 11 additions & 0 deletions style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
margin-top: 12px;
}

/* Error reporting */
.jp-error-boundary {
max-width: 500px;
margin: 12px;
}

.jp-error-boundary h1 {
font-size: 1.25rem;
font-weight: bold;
}

/* Create job form */

.jp-create-job-form {
Expand Down