Skip to content

Commit

Permalink
Replace usage of VError with Error.cause (#2363)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgoss authored Dec 21, 2023
1 parent 2a95e47 commit 96a65ca
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 56 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Please see [CONTRIBUTING.md](./CONTRIBUTING.md) on how to contribute to Cucumber
### Fixed
- Prevent mutations on world parameters leaking between test cases ([#2362](https://github.com/cucumber/cucumber-js/pull/2362))

### Changed
- Replace usage of `VError` with `Error.cause` ([#2363](https://github.com/cucumber/cucumber-js/pull/2363))

## [10.0.1] - 2023-10-20
### Fixed
- Honour order of paths in configuration ([#2345](https://github.com/cucumber/cucumber-js/pull/2345))
Expand Down
8 changes: 5 additions & 3 deletions features/support/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { PassThrough, pipeline, Writable } from 'node:stream'
import fs from 'node:fs'
import path from 'node:path'
import util from 'node:util'
import { Console } from 'node:console'
import { expect } from 'chai'
import toString from 'stream-to-string'
import stripAnsi from 'strip-ansi'
import VError from 'verror'
import * as messages from '@cucumber/messages'
import * as messageStreams from '@cucumber/message-streams'
import FakeReportServer from '../../test/fake_report_server'
Expand Down Expand Up @@ -106,13 +106,15 @@ export class World {
} catch (err) {
error = err
}
if (error) {
new Console(stderr).error(error)
}
stdout.end()
stderr.end()
const stderrSuffix = error != null ? VError.fullStack(error) : ''
result = {
error,
stdout: await toString(stdout),
stderr: (await toString(stderr)) + stderrSuffix,
stderr: await toString(stderr),
}
}
const envelopes: messages.Envelope[] = []
Expand Down
42 changes: 0 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@
"tmp": "^0.2.1",
"type-fest": "^4.8.3",
"util-arity": "^1.1.0",
"verror": "^1.10.0",
"xmlbuilder": "^15.1.1",
"yaml": "^2.2.2",
"yup": "1.2.0"
Expand Down Expand Up @@ -277,7 +276,6 @@
"@types/sinonjs__fake-timers": "8.1.2",
"@types/stream-buffers": "3.0.4",
"@types/tmp": "0.2.3",
"@types/verror": "1.10.6",
"@typescript-eslint/eslint-plugin": "6.7.4",
"@typescript-eslint/parser": "6.7.4",
"chai": "4.3.7",
Expand Down
3 changes: 1 addition & 2 deletions src/cli/run.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-console */
/* This is one rare place where we're fine to use process/console directly,
* but other code abstracts those to remain composable and testable. */
import VError from 'verror'
import { validateNodeEngineVersion } from './validate_node_engine_version'
import Cli, { ICliRunResult } from './'

Expand Down Expand Up @@ -32,7 +31,7 @@ export default async function run(): Promise<void> {
try {
result = await cli.run()
} catch (error) {
logErrorMessageAndExit(VError.fullStack(error))
logErrorMessageAndExit(error)
}

const exitCode = result.success ? 0 : 1
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/parallel/run_worker.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import VError from 'verror'
import { doesHaveValue } from '../../value_checker'
import Worker from './worker'

function run(): void {
const exit = (exitCode: number, error?: Error, message?: string): void => {
if (doesHaveValue(error)) {
console.error(VError.fullStack(new VError(error, message))) // eslint-disable-line no-console
console.error(new Error(message, { cause: error })) // eslint-disable-line no-console
}
process.exit(exitCode)
}
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/run_test_run_hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import VError from 'verror'
import UserCodeRunner from '../user_code_runner'
import { formatLocation } from '../formatter/helpers'
import { doesHaveValue, valueOrDefault } from '../value_checker'
Expand Down Expand Up @@ -29,7 +28,7 @@ export const makeRunTestRunHooks = (
})
if (doesHaveValue(error)) {
const location = formatLocation(hookDefinition)
throw new VError(error, errorMessage(name, location))
throw new Error(errorMessage(name, location), { cause: error })
}
}
}
5 changes: 2 additions & 3 deletions src/try_require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ export default function tryRequire(path: string) {
if (error.code === 'ERR_REQUIRE_ESM') {
throw Error(
`Cucumber expected a CommonJS module at '${path}' but found an ES module.
Either change the file to CommonJS syntax or use the --import directive instead of --require.
Original error message: ${error.message}`
Either change the file to CommonJS syntax or use the --import directive instead of --require.`,
{ cause: error }
)
} else {
throw error
Expand Down

0 comments on commit 96a65ca

Please sign in to comment.