Skip to content

Commit

Permalink
feat: add error handling for workflowTemplateRef api call and support…
Browse files Browse the repository at this point in the history
… clusteWorkflowTemplate references

Signed-off-by: Unperceivable <[email protected]>
  • Loading branch information
Unperceivable committed Jan 1, 2025
1 parent 31ad09b commit 180a142
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions ui/src/shared/components/editors/graph-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {Icon} from '../icon';
export function GraphViewer({workflowDefinition}: {workflowDefinition: Workflow | WorkflowTemplate | ClusterWorkflowTemplate | CronWorkflow}) {
const [workflow, setWorkflow] = useState<Workflow | WorkflowTemplate | ClusterWorkflowTemplate>(workflowDefinition);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<Error>();
const [state, saveOptions] = useState<WorkflowDagRenderOptions>({
expandNodes: new Set(),
showArtifacts: false,
Expand All @@ -32,7 +33,12 @@ export function GraphViewer({workflowDefinition}: {workflowDefinition: Workflow
useEffect(() => {
if ('workflowTemplateRef' in workflowDefinition.spec && isLoading) {
setWorkflowFromRefrence(workflowDefinition.spec.workflowTemplateRef.name).then(() => {
setError(null);
setIsLoading(false);
}).catch(err => {
const explicitError = new Error(`${err.message}, no workflowTemplateRef "${workflowDefinition.spec.workflowTemplateRef.name}" found in workflowTemplates or clusterWorkflowTemplates`);
explicitError.stack = err.stack;
setError(explicitError);
});
} else if ('workflowSpec' in workflowDefinition.spec && isLoading) {
const convertedCronWorkflow = convertFromCronWorkflow(workflowDefinition as CronWorkflow);
Expand All @@ -44,7 +50,8 @@ export function GraphViewer({workflowDefinition}: {workflowDefinition: Workflow
}, [workflow]);

if (isLoading) {
return <div>Loading...</div>;
const currentState = error ? `${error.name}: ${error.message}` : 'Loading...';
return <div>{currentState}</div>;
}

const name = workflow.metadata.name ? `${workflow.metadata.name}-${generateNamePostfix(5)}` : `${workflow.metadata.generateName}${generateNamePostfix(5)}`;
Expand All @@ -69,9 +76,22 @@ export function GraphViewer({workflowDefinition}: {workflowDefinition: Workflow
);

function setWorkflowFromRefrence(name: string): Promise<void> {
return services.workflowTemplate.get(name, workflowDefinition.metadata.namespace).then(workflowTemplate => {
setWorkflow(workflowTemplate);
});
try {
return services.workflowTemplate.get(name, workflowDefinition.metadata.namespace).then(workflowTemplate => {
setWorkflow(workflowTemplate);
}).catch(() => {
return services.clusterWorkflowTemplate

Check failure on line 83 in ui/src/shared/components/editors/graph-viewer.tsx

View workflow job for this annotation

GitHub Actions / UI

Unnecessary try/catch wrapper
.get(name)
.then(clusterWorkflowTemplate => {
setWorkflow(clusterWorkflowTemplate);
})
.catch(err => {
throw err;
});
});
} catch (err) {
throw err;
}
}

function convertFromCronWorkflow(cronWorkflow: CronWorkflow): Workflow {
Expand Down

0 comments on commit 180a142

Please sign in to comment.