Skip to content

Commit

Permalink
Add alert if failed, make lastError an error only (instead of message…
Browse files Browse the repository at this point in the history
… + error)

Signed-off-by: David Kwon <[email protected]>
  • Loading branch information
dkwon17 committed Aug 17, 2022
1 parent 53fc942 commit 7aecab3
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 51 deletions.
14 changes: 3 additions & 11 deletions packages/dashboard-frontend/src/containers/Loader/AbstractStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* Red Hat, Inc. - initial API and implementation
*/

import common from '@eclipse-che/common';
import React from 'react';
import { Cancellation, pseudoCancellable } from 'real-cancellable-promise';
import { List, LoaderStep } from '../../components/Loader/Step';
Expand All @@ -24,12 +23,9 @@ export type LoaderStepProps = {
onRestart: () => void;
};
export type LoaderStepState = {
lastError?: LoaderStepError;
};
export type LoaderStepError = {
message: string;
error: unknown;
lastError?: unknown;
};

export abstract class AbstractLoaderStep<
P extends LoaderStepProps,
S extends LoaderStepState,
Expand Down Expand Up @@ -65,12 +61,8 @@ export abstract class AbstractLoaderStep<
const currentStep = loaderSteps.get(currentStepIndex).value;

currentStep.hasError = true;
const lastError = {
message: common.helpers.errors.getMessage(e),
error: e,
};
this.setState({
lastError,
lastError: e,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import * as WorkspacesStore from '../../../../../store/Workspaces';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
Expand Down Expand Up @@ -84,7 +86,7 @@ class StepApplyDevfile extends AbstractLoaderStep<Props, State> {
}

// current step failed
if (this.state.lastError?.message !== nextState.lastError?.message) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}

Expand Down Expand Up @@ -142,9 +144,10 @@ class StepApplyDevfile extends AbstractLoaderStep<Props, State> {
}

if (shouldCreate === false) {
throw new Error(
this.state.lastError?.message || 'The workspace creation unexpectedly failed.',
);
if (this.state.lastError instanceof Error) {
throw this.state.lastError;
}
throw new Error('The workspace creation unexpectedly failed.');
}

const devfile = factoryResolverConverted?.devfileV2;
Expand Down Expand Up @@ -213,7 +216,7 @@ class StepApplyDevfile extends AbstractLoaderStep<Props, State> {
key: 'factory-loader-' + getRandomString(4),
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError.message,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import * as FactoryResolverStore from '../../../../../store/FactoryResolver';
import * as WorkspacesStore from '../../../../../store/Workspaces';
Expand Down Expand Up @@ -91,7 +93,7 @@ class StepApplyResources extends AbstractLoaderStep<Props, State> {
}

// current step failed
if (this.state.lastError?.message !== nextState.lastError?.message) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}

Expand Down Expand Up @@ -149,9 +151,10 @@ class StepApplyResources extends AbstractLoaderStep<Props, State> {
}

if (shouldCreate === false) {
throw new Error(
this.state.lastError?.message || 'The workspace creation unexpectedly failed.',
);
if (this.state.lastError instanceof Error) {
throw this.state.lastError;
}
throw new Error('The workspace creation unexpectedly failed.');
}

const resources = devWorkspaceResources[sourceUrl]?.resources;
Expand Down Expand Up @@ -212,7 +215,7 @@ class StepApplyResources extends AbstractLoaderStep<Props, State> {
key: 'factory-loader-' + getRandomString(4),
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError.message,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import React from 'react';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
import { delay } from '../../../../../services/helpers/delay';
import { FactoryLoaderPage } from '../../../../../pages/Loader/Factory';
Expand Down Expand Up @@ -71,7 +72,7 @@ export default class StepCreateWorkspace extends AbstractLoaderStep<Props, State
key: 'factory-loader-' + getRandomString(4),
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError.message,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import common from '@eclipse-che/common';
import { isEqual } from 'lodash';
import { helpers } from '@eclipse-che/common';
import { AlertVariant } from '@patternfly/react-core';
import { AppState } from '../../../../../store';
import * as FactoryResolverStore from '../../../../../store/FactoryResolver';
Expand Down Expand Up @@ -96,7 +97,7 @@ class StepFetchDevfile extends AbstractLoaderStep<Props, State> {
}

// current step failed
if (this.state.lastError?.message !== nextState.lastError?.message) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}

Expand Down Expand Up @@ -170,7 +171,10 @@ class StepFetchDevfile extends AbstractLoaderStep<Props, State> {
}

if (shouldResolve === false) {
throw new Error(this.state.lastError?.message || 'Failed to resolve the devfile.');
if (this.state.lastError instanceof Error) {
throw this.state.lastError;
}
throw new Error('Failed to resolve the devfile.');
}

// start resolving the devfile
Expand Down Expand Up @@ -243,7 +247,7 @@ class StepFetchDevfile extends AbstractLoaderStep<Props, State> {
oauthUrlTmp.toString() + '&redirect_after_login=' + redirectUrl.toString();
window.location.href = fullOauthUrl;
} catch (e) {
throw new Error(`Failed to open authentication page. ${common.helpers.errors.getMessage(e)}`);
throw new Error(`Failed to open authentication page. ${helpers.errors.getMessage(e)}`);
}
}

Expand Down Expand Up @@ -314,7 +318,7 @@ class StepFetchDevfile extends AbstractLoaderStep<Props, State> {
key: 'factory-loader-fetch-devfile',
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError.message,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import * as DevfileRegistriesStore from '../../../../../store/DevfileRegistries';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
Expand Down Expand Up @@ -84,7 +86,7 @@ class StepFetchResources extends AbstractLoaderStep<Props, State> {
}

// current step failed
if (this.state.lastError?.message !== nextState.lastError?.message) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}

Expand Down Expand Up @@ -146,7 +148,10 @@ class StepFetchResources extends AbstractLoaderStep<Props, State> {
}

if (shouldResolve === false) {
throw new Error(lastError?.message || 'Failed to fetch pre-built resources');
if (lastError instanceof Error) {
throw lastError;
}
throw new Error('Failed to fetch pre-built resources');
}

await this.props.requestResources(sourceUrl);
Expand Down Expand Up @@ -186,7 +191,7 @@ class StepFetchResources extends AbstractLoaderStep<Props, State> {
key: 'factory-loader-fetch-resources',
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError.message,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { generatePath } from 'react-router-dom';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import { selectInfrastructureNamespaces } from '../../../../../store/InfrastructureNamespaces/selectors';
import { DisposableCollection } from '../../../../../services/helpers/disposable';
Expand Down Expand Up @@ -60,7 +62,7 @@ class StepInitialize extends AbstractLoaderStep<Props, State> {
}

// current step failed
if (this.state.lastError?.message !== nextState.lastError?.message) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}

Expand Down Expand Up @@ -136,7 +138,7 @@ class StepInitialize extends AbstractLoaderStep<Props, State> {
key: 'factory-loader-initialize',
title: 'Failed to create the workspace',
variant: AlertVariant.danger,
children: lastError.message,
children: helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import { helpers } from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import { selectAllWorkspaces } from '../../../../../store/Workspaces/selectors';
import * as WorkspaceStore from '../../../../../store/Workspaces';
Expand Down Expand Up @@ -69,7 +71,7 @@ class StepInitialize extends AbstractLoaderStep<Props, State> {
return true;
}
// set the error for the current step
if (this.state.lastError?.message !== nextState.lastError?.message) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}
return false;
Expand Down Expand Up @@ -161,8 +163,8 @@ class StepInitialize extends AbstractLoaderStep<Props, State> {
key: 'ide-loader-initialize',
title: 'Failed to open the workspace',
variant: AlertVariant.danger,
children: lastError.message,
error: lastError.error,
children: helpers.errors.getMessage(lastError),
error: lastError,
};
return (
<WorkspaceLoaderPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { isEqual } from 'lodash';
import { AlertVariant } from '@patternfly/react-core';
import common from '@eclipse-che/common';
import { AppState } from '../../../../../store';
import { selectAllWorkspaces } from '../../../../../store/Workspaces/selectors';
import * as WorkspaceStore from '../../../../../store/Workspaces';
Expand Down Expand Up @@ -69,7 +71,7 @@ class StepOpenWorkspace extends AbstractLoaderStep<Props, State> {
return true;
}
// set the error for the current step
if (this.state.lastError?.message !== nextState.lastError?.message) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}
return false;
Expand Down Expand Up @@ -147,7 +149,7 @@ class StepOpenWorkspace extends AbstractLoaderStep<Props, State> {
key: 'ide-loader-open-ide',
title: 'Failed to open the workspace',
variant: AlertVariant.danger,
children: lastError.message,
children: common.helpers.errors.getMessage(lastError),
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { AlertVariant } from '@patternfly/react-core';
import common from '@eclipse-che/common';
import { isEqual } from 'lodash';
import { AppState } from '../../../../../store';
import { selectAllWorkspaces, selectLogs } from '../../../../../store/Workspaces/selectors';
import * as WorkspaceStore from '../../../../../store/Workspaces';
Expand Down Expand Up @@ -77,7 +78,7 @@ class StepStartWorkspace extends AbstractLoaderStep<Props, State> {
return true;
}
// set the error for the current step
if (this.state.lastError?.message !== nextState.lastError?.message) {
if (!isEqual(this.state.lastError, nextState.lastError)) {
return true;
}
return false;
Expand Down Expand Up @@ -171,14 +172,10 @@ class StepStartWorkspace extends AbstractLoaderStep<Props, State> {
// do not switch to the next step
return false;
} catch (e) {
const message = common.helpers.errors.getMessage(e);

if (common.helpers.errors.isError(e)) {
// throw original error
e.message = message;
throw e;
}
throw new Error(message);
throw new Error(common.helpers.errors.getMessage(e));
}
}

Expand All @@ -205,8 +202,8 @@ class StepStartWorkspace extends AbstractLoaderStep<Props, State> {
key: 'ide-loader-start-workspace',
title: 'Failed to open the workspace',
variant: AlertVariant.danger,
children: lastError.message,
error: lastError.error,
children: common.helpers.errors.getMessage(lastError),
error: lastError,
};

return (
Expand Down
Loading

0 comments on commit 7aecab3

Please sign in to comment.