Skip to content

feat: add logger.formatError#10268

Merged
sheremet-va merged 4 commits intovitest-dev:mainfrom
hi-ogawa:expose-logger-format-error
May 5, 2026
Merged

feat: add logger.formatError#10268
sheremet-va merged 4 commits intovitest-dev:mainfrom
hi-ogawa:expose-logger-format-error

Conversation

@hi-ogawa
Copy link
Copy Markdown
Collaborator

@hi-ogawa hi-ogawa commented May 5, 2026

Description

This PR adds ctx.logger.formatError(error, options) as a side-effect-free counterpart to ctx.logger.printError(...). Custom reporters can now reuse Vitest’s existing error formatting while writing the formatted output to their own sinks.

This change also removes the redundant options.task field, which leaked the internal runner task type into error formatting options. It was used for branching browser mode stack formatting but another option options.project is sufficient for the same purpose. Also, as a part of the migration, the built-in GitHub Actions and JUnit reporters now use logger.formatError.


Here are some other ways to expose the same API. I ended up with logger.formatError as it seems most natural place.

  • A top-level formatError(error, ctx, options) export would be simple, but it would introduce a new standalone reporter utility surface and still need ctx for config, stack filtering, source maps, browser parsing, and highlighting.

  • ctx.formatError(error, options) would avoid a top-level export, but error formatting is logger/reporting behavior rather than core Vitest orchestration behavior.

  • static DefaultReporter.formatError(error, ctx, options) would keep the helper near reporter APIs, but formatting is not specific to DefaultReporter, and it would still need ctx.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

hi-ogawa and others added 4 commits May 4, 2026 17:24
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
@netlify
Copy link
Copy Markdown

netlify Bot commented May 5, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 855578f
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69f938a62b45b70008903bea
😎 Deploy Preview https://deploy-preview-10268--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@hi-ogawa hi-ogawa changed the title feat: expose Logger.formatError feat: expose logger.formatError May 5, 2026
@hi-ogawa hi-ogawa changed the title feat: expose logger.formatError feat: add logger.formatError May 5, 2026
@hi-ogawa hi-ogawa marked this pull request as ready for review May 5, 2026 00:53
@sheremet-va sheremet-va merged commit 2c5f3ee into vitest-dev:main May 5, 2026
21 of 23 checks passed
@hi-ogawa hi-ogawa deleted the expose-logger-format-error branch May 5, 2026 09:56
@samchungy
Copy link
Copy Markdown

Wonderful! many thanks @hi-ogawa 🫶

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants