replicate / replicate-go

Go client for Replicate
https://replicate.com
Apache License 2.0
65 stars 9 forks source link

Unknown error: json: cannot unmarshal object into Go struct field APIError.detail of type string #38

Closed mmazurkevich closed 7 months ago

mmazurkevich commented 8 months ago

I've got it from replicate-go@v0.14.2/apierror.go unmarshalAPIError function. Exception at unmarshalling doesn't allow me to see the original root cause of the request failure.

Example of JSON:

{"detail":{"name":"Enter a valid name. This value may contain only lowercase letters, numbers, dashes, underscores, or periods, and may not start or end with a dash, underscore, or period."}}

failed with with the following exception: Unknown error: json: cannot unmarshal object into Go struct field APIError.detail of type string

mmazurkevich commented 8 months ago

As I see in the example of error message from server there has to be no nested objects in the JSON from the server https://replicate.com/docs/reference/http#rate-limits

Also it worth to mention the requirements for the name somewhere in the documentation, at least in the https://replicate.com/docs/reference/http

mattt commented 8 months ago

Hi @mmazurkevich. Thanks for reporting. The response sent by Replicate's API for invalid models in the POST /models endpoint is incorrect. This is something we'll need to fix on our side.

mattt commented 7 months ago

@mmazurkevich I'm happy to say that this is now fixed. Replicate's API now returns error objects in the form of RFC 9457 problem details. I just ran replicate model create with an invalid hardware sku, and it correctly repoted the error instead of panicking with that JSON error. Thanks again for reporting!