Skip to content

Commit

Permalink
Instruct users with JsonFormatter errors to attach messages
Browse files Browse the repository at this point in the history
Additionally, for users that haven't enabled messages, one is generated
anyway in the users temporary location. This will hopefully shed some
light onto a previously reported and hard-to-reproduce issue [1].

I would ideally have liked to use error cause for this, but Cypress will
swallow this [2].

[1] #1161
[2] cypress-io/cypress#30265
  • Loading branch information
badeball committed Sep 22, 2024
1 parent 65fdbc3 commit 73637e6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Other changees:

- Re-introduce support for Node v18, fixes [#1230](https://github.com/badeball/cypress-cucumber-preprocessor/discussions/1230).

- Generate a temporary messages report in case of `JsonFormatter` errors, relates to [#1161](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1161).

## v20.1.2

- Updated all dependencies, including esbuild, relates to [#1068](https://github.com/badeball/cypress-cucumber-preprocessor/issues/1068).
Expand Down
31 changes: 29 additions & 2 deletions lib/plugin-event-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,35 @@ export async function afterRunHandler(config: Cypress.PluginConfigOptions) {
},
);

for (const message of state.messages.accumulation) {
eventBroadcaster.emit("envelope", message);
try {
for (const message of state.messages.accumulation) {
eventBroadcaster.emit("envelope", message);
}
} catch (e) {
const message = (messagesOutput: string) =>
`JsonFormatter failed with an error shown below. This might be a bug, please report at ${homepage} and make sure to attach the messages report in your ticket (${messagesOutput}).\n`;

if (preprocessor.messages.enabled) {
console.warn(chalk.yellow(message(preprocessor.messages.output)));
} else {
const temporaryMessagesOutput = path.join(
await fs.mkdtemp(
path.join(os.tmpdir(), "cypress-cucumber-preprocessor-"),
),
"cucumber-messages.ndjson",
);

await fs.writeFile(
temporaryMessagesOutput,
state.messages.accumulation
.map((message) => JSON.stringify(message))
.join("\n") + "\n",
);

console.warn(chalk.yellow(message(temporaryMessagesOutput)));
}

throw e;
}

assertIsString(
Expand Down

0 comments on commit 73637e6

Please sign in to comment.