thoth-org / Thoth.Fetch

Thoth.Fetch provides an easy to use API for working with Fable.Fetch and Thoth.Json
https://thoth-org.github.io/Thoth.Fetch/
MIT License
35 stars 11 forks source link

Extra coders seem to be getting recognized, but their results aren't used #17

Open reinux opened 4 years ago

reinux commented 4 years ago

I have a couple coders for single-case unions:

let itemIDEnc (ItemID id) =
  Encode.string id
let itemIDDec : Decoder<ItemID> =
  Decode.map ItemID Decode.string

let extras =
  Extra.empty
    |> Extra.withCustom itemIDEnc itemIDDec
    |> Extra.withInt64

And I receive it fairly straightforwardly:

  let cmd = promise {
    return! Fetch.tryPost(Routes.query, q, extra = JsonCodecs.extras)
  }
  m, Cmd.OfPromise.perform
      (fun () -> cmd :?> JS.Promise<Result<QueryResult, FetchError>>) ()
      (fun r -> QueryResultReceived (TabID 1, r))

QueryResult has a couple int64s in there, so it'll complain if I don't have the withInt64 in there, but it still loses precision, and the other ItemID just takes on a raw string value, which causes an invalid access exception later on when I try to retrieve the value.

The same coders work fine on the encoder side.

What could be going on here?

MangelMaxime commented 4 years ago

Which version of the library are you using?

Because, since version 2, we do have tests for extra coder and then seems to all pass.

reinux commented 4 years ago

That's odd... I'm using 2.0.0.

MangelMaxime commented 4 years ago

Then I have no idea, can you please try to add a failing test?

Because right now I can't really help as according to the tests it should be supported 🤷‍♂️

reinux commented 4 years ago

Hmm... I'm trying to build Thoth.Fetch on my machine, but I keep getting an error with fake build:

Script reported an error: -> BuildFailedException: Target 'YarnInstall' failed. -> One or more errors occurred. ('yarn install' task failed) -> 'yarn install' task failed

MangelMaxime commented 4 years ago

Do you have yarn installed on your machine?

Can you please try to set Fake to be verbose? I think it is with --verbose.

Does yarn install work if you execute it manually?

reinux commented 4 years ago

fake --v build output (where it errors out):

---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target          Duration
------          --------
Clean           00:00:00.0858898
YarnInstall     00:00:08.0190067   ('yarn install' task failed)
DotnetRestore   00:00:00           (skipped)
MochaTest       00:00:00           (skipped)
Total:          00:00:08.3185375
Status:         Failure
---------------------------------------------------------------------
saving cache...
Script reported an error, see standard error for details.
Script reported an error:
-> BuildFailedException: Target 'YarnInstall' failed.
   StackTrace:
        at Fake.Core.TargetModule.raiseIfError(OptionalTargetContext context) in D:\a\1\s\src\app\Fake.Core.Target\Target.fs:line 968
        at Fake.Core.TargetModule.runOrDefault(String defaultTarget) in D:\a\1\s\src\app\Fake.Core.Target\Target.fs:line 1150
        at <StartupCode$build_E709CA1B3B6432F31128B87BD678A183A6B658B9891136EDD4278807EAED3AD5>.$Build$fsx.main@() in C:\Users\rei\source\repos\Thoth-Fetch\Thoth.Fetch\build.fsx:line 252
-> One or more errors occurred. ('yarn install' task failed)
-> 'yarn install' task failed
   StackTrace:
        at Fake.Core.CreateProcess.ensureExitCodeWithMessage@576.Invoke(a data, Int32 exitCode) in D:\a\1\s\src\app\Fake.Core.Process\CreateProcess.fs:line 577
        at Fake.Core.CreateProcess.addOnExited@568-5.Invoke(RawProcessResult _arg2) in D:\a\1\s\src\app\Fake.Core.Process\CreateProcess.fs:line 568
        at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, FSharpFunc`2 userCode, b result1) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 416
        at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 109
     --- End of stack trace from previous location where exception was thrown ---
        at Microsoft.FSharp.Control.AsyncResult`1.Commit() in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 349
        at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronouslyInCurrentThread[a](CancellationToken cancellationToken, FSharpAsync`1 computation) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 870
        at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 890
        at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 1153
        at Fake.JavaScript.Yarn.run(YarnParams yarnParams, YarnCommand command) in D:\a\1\s\src\app\Fake.JavaScript.Yarn\Yarn.fs:line 78
        at Fake.JavaScript.Yarn.install(FSharpFunc`2 setParams) in D:\a\1\s\src\app\Fake.JavaScript.Yarn\Yarn.fs:line 97        at Build.clo@87-2.Invoke(TargetParameter _arg2) in C:\Users\rei\source\repos\Thoth-Fetch\Thoth.Fetch\build.fsx:line 88
        at Fake.Core.TargetModule.runSimpleInternal(TargetContext context, Target target) in D:\a\1\s\src\app\Fake.Core.Target\Target.fs:line 300
Hint: Detected paket version '5.210.1' in your paket.dependencies file bootstrapper arguments, consider locking the version to '5.245.1' in your dependencies file (C:\Users\rei\source\repos\Thoth-Fetch\Thoth.Fetch\paket.dependencies).
Read https://github.com/fsharp/FAKE/issues/2193 for details.
Performance:
reinux commented 4 years ago

I tried yarn install too, but yarn also crashes with a few warnings and then an error:

PS C:\Users\rei\source\repos\Thoth-Fetch\Thoth.Fetch> yarn install
yarn install v1.17.3
[1/4] Resolving packages...
[2/4] Fetching packages...
warning Pattern ["colors@latest"] is trying to unpack in the same destination "C:\\Users\\rei\\AppData\\Local\\Yarn\\Cache\\v4\\npm-colors-1.4.0-c50491479d4c1bdaed2c9ced32cf7c7dc2360f78\\node_modules\\colors" as pattern ["colors@^1.3.1"]. This could result in non-deterministic behavior, skipping.
warning Pattern ["cors@latest"] is trying to unpack in the same destination "C:\\Users\\rei\\AppData\\Local\\Yarn\\Cache\\v4\\npm-cors-2.8.5-eac11da51592dd86b9f06f6e7ac293b3df875d29\\node_modules\\cors" as pattern ["cors@^2.8.5"]. This could result in non-deterministic behavior, skipping.
warning Pattern ["object-assign@latest"] is trying to unpack in the same destination "C:\\Users\\rei\\AppData\\Local\\Yarn\\Cache\\v4\\npm-object-assign-4.1.1-2109adc7965887cfc05cbbd442cac8bfbb360863\\node_modules\\object-assign" as pattern ["object-assign@^4.1.0","object-assign@^4.0.1","object-assign@^4.0.1","object-assign@^4.1.0","object-assign@^4.1.1","object-assign@^4","object-assign@^4.1.1","object-assign@^4.1.1","object-assign@^4.1.1","object-assign@^4.1.1","object-assign@^4"]. This could result in non-deterministic behavior, skipping.
warning Pattern ["send@latest"] is trying to unpack in the same destination "C:\\Users\\rei\\AppData\\Local\\Yarn\\Cache\\v4\\npm-send-0.17.1-c1d8b059f7900f7466dd4938bdc44e11ddb376c8\\node_modules\\send" as pattern ["send@0.17.1","send@0.17.1"]. This could result in non-deterministic behavior, skipping.
info fsevents@1.2.9: The platform "win32" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.1.0: The platform "win32" is incompatible with this module.
info "fsevents@2.1.0" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
[-/3] ⠄ waiting...
[2/3] ⠄ oniguruma
error C:\Users\rei\source\repos\Thoth-Fetch\Thoth.Fetch\node_modules\oniguruma: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: C:\Users\rei\source\repos\Thoth-Fetch\Thoth.Fetch\node_modules\oniguruma
Output:
C:\Users\rei\source\repos\Thoth-Fetch\Thoth.Fetch\node_modules\oniguruma>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
gyp info it worked if it ends with ok
gyp info using node-gyp@3.8.0
gyp info using node@12.7.0 | win32 | x64
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Python37\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                                ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:295:12)
gyp ERR! stack     at ChildProcess.emit (events.js:203:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\rei\source\repos\Thoth-Fetch\Thoth.Fetch\node_modules\oniguruma
gyp ERR! node -v v12.7.0
gyp ERR! node-gyp -v v3.8.0
MangelMaxime commented 4 years ago

Ok, so this is a problem with the oniguruma dependency and your environnement...

I think you are using a newer version of Node.js than me.

Can please clean your repro git clean -xdf and then try to run yarn upgrade to force an upgrade all the dependencies. Perhaps a fix has been released in one of them...

reinux commented 4 years ago

No luck, same error on yarn upgrade as with yarn install :(

I wonder if this is only happening for me, and if it's maybe a corrupt Python install or something.

MangelMaxime commented 4 years ago

I can't really help you much more then...

I will configure this repo to support https://gitpod.io/ so you will be able to work on it without installing anything on your machine all from your browser.

reinux commented 4 years ago

Thanks, I appreciate the effort.

I'll try installing it on my laptop machine when I get a chance. I have to update VS and a bunch of other stuff in order to get it to work.

MangelMaxime commented 4 years ago

I am blocked by an issue where Dotnet Core complains about "Permission denied" on Gitpod... I open a discussion to try to solve it because it is not the first time I have this problem but I never really understood how to fix it.

So the environment will take some time to be available.