Skip to content

Feature/set map support for logging#6043

Merged
bijin-bruno merged 3 commits intousebruno:mainfrom
james-ha-bruno:feature/set-map-support-for-logging
Feb 5, 2026
Merged

Feature/set map support for logging#6043
bijin-bruno merged 3 commits intousebruno:mainfrom
james-ha-bruno:feature/set-map-support-for-logging

Conversation

@james-ha-bruno
Copy link
Contributor

@james-ha-bruno james-ha-bruno commented Nov 7, 2025

Description

This PR improves the display of JavaScript Map and Set objects in Bruno's developer console to match Postman's cleaner, more user-friendly implementation.

JIRA

Changes

Map Display Improvements

  • ✅ Removed [[Map]] wrapper property
  • ✅ Display Map entries directly at top level with => notation (e.g., "key =>": "value")
  • ✅ Removed size property from display
  • ✅ Added "Map" type label for clarity
  • ✅ Collapse by default for cleaner console output

Set Display Improvements

  • ✅ Removed [[Set]] wrapper property
  • ✅ Display Set values directly at top level with numeric indices (0, 1, 2, ...)
  • ✅ Removed size property from display
  • ✅ Added "Set" type label for clarity
  • ✅ Collapse by default for cleaner console output

Implementation Details

Modified Function: transformBrunoTypes()

  • Enhanced to support metadata tracking via optional returnMetadata parameter
  • Returns { data, metadata } when metadata is requested
  • Metadata includes type information ('Map', 'Set', etc.)

Modified Function: formatMessage()

  • Uses metadata to determine display name and collapse behavior
  • Sets name prop to 'Map' or 'Set' for type identification
  • Sets collapsed prop to true for Maps and Sets (collapse by default)
  • Maintains collapsed={1} for regular objects (collapse at depth 1)

Testing

Tested with post-response script logging Set and Map objects:

  • ✅ Sets display with numeric indices at top level
  • ✅ Maps display with => notation at top level
  • ✅ Both collapse by default
  • ✅ Type labels clearly identify object types
  • ✅ Expandable/collapsible UI works correctly

Demo

set - maps console log update

Contribution Checklist:

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

Summary by CodeRabbit

  • New Features

    • Pretty-printing of Set and Map across sandboxes and the in-app log viewer for clearer, compact output.
    • Enhanced sandbox consoles now serialize Set/Map/Function/undefined for consistent logs.
  • Bug Fixes

    • Improved handling of circular references to prevent render/logging errors.
  • Improvements

    • Bruno-type-aware rendering with sensible collapse/summary behavior for complex objects.
  • Other

    • Minor timing adjustment to in-VM async execution.

@james-ha-bruno
Copy link
Contributor Author

Sample Bruno Request to use for testing Sets / Maps

- Remove size property from Map and Set displays
- Display Set values at top level with numeric indices (0, 1, 2, ...)
- Display Map entries at top level with => notation (key =>: value)
- Remove [[Set]] and [[Map]] wrapper properties for cleaner display
- Collapse Maps and Sets by default in console (matching Postman behavior)
- Add 'Map' and 'Set' type labels to clearly identify object types
- Maintain expandable/collapsible UI for easy inspection of contents
@bijin-bruno bijin-bruno force-pushed the feature/set-map-support-for-logging branch from 78e385e to 2f005f2 Compare February 4, 2026 12:44
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 4, 2026

Walkthrough

Adds cross-sandbox serialization and rendering for Bruno special types (Set/Map/Function/undefined). VM consoles (Node VM and QuickJS) now serialize those types into __brunoType/__brunoValue structures; Devtools console renderer detects and transforms them for compact, typed display.

Changes

Cohort / File(s) Summary
Devtools Console UI
packages/bruno-app/src/components/Devtools/Console/index.js
Added isPlainObject, transformBrunoTypes, and getBrunoTypeMetadata. LogMessage rendering now detects Bruno-tagged objects, transforms them (with circular protection), and adjusts ReactJson name/collapsed behavior for Map/Set.
Node VM console wrapper
packages/bruno-js/src/sandbox/node-vm/console.js, packages/bruno-js/src/sandbox/node-vm/index.js
New wrapConsoleWithSerializers(originalConsole) that recursively serializes Set/Map (and nested values) into { __brunoType, __brunoValue } forms and wraps VM console to apply this for log/debug/info/warn/error; integrated into VM context creation.
QuickJS console shim & VM timing tweak
packages/bruno-js/src/sandbox/quickjs/shims/console.js, packages/bruno-js/src/sandbox/quickjs/index.js
Replaced direct vm.dump usage with dumpWithSerializers to emit __brunoType representations for Set/Map and similar values; added an extra await bru.sleep(0) in the in-VM async execution path.

Sequence Diagram

sequenceDiagram
    participant Script as VM Script
    participant WrappedConsole as Wrapped Console
    participant Serializer as Transform/Serializer
    participant HostConsole as Host Console
    participant Devtools as Devtools UI

    Script->>WrappedConsole: console.log(value)
    WrappedConsole->>Serializer: transformValue(value)
    Serializer->>Serializer: detect Set/Map/Array/Object/Function
    Serializer-->>WrappedConsole: serialized ({__brunoType,__brunoValue}) or primitive
    WrappedConsole->>HostConsole: forward serialized args
    HostConsole->>Devtools: emit log message/event
    Devtools->>Devtools: getBrunoTypeMetadata()/transformBrunoTypes()
    Devtools-->>Devtools: render formatted, collapsed output
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno

Poem

🗺️ Maps and Sets now cross the wall,
Tagged and folded, shown to all.
VM whispers, UI sings,
Serialized treasures, pretty things—
Logs aligned, no more sprawl. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly reflects the main change: adding Set and Map support for logging in Bruno's developer console to improve readability.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Fix all issues with AI agents
In `@packages/bruno-app/src/components/Devtools/Console/index.js`:
- Around line 67-129: transformBrunoTypes currently deep-traverses every object
which causes infinite recursion on circular structures and flattens non-plain
objects (Date, Error, RegExp, class instances) to plain objects; fix by adding
cycle detection (use a WeakSet named like visited passed through recursive
calls) to return a placeholder (e.g., "[Circular]") when revisiting an object,
and add a plain-object guard (use an isPlainObject check:
Object.prototype.toString or constructor === Object) so that non-plain objects
are not recursively expanded but are returned as a sensible string/primitive
representation (e.g., date.toISOString(), error.message or error.stack,
regex.toString(), or obj.toString()) instead of {} ; update transformBrunoTypes
to accept an optional visited param and ensure getBrunoTypeMetadata continues to
treat Bruno special wrappers the same.

In `@packages/bruno-js/src/sandbox/node-vm/console.js`:
- Around line 17-50: transformValue is currently recursing into any object (and
into cycles) which flattens Date/Error/RegExp/instances and can cause stack
overflows on cyclic structures; update transformValue to accept an internal
WeakSet (e.g. visited) and bail with a sentinel like "[Circular]" when
revisiting an object, and only recurse into plain objects (guard by checking
Object.getPrototypeOf(value) === Object.prototype or similar) while leaving
non‑plain objects (Date, Error, RegExp, class instances) untouched or serialized
via toString/constructor info; make sure Set/Map/Array handling passes the
visited set through when mapping so cycles are detected across those
collections.

In `@packages/bruno-js/src/sandbox/quickjs/index.js`:
- Around line 167-214: The console overrides (console.log and the loop that
replaces console.debug/info/warn/error) currently include a size property in the
Set/Map payloads; remove the size field from both processed Set and Map objects
so they only include __brunoType and __brunoValue to match the new display
contract—update the mapping logic inside the console.log override (refer to
originalConsoleLog and its processedArgs mapping) and inside the forEach
override (refer to originalMethod and its processedArgs mapping) to stop adding
size for both Set and Map cases.

In `@packages/bruno-js/src/sandbox/quickjs/shims/console.js`:
- Around line 4-58: The dumpWithSetMapSupport function can leak QuickJS handles
if vm.getProp or vm.callFunction throws; update it to track any created handles
(e.g., constructorProp, constructorNameProp, arrayFromFn, fromFn, arrayResult)
and ensure they are disposed in a single finally block regardless of success or
error, using try/finally around the main logic so every created handle is
disposed before returning or rethrowing; keep the existing early returns but
move handle disposal into that centralized cleanup so no handle is left
undisposed on error paths.

@bijin-bruno bijin-bruno force-pushed the feature/set-map-support-for-logging branch from 2f005f2 to c9c2ec5 Compare February 4, 2026 15:05
@bijin-bruno bijin-bruno force-pushed the feature/set-map-support-for-logging branch from c9c2ec5 to 29e5ab9 Compare February 4, 2026 16:45
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-js/src/sandbox/quickjs/index.js (1)

160-168: ⚠️ Potential issue | 🟡 Minor

Move the new sleep inside the existing try/catch.

Line 167 runs before the try, so a missing/failed bru.sleep bypasses the VM error logging and changes behavior when bru isn’t injected.

Proposed fix
-        await bru.sleep(0);
-        try {
+        try {
+          await bru.sleep(0);
           ${externalScript}
🧹 Nitpick comments (1)
packages/bruno-js/src/sandbox/quickjs/shims/console.js (1)

4-94: Add a brief JSDoc for the new serializer helper.

This helper is now a core abstraction; a short JSDoc will clarify the input handle and the returned shape.

Suggested JSDoc
-  // Helper function to convert QuickJS values to native values with Set/Map support
+  /**
+   * Convert QuickJS values to native values, including Set/Map wrappers.
+   * `@param` {*} arg
+   * `@returns` {*}
+   */
   const dumpWithSerializers = (arg) => {

As per coding guidelines, "Add JSDoc comments to abstractions for additional details."

@bijin-bruno bijin-bruno merged commit e6dd582 into usebruno:main Feb 5, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants