Skip to content

[Nexus] Need better error messages on bad request bodies #1848

Open

Description

@david-crespo

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:

{
  "name": "abc",
  "description": "",
  "size": "abc",
  "disk_source": { "block_size": 4096, "type": "blank" },
  "block_size": "4096"
}

The error message is this:

"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.

Activity

  1. self-assigned this
    on Feb 28, 2023
  2. askfongjojo commented on Apr 3, 2023

    @askfongjojo

    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
    

    Duplicates [ObjectAlreadyExists]

    $ ./cli project create --name website --organization dev --description web 
    error
    Error Response: status: 400 Bad Request; headers: {"content-type": "application/json", "x-request-id": "b2fbc9b1-dfcd-4c70-97e4-67606a9e57f2", "content-length": "149", "date": "Fri, 17 Mar 2023 22:25:34 GMT"}; value: Error { error_code: Some("ObjectAlreadyExists"), message: "already exists: project \"website\"", request_id: "b2fbc9b1-dfcd-4c70-97e4-67606a9e57f2" }
    

    Invalid value - object not found [ObjectNotFound]

    $ ./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"
    

    Invalid argument

    $ ./cli silo create  --name venus --discoverable true --identity_mode local_only --description "another idp" --stuff unknown
    error: unexpected argument '--stuff' found
    Usage: oxide silo create --description <description> --discoverable <discoverable> --identity_mode <identity_mode> --name <name>
    

    Constraint violation [InvalidRequest]

    $ ./cli project delete --project website-stg  --organization dev
    error
    Error Response: status: 400 Bad Request; headers: {"content-type": "application/json", "x-request-id": "2d7fc15e-f5e4-4d68-9235-c6e3babb361d", "content-length": "154", "date": "Fri, 17 Mar 2023 06:08:27 GMT"}; value: Error { error_code: Some("InvalidRequest"), message: "project to be deleted contains a vpc: default", request_id: "2d7fc15e-f5e4-4d68-9235-c6e3babb361d" }
    

    cc @david-crespo, @zephraphm, @karencfv

  3. askfongjojo commented on Apr 3, 2023

    @askfongjojo

    We can perhaps mark this issue closed and open new ones for other specific improvements.

  4. david-crespo commented on Apr 3, 2023

    @david-crespo
    ContributorAuthor

    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"
    }
    
  5. david-crespo commented on Apr 3, 2023

    @david-crespo
    ContributorAuthor

    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.

    $ oxide api '/v1/system/silos' -X POST --input - <<EOF
    {
      "name": "saturn",
      "description": "hi",
      "discoverable": "1",
      "identity_mode": "local_only"
    }
    EOF
    error; status code: 400 Bad Request
    {
      "message": "unable to parse JSON body: discoverable: invalid type: string \"1\", expected a boolean at line 4 column 21",
      "request_id": "416c0eb5-12fa-4b0f-8e9c-045f08ce97d8"
    }
    
  6. karencfv commented on Apr 4, 2023

    @karencfv
    Contributor

    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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions