goat-systems / go-tezos

Go Tezos Is a Go library that exposes and builds upon the Tezos RPC.
MIT License
71 stars 45 forks source link

InjectionOperation fails to parse failure result #178

Open utdrmac opened 3 years ago

utdrmac commented 3 years ago

Here's the actual result when attempting manually:

curl --verbose -H "content-type: application/json" -X POST --data '"03d7b1a..."' http://127.0.0.1:18732/injection/operation
...
* upload completely sent off: 320 out of 320 bytes
< HTTP/1.1 500 Internal Server Error
< content-length: 106
< content-type: application/json
<
[{"kind":"temporary","id":"failure","msg":"Unknown branch (BKjyVHcJu9yE), cannot inject the operation."}]

When attempting to use client.InjectionOperation(), json.Unmarshal assumes result is string and decode fails https://github.com/goat-systems/go-tezos/blob/430d10683e4d342fa6999fe5e9aadf45d219b52f/rpc/independent.go#L77

json: cannot unmarshal array into Go value of type string

utdrmac commented 3 years ago

Another example:

* upload completely sent off: 320 out of 320 bytes
< HTTP/1.1 500 Internal Server Error
< content-length: 259
< content-type: application/json
<
[{"kind":"temporary","id":"failure","msg":"Error while applying operation onhFNDM8v9h6A2p4F5uB1roCBbM2fwcUwxQNcAPYc9rhyuRSnZa:\nbranch refused (Error:\n                  Previously revealed manager key for contract tz1T1ScbsER3x2gex5LDL87uvGx9hwvNg1bq.\n)"}]
utdrmac commented 3 years ago

client.go:17, regRPCError does not properly match RPC errors:

https://play.golang.org/p/Or8-FeGRK28