Skip to content

Commit

Permalink
introducing error boundaries to not crash on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
laszlocph committed Oct 1, 2024
1 parent 998be33 commit 5b389ae
Show file tree
Hide file tree
Showing 12 changed files with 1,958 additions and 6,538 deletions.
8,442 changes: 1,905 additions & 6,537 deletions web/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"jsonpath": "^1.1.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-error-boundary": "^4.0.13",
"redux": "^5.0.1",
"tailwindcss": "^3.4.13",
"web-vitals": "^4.2.3"
Expand Down
4 changes: 4 additions & 0 deletions web/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import FilterBar from "./FilterBar";
import Services from "./Services";
import ToastNotifications from "./ToastNotifications";
import { useState, useEffect, useCallback } from "react";
import { ErrorBoundary } from "react-error-boundary";
import { fallbackRender } from "./FallbackRender"

function App() {
const capacitorClient = new CapacitorClient(
Expand Down Expand Up @@ -52,12 +54,14 @@ function App() {
/>
</div>
<div className="grid grid-cols-1 gap-y-4 pb-32">
<ErrorBoundary fallbackRender={fallbackRender}>
<Services
capacitorClient={capacitorClient}
store={store}
filters={filters}
handleNavigationSelect={handleNavigationSelect}
/>
</ErrorBoundary>
</div>
</div>
<Footer
Expand Down
14 changes: 14 additions & 0 deletions web/src/ExpandedFooter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { TerraformResources } from "./TerraformResources";
import FluxEvents from "./FluxEvents";
import { Sources } from "./Sources";
import { CompactServices } from "./CompactServices";
import { ErrorBoundary } from "react-error-boundary";
import { fallbackRender } from "./FallbackRender"

export function ExpandedFooter(props) {
const {
Expand Down Expand Up @@ -55,49 +57,61 @@ export function ExpandedFooter(props) {
<div className="w-full max-w-7xl mx-auto flex-col h-full">
<div className="pb-24 pt-2">
{selected === "Kustomizations" && (
<ErrorBoundary fallbackRender={fallbackRender}>
<Kustomizations
capacitorClient={client}
fluxState={fluxState}
targetReference={targetReference}
handleNavigationSelect={handleNavigationSelect}
/>
</ErrorBoundary>
)}
{selected === "Helm Releases" && (
<ErrorBoundary fallbackRender={fallbackRender}>
<HelmReleases
capacitorClient={client}
helmReleases={fluxState.helmReleases}
targetReference={targetReference}
handleNavigationSelect={handleNavigationSelect}
/>
</ErrorBoundary>
)}
{selected === "Terraform" && (
<ErrorBoundary fallbackRender={fallbackRender}>
<TerraformResources
capacitorClient={client}
tfResources={fluxState.tfResources}
targetReference={targetReference}
handleNavigationSelect={handleNavigationSelect}
/>
</ErrorBoundary>
)}
{selected === "Sources" && (
<ErrorBoundary fallbackRender={fallbackRender}>
<Sources
capacitorClient={client}
fluxState={fluxState}
targetReference={targetReference}
handleNavigationSelect={handleNavigationSelect}
/>
</ErrorBoundary>
)}
{selected === "Flux Runtime" && (
<ErrorBoundary fallbackRender={fallbackRender}>
<CompactServices
capacitorClient={client}
store={store}
services={fluxState.fluxServices}
/>
</ErrorBoundary>
)}
{selected === "Flux Events" && (
<ErrorBoundary fallbackRender={fallbackRender}>
<FluxEvents
events={fluxEvents}
handleNavigationSelect={handleNavigationSelect}
/>
</ErrorBoundary>
)}
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions web/src/FallbackRender.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function fallbackRender({ error, resetErrorBoundary }) {
return (
<div role="alert">
<p>Something went wrong:</p>
<pre style={{ color: "red" }}>{error.message}</pre>
</div>
);
}
4 changes: 4 additions & 0 deletions web/src/HelmRelease.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState, useRef, useEffect } from 'react';
import { ReadyWidget } from './ReadyWidget'
import { HelmRevisionWidget } from './HelmRevisionWidget';
import { ErrorBoundary } from "react-error-boundary";
import { fallbackRender } from "./FallbackRender"

export function HelmRelease(props) {
const { capacitorClient, item, targetReference, handleNavigationSelect } = props;
Expand Down Expand Up @@ -33,7 +35,9 @@ export function HelmRelease(props) {
<span className="block"><ReadyWidget resource={item} displayMessage={true} label="Reconciled" /></span>
</div>
<div className="col-span-5">
<ErrorBoundary fallbackRender={fallbackRender}>
<div className="font-medium text-neutral-700"><HelmRevisionWidget helmRelease={item} withHistory={true} handleNavigationSelect={handleNavigationSelect} /></div>
</ErrorBoundary>
</div>
<div className="grid grid-cols-1 text-right space-y-1">
<button className="bg-transparent hover:bg-neutral-100 font-medium text-sm text-neutral-700 py-1 px-2 border border-neutral-300 rounded"
Expand Down
4 changes: 4 additions & 0 deletions web/src/Kustomization.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ReadyWidget } from './ReadyWidget'
import jp from 'jsonpath'
import { NavigationButton } from './NavigationButton'
import { findSource } from './utils';
import { ErrorBoundary } from "react-error-boundary";
import { fallbackRender } from "./FallbackRender"

export function Kustomization(props) {
const { capacitorClient, item, fluxState, targetReference, handleNavigationSelect } = props;
Expand Down Expand Up @@ -46,12 +48,14 @@ export function Kustomization(props) {
</div>
<div className="col-span-5">
<div className="font-medium text-neutral-700 field">
<ErrorBoundary fallbackRender={fallbackRender}>
<RevisionWidget
kustomization={item}
source={source}
handleNavigationSelect={handleNavigationSelect}
inFooter={true}
/>
</ErrorBoundary>
</div>
{ source.kind !== 'OCIRepository' &&
<span className='font-mono rounded text-neutral-600 bg-gray-100 px-1'>{item.spec.path}</span>
Expand Down
4 changes: 4 additions & 0 deletions web/src/Service.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Logs } from './Logs'
import { Describe } from './Describe'
import { SkeletonLoader } from './SkeletonLoader'
import { Modal } from './Modal'
import { ErrorBoundary } from "react-error-boundary";
import { fallbackRender } from "./FallbackRender"

const documentIcon = (
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="currentColor" className="w-6 h-6">
Expand Down Expand Up @@ -202,7 +204,9 @@ function Service(props) {
<p className="text-base text-neutral-600">Sync</p>
<div className="flex text-sm text-neutral-600">
<div className="ml-4"><ReadyWidget resource={kustomization} label="Applied" /></div>
<ErrorBoundary fallbackRender={fallbackRender}>
<div className="ml-2 field flex-1"><RevisionWidget kustomization={kustomization} source={source} handleNavigationSelect={handleNavigationSelect} /></div>
</ErrorBoundary>
</div>
</div>
}
Expand Down
4 changes: 4 additions & 0 deletions web/src/Source.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ArtifactWidget } from './ArtifactWidget';
import { OCIArtifactWidget } from './OCIArtifactWidget';
import { HelmChartWidget } from './HelmChartWidget';
import { HelmRepositoryWidget } from './HelmRepositoryWidget';
import { ErrorBoundary } from "react-error-boundary";
import { fallbackRender } from "./FallbackRender"

export function Source(props) {
const { capacitorClient, source, targetReference, handleNavigationSelect } = props;
Expand Down Expand Up @@ -39,6 +41,7 @@ export function Source(props) {
<ReadyWidget resource={source} displayMessage={true} />
</div>
<div className="col-span-5">
<ErrorBoundary fallbackRender={fallbackRender}>
{source.kind === 'GitRepository' &&
<ArtifactWidget gitRepository={source} displayMessage={true} />
}
Expand All @@ -54,6 +57,7 @@ export function Source(props) {
{source.kind === 'HelmChart' &&
<HelmChartWidget source={source} displayMessage={true} handleNavigationSelect={handleNavigationSelect} />
}
</ErrorBoundary>
</div>
<div className="grid grid-cols-1 text-right space-y-1">
<button className="bg-transparent hover:bg-neutral-100 font-medium text-sm text-neutral-700 py-1 px-2 border border-neutral-300 rounded"
Expand Down
6 changes: 6 additions & 0 deletions web/src/TerraformResource.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState, useRef, useEffect } from "react";
import { ReadyWidget } from "./ReadyWidget";
import { TerraformResourceWidget } from "./TerraformResourceWidget";
import { ErrorBoundary } from "react-error-boundary";
import { fallbackRender } from "./FallbackRender"

export function TerraformResource(props) {
const { capacitorClient, item, targetReference, handleNavigationSelect } =
Expand All @@ -24,6 +26,7 @@ export function TerraformResource(props) {
className={`${highlight ? "ring-2 ring-indigo-600 ring-offset-2" : ""} rounded-md border border-neutral-300 p-4 grid grid-cols-12 gap-x-4 bg-white shadow`}
key={`hr-${item.metadata.namespace}/${item.metadata.name}`}
>
<ErrorBoundary fallbackRender={fallbackRender}>
<div className="col-span-2">
<span className="block font-medium text-black">
{item.metadata.name}
Expand All @@ -32,6 +35,7 @@ export function TerraformResource(props) {
{item.metadata.namespace}
</span>
</div>
</ErrorBoundary>
<div className="col-span-4">
<span className="block">
<ReadyWidget
Expand All @@ -43,11 +47,13 @@ export function TerraformResource(props) {
</div>
<div className="col-span-5">
<div className="font-medium text-neutral-700">
<ErrorBoundary fallbackRender={fallbackRender}>
<TerraformResourceWidget
tfRelease={item}
withHistory={true}
handleNavigationSelect={handleNavigationSelect}
/>
</ErrorBoundary>
</div>
</div>
<div className="grid grid-cols-1 text-right space-y-1">
Expand Down
1 change: 0 additions & 1 deletion web/src/TerraformResourceWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export function TerraformResourceWidget(props) {
const reconciling =
reconcilingCondition && reconcilingConditions[0].status === "True";

console.log("TF", tfRelease);
const sourceRef = tfRelease.spec.sourceRef;
const namespace = sourceRef.namespace
? sourceRef.namespace
Expand Down
4 changes: 4 additions & 0 deletions web/src/TerraformResources.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { useMemo, useState } from "react";
import { TerraformResource } from "./TerraformResource";
import { filterResources } from "./utils";
import FilterBar from "./FilterBar";
import { ErrorBoundary } from "react-error-boundary";
import { fallbackRender } from "./FallbackRender"

export function TerraformResources(props) {
const {
Expand Down Expand Up @@ -30,6 +32,7 @@ export function TerraformResources(props) {
filters={filters}
change={setFilters}
/>
<ErrorBoundary fallbackRender={fallbackRender}>
{filteredHelmReleases?.map((resource) => (
<TerraformResource
key={"hr-" + resource.metadata.namespace + resource.metadata.name}
Expand All @@ -39,6 +42,7 @@ export function TerraformResources(props) {
targetReference={targetReference}
/>
))}
</ErrorBoundary>
</div>
);
}

0 comments on commit 5b389ae

Please sign in to comment.