Feature/set map support for logging#6043
Conversation
|
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
78e385e to
2f005f2
Compare
WalkthroughAdds cross-sandbox serialization and rendering for Bruno special types (Set/Map/Function/undefined). VM consoles (Node VM and QuickJS) now serialize those types into Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
2f005f2 to
c9c2ec5
Compare
…into developer mode
c9c2ec5 to
29e5ab9
Compare
There was a problem hiding this comment.
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 | 🟡 MinorMove the new sleep inside the existing try/catch.
Line 167 runs before the try, so a missing/failed
bru.sleepbypasses the VM error logging and changes behavior whenbruisn’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."
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
[[Map]]wrapper property=>notation (e.g.,"key =>": "value")sizeproperty from displaySet Display Improvements
[[Set]]wrapper propertysizeproperty from displayImplementation Details
Modified Function:
transformBrunoTypes()returnMetadataparameter{ data, metadata }when metadata is requestedModified Function:
formatMessage()nameprop to 'Map' or 'Set' for type identificationcollapsedprop totruefor Maps and Sets (collapse by default)collapsed={1}for regular objects (collapse at depth 1)Testing
Tested with post-response script logging Set and Map objects:
=>notation at top levelDemo
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
Bug Fixes
Improvements
Other