From 6c405d03a5c9db94d1aecc86c48b431d0c06717f Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 6 Sep 2024 12:39:01 -0600 Subject: [PATCH 1/2] fix: use ErrorBoundary to prevent stack traces --- src/components/stages.tsx | 76 +++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/src/components/stages.tsx b/src/components/stages.tsx index 7dc0088..8317472 100644 --- a/src/components/stages.tsx +++ b/src/components/stages.tsx @@ -1,6 +1,7 @@ +import {getLogger} from '@oclif/core/logger' import {capitalCase} from 'change-case' import {Box, Text, useStdout} from 'ink' -import React from 'react' +import React, {ErrorInfo} from 'react' import {RequiredDesign, constructDesignParams} from '../design.js' import {StageStatus, StageTracker} from '../stage-tracker.js' @@ -531,6 +532,37 @@ export function determineCompactionLevel( } } +class ErrorBoundary extends React.Component<{ + children: React.ReactNode + getFallbackText?: () => string +}> { + public state = { + hasError: false, + } + + static getDerivedStateFromError() { + // Update state so the next render will show the fallback UI. + return {hasError: true} + } + + componentDidCatch(error: Error, info: ErrorInfo) { + getLogger('multi-stage-output').debug(error) + getLogger('multi-stage-output').debug(info) + } + + render() { + if (this.state.hasError) { + if (this.props.getFallbackText) { + return {this.props.getFallbackText()} + } + + return false + } + + return this.props.children + } +} + export function Stages({ compactionLevel, design = constructDesignParams(), @@ -629,38 +661,52 @@ export function Stages({ {actualLevelOfCompaction < 3 && title && ( - + title}> + + )} {preStages && preStages.length > 0 && ( - + preStages.map((s) => (s.label ? `${s.label}: ${s.value}` : s.value)).join('\n')} + > + + )} - + stageTracker.current ?? 'unknown'}> + + {postStages && postStages.length > 0 && ( - + postStages.map((s) => (s.label ? `${s.label}: ${s.value}` : s.value)).join('\n')} + > + + )} {hasElapsedTime && ( - Elapsed Time: - + + Elapsed Time: + + )} From 23a0ca2cf470a150b323356deced634e32d52357 Mon Sep 17 00:00:00 2001 From: svc-cli-bot Date: Wed, 11 Sep 2024 20:49:34 +0000 Subject: [PATCH 2/2] chore(release): 0.5.3 [skip ci] --- CHANGELOG.md | 9 +++++++++ package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d5881f..0058baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [0.5.3](https://github.com/oclif/core/compare/0.5.2...0.5.3) (2024-09-11) + + +### Bug Fixes + +* use ErrorBoundary to prevent stack traces ([6c405d0](https://github.com/oclif/core/commit/6c405d03a5c9db94d1aecc86c48b431d0c06717f)) + + + ## [0.5.2](https://github.com/oclif/core/compare/0.5.1...0.5.2) (2024-09-08) diff --git a/package.json b/package.json index 146ff5d..bd23e00 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@oclif/multi-stage-output", "description": "Terminal output for oclif commands with multiple stages", - "version": "0.5.2", + "version": "0.5.3", "author": "Salesforce", "bugs": "https://github.com/oclif/multi-stage-output/issues", "dependencies": {