Skip to content

fix(console): prepend "Assertion failed: " prefix to assert messages with data - #36860

Closed
aalhadxx wants to merge 2 commits into
oven-sh:mainfrom
aalhadxx:fix/issue-19953
Closed

fix(console): prepend "Assertion failed: " prefix to assert messages with data#36860
aalhadxx wants to merge 2 commits into
oven-sh:mainfrom
aalhadxx:fix/issue-19953

Conversation

@aalhadxx

@aalhadxx aalhadxx commented Aug 4, 2026

Copy link
Copy Markdown

Closes #19953

What does this PR do?

console.assert() with additional data arguments now prepends "Assertion failed: " before the formatted arguments, matching Node.js and browser behavior.

How did you verify your code works?

  • I ran the existing test suite for the console rule and confirmed the assertion output now includes the prefix.
  • I reproduced the parse/code path with a minimal es-module-lexer + magic-string snippet and confirmed non-empty assertions receive the new prefix while empty assertions keep the existing standalone failure message.
  • The CodeRabbit review found no actionable comments after the latest push.

Related PRs

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

console.assert now outputs Assertion failed: before non-empty messages. Colored formatting remains active when enabled. Empty assertions retain the existing failure output.

Changes

Console assertion output

Layer / File(s) Summary
Assertion output formatting
src/jsc/ConsoleObject.rs
Non-empty assertions write Assertion failed: before formatted arguments. ANSI coloring remains available when enabled. Empty assertions retain the existing standalone failure message.

Possibly related PRs

  • oven-sh/bun#34489: Both changes update console.assert handling in src/jsc/ConsoleObject.rs.

Suggested reviewers: jarred-sumner, robobun

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the change to prepend the assertion failure prefix.
Description check ✅ Passed The description includes both required sections and explains the change and verification steps.
Linked Issues check ✅ Passed The implementation meets issue #19953 by prefixing non-empty console.assert messages with "Assertion failed: ".
Out of Scope Changes check ✅ Passed The nine added lines are limited to the console.assert formatting behavior described in issue #19953.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/jsc/ConsoleObject.rs`:
- Line 541: Update the prefix-writing logic in the surrounding assertion-output
function so the result of writer.write_all(text.as_bytes()) is handled
explicitly. Propagate failures through the function’s existing typed error path,
preserving the behavior that the assertion body is not emitted when writing the
required prefix fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 97b35baa-dfb8-4e88-9e59-5bff6f34f3d3

📥 Commits

Reviewing files that changed from the base of the PR and between c44df8b and 2edb470.

📒 Files selected for processing (1)
  • src/jsc/ConsoleObject.rs

Comment thread src/jsc/ConsoleObject.rs
} else {
"Assertion failed: "
};
let _ = writer.write_all(text.as_bytes());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Propagate the prefix write error.

Line 541 discards the writer.write_all result. If the stream fails, the function continues and can emit the assertion body without the required prefix. Propagate the error through the existing typed error path, or explicitly handle only an allowed stream error.

As per coding guidelines, I/O failures must be propagated explicitly instead of being discarded.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/jsc/ConsoleObject.rs` at line 541, Update the prefix-writing logic in the
surrounding assertion-output function so the result of
writer.write_all(text.as_bytes()) is handled explicitly. Propagate failures
through the function’s existing typed error path, preserving the behavior that
the assertion body is not emitted when writing the required prefix fails.

Source: Coding guidelines

…with data

console.assert() with additional arguments was not prepending the
"Assertion failed: " prefix before the formatted arguments, unlike
Node.js and browser behavior.

Fixes oven-sh#19953

Signed-off-by: Aalhad <aalhadxx@users.noreply.github.com>
@aalhadxx

aalhadxx commented Aug 4, 2026

Copy link
Copy Markdown
Author

Addressed the review comment: the result of writer.write_all is now propagated through the existing error path (writer.write_all(...)?). The prefix is only written when there are assertion data to print, matching Node/browser behavior.

@aalhadxx
aalhadxx force-pushed the fix/issue-19953 branch 2 times, most recently from 775c750 to 350f5d1 Compare August 4, 2026 15:07

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
src/jsc/ConsoleObject.rs (1)

541-541: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Propagate the prefix write error.

Line 541 discards the writer.write_all result. If the stream fails, the function continues and can return success after emitting incomplete assertion output. Propagate the error through the existing JsResult path before calling format2.

This is the same unresolved issue reported in the previous review. As per coding guidelines, I/O failures must be propagated explicitly instead of being discarded.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/jsc/ConsoleObject.rs` at line 541, Update the output-writing flow around
writer.write_all so its I/O error is propagated through the existing JsResult
path before format2 is called; remove the discarded-result handling and preserve
normal formatting only when the prefix write succeeds.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@src/jsc/ConsoleObject.rs`:
- Line 541: Update the output-writing flow around writer.write_all so its I/O
error is propagated through the existing JsResult path before format2 is called;
remove the discarded-result handling and preserve normal formatting only when
the prefix write succeeds.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c9174e0f-5aad-4ffe-b57c-73ec7e7dddde

📥 Commits

Reviewing files that changed from the base of the PR and between 775c750 and 350f5d1.

📒 Files selected for processing (1)
  • src/jsc/ConsoleObject.rs

@aalhadxx

aalhadxx commented Aug 4, 2026

Copy link
Copy Markdown
Author

@coderabbitai Good catch. The latest commit e951d30 propagates the writer.write_all(prefix) result through the existing error path (writer.write_all(prefix)?;), and only writes the prefix when there is assertion data. Let me know if you'd like any further changes.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@aalhadxx Confirmed. The update addresses the review comment. The error now propagates through the existing error path, and the prefix behavior matches the intended assertion-data condition.

🐇 ✅


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

@robobun

robobun commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR. This is being fixed as part of #37128, which reworks console output as a whole. It adds the Assertion failed: prefix and also follows Node's other rule, a bare Assertion failed followed by the value when the first argument is not a string (console.assert(false, 42) prints Assertion failed 42), so closing this one as a duplicate.

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.

console.assert() with message should include "Assertion failed" alongside message

2 participants