You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Nexus] Need better error messages on bad request bodies #1848
I thought there was already an issue for this, but I couldn't find one. The errors from Nexus on bad request bodies are not very helpful. It's possible this can be fixed in Dropshot.
Example
If I give a string instead of a number for the size of a disk on disk create:
"unable to parse JSON body: invalid type: string \"abc\", expected u64 at line 1 column 43"
At the very least the error should point the user to a particular key in the JSON. "Unable to parse JSON body" is also an unfriendly way to say "You sent us some JSON (which is parseable as JSON) with a bad value in it."
By contrast, this is the error we're able to get out of Zod validators we generate from the OpenAPI spec for use in the console and its mock API server:
{"code": "invalid_type","expected": "number","received": "string","path": ["size"],"message": "Expected number, received string"}
We can use these validators as a workaround in the console (we aren't using them much yet), but getting something similar from the API itself is a matter of basic usability for a direct API consumer.
Error responses are more informative at this time (though there isn't always a consistent error code for the client to use for error handling).
Here is a summary of the request validation errors and examples (using the new cli in oxide-sdk-and-cli repo):
Invalid value - data type [InvalidValue]
$ ./cli instance create --project website --organization dev --description "some vm for a good cause" --hostname "is this even valid as a hostname?" --ncpus "x" --memory 1073741824 --name host1
error: invalid value 'x' for '--ncpus <ncpus>': invalid digit found in string
$ ./cli silo create --name saturn --discoverable 1 --identity_mode local_only --description "a dup"
error: invalid value '1' for '--discoverable <discoverable>'
[possible values: true, false]
Invalid value - data content [InvalidValue]
$ ./cli project create --name MyWebSite --organization dev --description web
error: invalid value 'MyWebSite' for '--name <name>': doesn't match pattern "^(?![0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)^[a-z][a-z0-9-]*[a-zA-Z0-9]*$"
$ ./cli instance create --project website --organization dev --description "some vm for a good cause" --hostname "is this even valid as a hostname?" --ncpus 1 --memory 1073741824 --name host1234567890112345678902123456789031234567890412345678905123456789061234567890
error: invalid value 'host1234567890112345678902123456789031234567890412345678905123456789061234567890' for '--name <name>': longer than 63 characters
Invalid value - data type [InvalidValue, in some cases]
$ ./cli instance create --project website --organization dev --description "some vm for a good cause" --hostname "is this even valid as a hostname?" --ncpus 1 --memory 107374182 --name host1
error
Error Response: status: 400 Bad Request; headers: {"content-type": "application/json", "x-request-id": "989c5eea-58c2-4bb3-a86d-c8988cc44e3d", "content-length": "168", "date": "Fri, 17 Mar 2023 22:40:47 GMT"}; value: Error { error_code: Some("InvalidValue"), message: "unsupported value for \"size\": memory must be at least 1 GiB", request_id: "989c5eea-58c2-4bb3-a86d-c8988cc44e3d" }
$ ./cli instance create --project website --organization dev --description "some vm for a good cause" --hostname "is this even valid as a hostname?" --ncpus 1 --memory true --name host1
error: one of the values isn't valid for an argument
$ ./cli instance create --project website --organization dev --description "some vm for a good cause" --hostname "is this even valid as a hostname?" --ncpus 1 --memory "x" --name host1
error: one of the values isn't valid for an argument
$ ./cli project create --name website --organization de --description web
error
Error Response: status: 404 Not Found; headers: {"content-type": "application/json", "x-request-id": "90692d85-1474-4c15-9b86-6f9a60932a65", "content-length": "149", "date": "Fri, 17 Mar 2023 22:30:12 GMT"}; value: Error { error_code: Some("ObjectNotFound"), message: "not found: organization with name \"de\"", request_id: "90692d85-1474-4c15-9b86-6f9a60932a65" }
Missing arguments
$ ./cli project create --name website --organization dev
error: the following required arguments were not provided:
--description <description>
Usage: oxide project create --organization <organization> --description <description> --name <name>
$ ./cli instance create --project website --description "some vm for a good cause" --hostname "is this even valid as a hostname?" --ncpus 1 --memory 1073741824 --name host1
error
Error Response: status: 400 Bad Request; headers: {"content-type": "application/json", "x-request-id": "ea09ab33-9e7b-4d72-bfe8-57c5bbaf48c1", "content-length": "185", "date": "Fri, 17 Mar 2023 22:38:02 GMT"}; value: Error { error_code: Some("InvalidRequest"), message: "project should either be specified by id or organization should be specified", request_id: "ea09ab33-9e7b-4d72-bfe8-57c5bbaf48c1"
Many of those nice messages come from validation that happens in the CLI before the request is even sent, so it's possible some of those are still not great on the API site. We did improve the API errors in this dropshot PR: oxidecomputer/dropshot#598
That change adds the word size to the original error message I reported in this issue, but IMO it barely helps. (Note I'm using oxide api to get the API's error message instead of having it be caught more nicely by the CLI.)
~/oxide/omicron $ oxide api '/v1/disks?project=prod-online' -X POST --input - <<EOF
{
"name": "abc",
"description": "",
"size": "abc",
"disk_source": { "block_size": 4096, "type": "blank" },
"block_size": "4096"
}
EOF
error; status code: 400 Bad Request
{ "message": "unable to parse JSON body: size: invalid type: string \"abc\", expected u64 at line 4 column 15",
"request_id": "d97c0ff3-74ac-43f3-b4f6-b7ec14a0dc88"
}
Like David says, some of these errors come from other places.
The errors about invalid/required flags come directly from the clap crate.
Some of these are directly from progenitor, like the one with the regex. I know Adam is working on those as part of the CLI code generation work he's doing.
I think the only problematic one that comes from the API itself is the last one (returning a 400 for a request that's valid but can't proceed because a VPC exists)
Activity
askfongjojo commentedon Apr 3, 2023
Error responses are more informative at this time (though there isn't always a consistent error code for the client to use for error handling).
Here is a summary of the request validation errors and examples (using the new cli in oxide-sdk-and-cli repo):
Invalid value - data type [InvalidValue]
Invalid value - data content [InvalidValue]
Invalid value - data type [InvalidValue, in some cases]
Duplicates [ObjectAlreadyExists]
Invalid value - object not found [ObjectNotFound]
Missing arguments
Invalid argument
Constraint violation [InvalidRequest]
cc @david-crespo, @zephraphm, @karencfv
askfongjojo commentedon Apr 3, 2023
We can perhaps mark this issue closed and open new ones for other specific improvements.
david-crespo commentedon Apr 3, 2023
Many of those nice messages come from validation that happens in the CLI before the request is even sent, so it's possible some of those are still not great on the API site. We did improve the API errors in this dropshot PR: oxidecomputer/dropshot#598
That change adds the word
sizeto the original error message I reported in this issue, but IMO it barely helps. (Note I'm usingoxide apito get the API's error message instead of having it be caught more nicely by the CLI.)david-crespo commentedon Apr 3, 2023
Here's the create silo error from the API side. It's not that bad — you can figure out from it what the problem is. But it's a bit noisy.
karencfv commentedon Apr 4, 2023
Like David says, some of these errors come from other places.
clapcrate.I think the only problematic one that comes from the API itself is the last one (returning a 400 for a request that's valid but can't proceed because a VPC exists)