Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Improve error messages for API configuration save #2973

Open
gbraad opened this issue Jan 28, 2022 · 8 comments
Open

[Enhancement] Improve error messages for API configuration save #2973

gbraad opened this issue Jan 28, 2022 · 8 comments
Labels
kind/enhancement New feature or request priority/major status/pinned Prevents the stale bot from closing the issue

Comments

@gbraad
Copy link
Contributor

gbraad commented Jan 28, 2022

When a value fails validation, the error message is returned in the body. When multiple errors occur, they are concatenated in the body. This makes parsing very difficult in the applications using this:

Getting:
500

  body: "Value '6144' for configuration property 'memory' is invalid, reason: requires memory in MiB >= 9216\n" +
    "Value '19' for configuration property 'disk-size' is invalid, reason: requires disk size in GiB >= 31\n"

Is not the same as:
500

[
   {
      "value":"memory",
      "default":"9216",
      "request":"6144",
      "reason":"invalid",
      "requires":">= 9216"
   },
   {
      "value":"disk-size",
      "default":"31",
      "request":"19",
      "reason":"invalid",
      "requires":">= 31"
   }
]
@gbraad gbraad added kind/bug Something isn't working status/need triage labels Jan 28, 2022
@gbraad gbraad added kind/enhancement New feature or request priority/major and removed kind/bug Something isn't working status/need triage labels Jan 28, 2022
@cfergeau
Copy link
Contributor

This can be reproduced by adding this to the test suite:

diff --git a/pkg/crc/api/api_http_test.go b/pkg/crc/api/api_http_test.go
index 2d743126..b0db23a2 100644
--- a/pkg/crc/api/api_http_test.go
+++ b/pkg/crc/api/api_http_test.go
@@ -369,6 +369,16 @@ var testCases = []testCase{
                request:  get("config?cpus"),
                response: jSon(`{"Success":true,"Error":"","Configs":{"cpus":4}}`),
        },
+       {
+               request:  post("config?cpus").withBody(`{"properties":{"cpus":4}}`),
+               response: httpError(200).withBody(`{"Success":true,"Error":"","Properties":["cpus"]}`),
+       },
+       {
+               request: post("config?cpus").withBody(`{"properties":{"cpus":0,"memory":0}}`),
+               response: httpError(500).withBody(`Value '0' for configuration property 'cpus' is invalid, reason: requires CPUs >= 4
+Value '0' for configuration property 'memory' is invalid, reason: requires memory in MiB >= 9216
+`),
+       },
 }
 
 var invalidHTTPMethods = []testCase{

cfergeau added a commit to cfergeau/crc that referenced this issue Jan 28, 2022
cfergeau added a commit to cfergeau/crc that referenced this issue Jan 28, 2022
The end goal is to return more meaningful error data in the HTTP
API rather than just strings:

[
   {
      "value":"memory",
      "default":"9216",
      "request":"6144",
      "reason":"invalid",
      "requires":">= 9216"
   },
   {
      "value":"disk-size",
      "default":"31",
      "request":"19",
      "reason":"invalid",
      "requires":">= 31"
   }
]

instead of

body: "Value '6144' for configuration property 'memory' is invalid, reason: requires memory in MiB >= 9216\n" +
    "Value '19' for configuration property 'disk-size' is invalid, reason: requires disk size in GiB >= 31\n"

See issue crc-org#2973
@cfergeau
Copy link
Contributor

I'd suggest improving the error types internally in crc so that we can serialize them to json in a more meaningful way. Rather than returning strings from validation functions, we could return more complex error types, which could be serialized to json in a more useful way.
Quick PoC at cfergeau@15639be but this does not even build. Quite a few functions to change/error types to add if we go this way.

@anjannath anjannath moved this to Todo in Project planning Feb 2, 2022
@gbraad
Copy link
Contributor Author

gbraad commented Feb 14, 2022

It might also help to describe the defaults in a better way from /api/config, as at the moment they had to be defined in the Configuration component of the client.

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status/stale Issue went stale; did not receive attention or no reply from the OP label Apr 16, 2022
@stale stale bot closed this as completed Apr 30, 2022
Repository owner moved this from Todo to Done in Project planning Apr 30, 2022
@anjannath anjannath reopened this May 2, 2022
@stale stale bot removed the status/stale Issue went stale; did not receive attention or no reply from the OP label May 2, 2022
@gbraad
Copy link
Contributor Author

gbraad commented Jun 7, 2022

@anjannath has this been resolved?

@gbraad gbraad moved this from Done to Todo in Project planning Jun 7, 2022
@stale
Copy link

stale bot commented Aug 12, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the status/stale Issue went stale; did not receive attention or no reply from the OP label Aug 12, 2022
@stale stale bot closed this as completed Sep 20, 2022
Repository owner moved this from Todo to Done in Project planning Sep 20, 2022
@praveenkumar praveenkumar reopened this Sep 21, 2022
@praveenkumar praveenkumar added status/pinned Prevents the stale bot from closing the issue and removed status/stale Issue went stale; did not receive attention or no reply from the OP labels Sep 21, 2022
@evidolob
Copy link
Contributor

@gbraad I think we could extend this issue to all API errors

For example now:
https://github.com/code-ready/crc/blob/0bad8c24d6d3e560ad530913f635b765d5ae97d9/pkg/crc/api/client/client.go#L188-L202

Just ignore any body text/json in error response.

So caller of sendGetRequest just receive error with Error occurred sending GET request to {API uri}: {statusCode}

So hawing some sort of unified way to send/handle errors from daemon API is a good enhancement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request priority/major status/pinned Prevents the stale bot from closing the issue
Projects
None yet
Development

No branches or pull requests

5 participants