usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
25.42k stars 1.16k forks source link

[Bug] Bru files containing multipart-form with json are not loaded #1692

Closed hhanquez closed 2 months ago

hhanquez commented 6 months ago

I'm writing requests containing multipart/form with json and files

When bruno is loading the collection, the bru file is not loaded as the body can't be parsed

Exemple of body:

body:multipart-form {
  body: {
    "label": "json",
    "foo": "bar"
  },
  file: @file(/home/myname/file.svg)
}

Error in console:

watcher add: /home/myname/bruno/collection/multipartTest.bru
Error sending from webFrameMain:  Error: Failed to serialize arguments
    at s.send (node:electron/js2c/browser_init:169:631)
    at g.send (node:electron/js2c/browser_init:165:2156)
    at add (/tmp/.mount_bruno_GLHdRM/resources/app.asar/src/app/watcher.js:258:23)
    at FSWatcher.<anonymous> (/tmp/.mount_bruno_GLHdRM/resources/app.asar/src/app/watcher.js:436:34)
    at FSWatcher.emit (node:events:527:28)
    at FSWatcher.emitWithAll (/tmp/.mount_bruno_GLHdRM/resources/app.asar/node_modules/chokidar/index.js:540:8)
    at FSWatcher._emit (/tmp/.mount_bruno_GLHdRM/resources/app.asar/node_modules/chokidar/index.js:632:8)
    at NodeFsHandler._handleFile (/tmp/.mount_bruno_GLHdRM/resources/app.asar/node_modules/chokidar/lib/nodefs-handler.js:400:14)
    at NodeFsHandler._addToNodeFs (/tmp/.mount_bruno_GLHdRM/resources/app.asar/node_modules/chokidar/lib/nodefs-handler.js:637:21)
(node:25051) UnhandledPromiseRejectionWarning: Error: Line 25, col 5:
  24 |     "foo": "bar"
> 25 |   },
           ^
  26 |   file: @file(/home/myname/file.svg)
Expected ":"
    at parser (/tmp/.mount_bruno_GLHdRM/resources/app.asar/node_modules/@usebruno/lang/v2/src/bruToJson.js:567:11)
    at bruToJson (/tmp/.mount_bruno_GLHdRM/resources/app.asar/src/bru/index.js:94:18)
    at add (/tmp/.mount_bruno_GLHdRM/resources/app.asar/src/app/watcher.js:255:19)
    at FSWatcher.<anonymous> (/tmp/.mount_bruno_GLHdRM/resources/app.asar/src/app/watcher.js:436:34)
    at FSWatcher.emit (node:events:527:28)
    at FSWatcher.emitWithAll (/tmp/.mount_bruno_GLHdRM/resources/app.asar/node_modules/chokidar/index.js:540:8)
    at FSWatcher._emit (/tmp/.mount_bruno_GLHdRM/resources/app.asar/node_modules/chokidar/index.js:632:8)
    at NodeFsHandler._handleFile (/tmp/.mount_bruno_GLHdRM/resources/app.asar/node_modules/chokidar/lib/nodefs-handler.js:400:14)
    at NodeFsHandler._addToNodeFs (/tmp/.mount_bruno_GLHdRM/resources/app.asar/node_modules/chokidar/lib/nodefs-handler.js:637:21)
(node:25051) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)

Tested on versions 1.9.0 and 1.10.0

LucaRed commented 5 months ago

Still present on v1.12.3. This bug bit me after importing a big collection from Insomnia :-S

Example body:

meta {
  name: Test
  type: http
  seq: 7
}

post {
  url: {{host}}/api/test
  body: multipartForm
  auth: none
}

headers {
  Accept: application/json, text/plain, */*
  Content-Type: application/json
}

body:multipart-form {
  city: {
    "name": "Test",
    "description": "Test"
  }
}
fskexp commented 4 months ago

Hi, a workaround could be to minify your JSON so it fits on a single line (worked for me).

sanjai0py commented 4 months ago

This bug has been fixed #2086. Please try the latest version of Bruno!

hhanquez commented 3 months ago

Sorry @sanjai0py but I still have the issue on version 1.18.0

This is a test file:

meta {
  name: Test of issue 1692
  type: http
  seq: 3
}

post {
  url: https://www.test.com
  body: multipartForm
  auth: none
}

body:multipart-form {
  body: {
      "label": "json",
      "foo": "bar"
    }
  file: @file(/home/myplace/Images/gif/OuEmkXe.gif)
}

The file is not loaded and I see this in the logs:

(node:242998) UnhandledPromiseRejectionWarning: Error: Line 17, col 6:
  16 |       "foo": "bar"
> 17 |     }
            ^
  18 |   file: @file(/home/myplace/Images/gif/OuEmkXe.gif)
Expected ":"
    at parser (/opt/Bruno/resources/app.asar/node_modules/@usebruno/lang/v2/src/bruToJson.js:592:11)
    at bruToJson (/opt/Bruno/resources/app.asar/src/bru/index.js:94:18)
    at add (/opt/Bruno/resources/app.asar/src/app/watcher.js:249:19)
    at FSWatcher.<anonymous> (/opt/Bruno/resources/app.asar/src/app/watcher.js:548:34)
    at FSWatcher.emit (node:events:527:28)
    at FSWatcher.emitWithAll (/opt/Bruno/resources/app.asar/node_modules/chokidar/index.js:540:8)
    at FSWatcher._emit (/opt/Bruno/resources/app.asar/node_modules/chokidar/index.js:632:8)
    at NodeFsHandler._handleFile (/opt/Bruno/resources/app.asar/node_modules/chokidar/lib/nodefs-handler.js:400:14)
    at NodeFsHandler._addToNodeFs (/opt/Bruno/resources/app.asar/node_modules/chokidar/lib/nodefs-handler.js:637:21)
(Use `bruno --trace-warnings ...` to show where the warning was created)
(node:242998) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
sanjai0py commented 3 months ago

Hi @hhanquez the PR #2407 with the fix has been merged. The next outgoing release will fix your problem.

sanjai0py commented 2 months ago

Closing this issue has been fixed. Thank you for taking the time to report the bug, everyone!