Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

k6 Converter: Cannot unmarshal array into Go value of type map[string]interface {} #777

Closed
san-slysz opened this issue Sep 24, 2018 · 3 comments
Labels

Comments

@san-slysz
Copy link

san-slysz commented Sep 24, 2018

Hey everyone,

I'm using the .har converter, and on one files obtained an error message.

Step to reproduce

  • Use my .har file
  • Convert it (see the line I use below)

Convert line
san@computer:~/mypath$ k6 convert save.har -O save.js --enable-status-code-checks --correlate --no-batch (--skip url1 --skip url2...)

Error Message
ERRO[0000] json: cannot unmarshal array into Go value of type map[string]interface {}

File (.har)
The file is difficult to reduce (and still make it valid). And contains some data I'm not crazy to put here. So please contact me (I'm on k6 slack) to obtain it :).

@na-- na-- added the bug label Sep 24, 2018
@na--
Copy link
Member

na-- commented Oct 8, 2018

@san-ouadghiri sent me a sample file that triggered this and the issue is a wrong assumption in the k6 HAR converter. Here's a pared-down and edited version of the problematic HAR file:

{
  "log": {
    "version": "1.1",
    "creator": {
      "name": "Firefox",
      "version": "62.0"
    },
    "browser": {
      "name": "Firefox",
      "version": "62.0"
    },
    "pages": [
      {
        "startedDateTime": "2018-09-24T10:57:17.234+02:00",
        "id": "page_3",
        "title": "sample page",
        "pageTimings": {
          "onContentLoad": -1,
          "onLoad": -1
        }
      }
    ],
    "entries": [
      {
        "pageref": "page_3",
        "startedDateTime": "2018-09-24T10:57:17.234+02:00",
        "request": {
          "bodySize": 2,
          "method": "PATCH",
          "url": "https://httpbin.org/anything",
          "httpVersion": "HTTP/2.0",
          "headers": [
            {
              "name": "content-type",
              "value": "application/json"
            }
          ],
          "queryString": [],
          "postData": {
            "mimeType": "application/json",
            "params": [],
            "text": "[]"
          }
        },
        "response": {
          "status": 200,
          "statusText": "OK",
          "httpVersion": "HTTP/2.0",
          "headers": [
            {
              "name": "content-type",
              "value": "application/json; charset=utf-8"
            }
          ],
          "cookies": [],
          "content": {
            "mimeType": "application/json; charset=utf-8",
            "size": 2,
            "text": "{}"
          },
          "redirectURL": "",
          "headersSize": 566,
          "bodySize": 2
        },
        "cache": {},
        "timings": {
          "blocked": 0,
          "dns": 0,
          "connect": 0,
          "ssl": 0,
          "send": 0,
          "wait": 811,
          "receive": 0
        },
        "time": 811,
        "_securityState": "secure",
        "connection": "443"
      }
    ]
  }
}

The problem comes from the "text": "[]" in postData - k6 attempts to json.Unmarshal() that into a map[string]interface{} variable and predictably fails.

@san-ouadghiri - disabling --correlate will work around the issue for now. I have to delve deeper into the correlation logic to understand the rationale behind the current code, but fixing the issue may just involve ignoring any cases that don't fit the current narrow correlation logic...

@san-slysz
Copy link
Author

Thanks! Good luck with your fix-expedition. In the meanwhile I'll use the given workaround :).

@codebien
Copy link
Collaborator

codebien commented Oct 3, 2023

The k6 convert command has been deprecated and will be removed in the future #3365.

Use https://github.com/grafana/har-to-k6 as a better alternative.

@codebien codebien closed this as completed Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants