parroty / exvcr

HTTP request/response recording library for elixir, inspired by VCR.
MIT License
722 stars 132 forks source link

JSX encode argument error #112

Closed beerlington closed 7 years ago

beerlington commented 7 years ago

I'm making a request in one of my tests that uses the path_encode_fun hackney option in order to override hackney's default url encoding. Doing so causes an encoding error as shown below. I suspect that the function in the request options is possibly causing the problem.

     ** (ArgumentError) argument error
     stacktrace:
       lib/jsx.ex:154: JSX.Encoder.Function.json/1
       lib/jsx.ex:121: JSX.Encoder.List.unzip/1
       lib/jsx.ex:121: JSX.Encoder.List.unzip/1
       lib/jsx.ex:114: JSX.Encoder.List.json/1
       lib/jsx.ex:105: JSX.Encoder.Map.unpack/2
       lib/jsx.ex:105: JSX.Encoder.Map.unpack/2
       lib/jsx.ex:101: JSX.Encoder.Map.json/1
       lib/jsx.ex:105: JSX.Encoder.Map.unpack/2
       lib/jsx.ex:101: JSX.Encoder.Map.json/1
       lib/jsx.ex:126: JSX.Encoder.List.unhitch/1
       lib/jsx.ex:117: JSX.Encoder.List.json/1
       lib/jsx.ex:4: JSX.encode!/2
       lib/exvcr/json.ex:12: ExVCR.JSON.save/2

I logged out what is getting passed to JSX.encode!/2 and pasted that below:

[%{request: %ExVCR.Request{body: "<removed>",
    headers: [{"Authorization", "***"}], method: "post",
    options: [proxy_auth: ["fixie", "removed"],
     proxy: "http://removed.usefixie.com:80", insecure: true,
     path_encode_fun: #Function<1.65578755/1 in MyApp.Request.auth_options/0>],
    request_body: "",
    url: "https://myapp.example/import/return_seq"},
   response: %ExVCR.Response{body: "14",
    headers: [{"Server",
      "Removed/0.3.8r1 Win-x86 OpenSSL/1.0.2j REST/0.3.8r1"},
     {"Date", "Tue, 20 Jun 2017 18:45:15 GMT"}, {"Connection", "close"},
     {"Cache-Control", "no-store, no-cache, must-revalidate"},
     {"Pragma", "no-cache"}, {"Expires", "Tue, 20 Jun 2017 18:45:15 GMT"},
     {"Content-Type", "text/plain"}], status_code: 200, type: "ok"}}]

Any ideas on how I can get around this? Thanks!

beerlington commented 7 years ago

I ended up fixing it with this https://github.com/AgilionApps/exvcr/commit/452cec8b1ebfad8cde2d38788bc1d9b7278eafc7

Not sure if that's the best fix, but I needed something. I'm happy to open a PR with a test if this seems good.

bernardd commented 7 years ago

Ah good, thanks, I was just fighting with the exact same issue.

parroty commented 7 years ago

Sorry being not responsive. Thank for the report and fix suggestion.

I'm happy to open a PR with a test if this seems good.

I appreciate if you could open a PR with a test case. I think the suggest fix would be good (there might be better solution to cover other related areas, but it would fix the original one).

parroty commented 7 years ago

Sorry being late. I've pushed the suggested code as above. I'm closing at the moment, but you find remaining issue, please reopen or open another one.

beerlington commented 7 years ago

@parroty thanks! I was going to do it and totally spaced it. Much appreciated.