-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Adds better error handling of workspace loading errors
* Adds a status plugin for displaying errors messages if the workspace failed to load. Such errors can get lost in the console log and a blank page is the result in the client. * workspace.ts * If an error occurs then add them to a collection in the workspace * Provides an api for quizzing the workspace on whether it has errored * app-status * Plugin that is only active if * there is a current connection (no point in displaying if nothing has been connected to yet) * there are no mbeans collected from the jolokia connection * Errors were flagged from the workspace * Assuming the plugin is active, offer a component that provides notification of the workspace *
- Loading branch information
1 parent
d12490c
commit e5474fb
Showing
8 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.workspace-alert { | ||
margin-top: 1em; | ||
} |
76 changes: 76 additions & 0 deletions
76
packages/hawtio/src/plugins/app-status/WorkspaceStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, { useEffect, useRef, useState } from 'react' | ||
import { | ||
Alert, | ||
Card, | ||
CardBody, | ||
PageSection, | ||
PageSectionVariants, | ||
Panel, | ||
PanelHeader, | ||
PanelMain, | ||
PanelMainBody, | ||
} from '@patternfly/react-core' | ||
import { HawtioLoadingCard, workspace } from '@hawtiosrc/plugins/shared' | ||
import './WorkspaceStatus.css' | ||
|
||
export const WorkspaceStatus: React.FunctionComponent = () => { | ||
const timerRef = useRef<NodeJS.Timeout | null>(null) | ||
const [errors, setErrors] = useState<Error[]>([]) | ||
const [loading, setLoading] = useState<boolean>(true) | ||
|
||
useEffect(() => { | ||
const waitLoading = async () => { | ||
const hasErrors = await workspace.hasErrors() | ||
|
||
if (hasErrors) { | ||
const errors = [...(await workspace.getErrors())] | ||
errors.reverse() // reverse so as to show latest first | ||
setErrors(errors) | ||
} | ||
|
||
setLoading(false) | ||
} | ||
|
||
timerRef.current = setTimeout(waitLoading, 1000) | ||
|
||
return () => { | ||
if (timerRef.current) clearTimeout(timerRef.current) | ||
} | ||
}, []) | ||
|
||
if (loading) { | ||
return ( | ||
<PageSection variant={PageSectionVariants.light}> | ||
<Panel> | ||
<PanelHeader>Waiting workspace to load ...</PanelHeader> | ||
<PanelMain> | ||
<PanelMainBody> | ||
<HawtioLoadingCard /> | ||
</PanelMainBody> | ||
</PanelMain> | ||
</Panel> | ||
</PageSection> | ||
) | ||
} | ||
|
||
const hasCause = (error: Error) => { | ||
if (!error || !error.cause) return false | ||
return error.cause instanceof Error | ||
} | ||
|
||
return ( | ||
<PageSection variant={PageSectionVariants.light}> | ||
<Card> | ||
<CardBody> | ||
<Alert variant='warning' title='Application returned no mbeans' /> | ||
|
||
{errors.map(error => ( | ||
<Alert variant='danger' title={error.message} className='workspace-alert'> | ||
{hasCause(error) && <p>Cause: {(error.cause as Error).message}</p>} | ||
</Alert> | ||
))} | ||
</CardBody> | ||
</Card> | ||
</PageSection> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Logger } from '@hawtiosrc/core/logging' | ||
|
||
export const pluginId = 'appstatus' | ||
export const pluginName = 'Application Status' | ||
export const pluginPath = '/appstatus' | ||
export const log = Logger.get(pluginName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { HawtioPlugin, hawtio } from '@hawtiosrc/core' | ||
import { connectService, workspace } from '@hawtiosrc/plugins/shared' | ||
import { WorkspaceStatus } from './WorkspaceStatus' | ||
import { pluginId, pluginPath, pluginName } from './globals' | ||
|
||
/* | ||
* Target application status plugin | ||
* only active if the workspace contains no mbeans, ie, totally empty. | ||
* and / or the workspace has produced errors. | ||
* Will communicate this to the user with a notice component. | ||
*/ | ||
export const appStatus: HawtioPlugin = () => { | ||
hawtio.addPlugin({ | ||
id: pluginId, | ||
title: pluginName, | ||
path: pluginPath, | ||
component: WorkspaceStatus, | ||
isActive: async () => { | ||
const connection = await connectService.getCurrentConnection() | ||
const beans = await workspace.hasMBeans() | ||
const errors = await workspace.hasErrors() | ||
|
||
if (!connection) return false // no connection yet so no beans in workspace | ||
|
||
return !beans || errors // either no beans or workspace has errors | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters