Skip to content

fix: preserve the raw flag of logs queued during a pause - #447

Open
MFA-G wants to merge 1 commit into
unjs:mainfrom
MFA-G:fix/resume-logs-preserve-raw
Open

fix: preserve the raw flag of logs queued during a pause#447
MFA-G wants to merge 1 commit into
unjs:mainfrom
MFA-G:fix/resume-logs-preserve-raw

Conversation

@MFA-G

@MFA-G MFA-G commented Aug 27, 2026

Copy link
Copy Markdown

Fixes #438.

Problem

_wrapLogFn stores isRaw as the fourth entry of the queue item:

queue.push([this, defaults, args, isRaw]);

but resumeLogs only forwarded the first three:

item[0]._logFn(item[1], item[2]); // item[3] never passed

so _logFn always received isRaw === undefined when replaying a queued log. That falsy value activates the log-object branch:

if (!isRaw && args.length === 1 && isLogObj(args[0])) {
  Object.assign(logObj, args[0]);
}

A .raw() call made while paused therefore behaves differently from the same call made without a pause: a single log-object argument is merged into the log object instead of being passed through as an argument.

const c = createConsola({ reporters: [{ log: obj => console.log(JSON.stringify(obj.args)) }] });

c.log.raw({ message: "hello" });   // [{"message":"hello"}]

c.pauseLogs();
c.log.raw({ message: "hello" });
c.resumeLogs();                    // ["hello"]  <- before this PR

Fix

Forward item[3] in resumeLogs.

Tests

test/consola.test.ts had no coverage for pauseLogs/resumeLogs at all, so this adds two tests:

  • resumeLogs preserves the raw flag of queued logs — logs the same raw object once without a pause and once through a pause/resume cycle, and asserts both reporter calls receive identical args. It fails on main and passes with the fix.
  • resumeLogs still merges non-raw log objects of queued logs — pins the non-raw queued path so the fix does not accidentally make every replayed log raw.

Validation

  • npx vitest run -> 5 passed (5)
  • pnpm lint (eslint . + prettier -c src examples test) -> clean

Summary by CodeRabbit

  • Bug Fixes

    • Preserved raw log output when queued messages are replayed after logging resumes.
    • Ensured queued standard log objects retain their expected message formatting.
  • Tests

    • Added coverage for raw and standard queued log behavior when logging resumes.

`_wrapLogFn` stores `isRaw` as the fourth entry of the queue item, but
`resumeLogs` only forwarded the first three, so `_logFn` always received
`isRaw === undefined` when replaying.

A `.raw()` call made while paused therefore took the non-raw branch on
resume: a single log-object argument was merged into the log object
instead of being passed through as an argument, producing different
output than the same call made without a pause.

Forward `item[3]` and cover both paths with tests.

Fixes unjs#438
@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0a7956e3-2e2c-4064-be5e-c90f49b43b96

📥 Commits

Reviewing files that changed from the base of the PR and between c47faac and 42bab52.

📒 Files selected for processing (2)
  • src/consola.ts
  • test/consola.test.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

resumeLogs now preserves the raw flag for queued logs. Tests cover raw log arguments and non-raw single-object logs after pause and resume.

Changes

Queued log replay

Layer / File(s) Summary
Forward queued log mode
src/consola.ts, test/consola.test.ts
resumeLogs passes the queued isRaw flag to _logFn. Tests verify that raw log objects remain arguments and non-raw log objects are merged into the emitted log. ๆ

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 42bab

This localized change preserves raw log arguments during pause/resume replay and adds regression tests for both raw and non-raw behavior; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: preserving the raw flag for logs queued during a pause.
Linked Issues check ✅ Passed The change satisfies issue #438 by forwarding the stored isRaw flag in resumeLogs. The added tests cover raw queued logs and preserve non-raw log-object merging behavior.
Out of Scope Changes check ✅ Passed All changes support issue #438. The source fix and focused regression tests are directly related to preserving queued log behavior.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

resumeLogs drops isRaw flag, mangling .raw() calls queued during pause

1 participant