Skip to content

Commit

Permalink
fix: improve error handler (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
northword authored Feb 11, 2025
1 parent 581dda8 commit 7d0dd5d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { VersionBumpProgress } from '../types/version-bump-progress'
import process from 'node:process'
import { x } from 'tinyexec'
import { NonZeroExitError, x } from 'tinyexec'
import { ProgressEvent } from '../types/version-bump-progress'
import { versionBump } from '../version-bump'
import { ExitCode } from './exit-code'
Expand Down Expand Up @@ -74,11 +74,14 @@ function progress({ event, script, updatedFiles, skippedFiles, newVersion }: Ver
}
}

function errorHandler(error: Error): void {
function errorHandler(error: Error | NonZeroExitError): void {
let message = error.message || String(error)

if (error instanceof NonZeroExitError)
message += `\n\n${error.output?.stderr || ''}`

if (process.env.DEBUG || process.env.NODE_ENV === 'development')
message = error.stack || message
message += `\n\n${error.stack || ''}`

console.error(message)
process.exit(ExitCode.FatalError)
Expand Down

0 comments on commit 7d0dd5d

Please # to comment.