cloudfoundry / cli

The official command line client for Cloud Foundry
https://docs.cloudfoundry.org/cf-cli
Apache License 2.0
1.75k stars 929 forks source link

CLI only prints first error when v3 job returns multiple errors #1442

Closed jenspinney closed 1 month ago

jenspinney commented 6 years ago

The job resource in the v3 CC API can contain multiple errors if there are multiple errors to report. However, the CLI only presents the first error to the user.

Command

This would appear in any command that ultimatey uses the "PollJob" function in ccv3 api client. For example, this will repro with cf v3-delete and probably several other v3- commands.

What occurred

If the CC returns multiple errors in the job description, only the first error will be reported by the CLI.

This is because of this line: https://github.com/cloudfoundry/cli/blob/cd80be90e462c7bd653a74f6ac0659474e18b477/api/cloudcontroller/ccv3/job.go#L79

What you expected to occur

A list of errors to be displayed that match the errors from the CC.

CLI Version

Current master branch, which happens to be SHA cd80be90e462c7bd653a74f6ac0659474e18b477. CLI version is 6.38.0.

CC API Endpoint Version

3.x

Any other relevant information

A user being able to see multiple errors is particularly important for cases where the user is trying to delete a resource which has subresources that failed to delete. If the user can't see all the errors at once, they end up playing whack a mole with the errors, since they can only see and fix one at a time.

cf-gitbot commented 6 years ago

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/159963543

The labels on this github issue will be updated when the story is started.

abbyachau commented 6 years ago

Hey @jenspinney thanks for creating this. Could you provide steps on how to reproduce this? Thanks.

ablease commented 6 years ago

Hey @abbyachau We have some work which, we will be creating a PR into CC soon, which we think will be effected by this. That work can be found here

In summary, this change allows a request which deletes an app via the v3 api, will cause the delayed job to return multiple errors. As Jen mentioned, it looks like the current cli code for polling delayed jobs only catches the first error returned by that job.

We could provide repro steps when this work gets merged.

abbyachau commented 6 years ago

Hi @jenspinney thanks for creating this issue. I'm closing this issue as it's not actionable for us at the moment. Please when you create the pr, could you reference this issue and/or create a new issue. Thanks.

jenspinney commented 6 years ago

Repro Steps

Using CAPI 1.68

Assuming you have some app you can push (using 'dora' here, but it can be anything) And assuming you have a service broker that supports async operations (using overview-broker in these steps)

  1. cf push dora
  2. cf cs overview-broker simple s1 (wait for creation to complete)
  3. cf cs overview-broker simple s2 (wait for creation to complete)
  4. cf bs dora s1 (wait for binding to complete)
  5. cf bs dora s2 (wait for binding to complete)
  6. cf v3-delete dora -v -f

In that last command, you can see that the CC responds with 2 error messages, but the CLI only prints the first one.

For example, this is what we see:

REQUEST: [2018-09-12T17:23:25+02:00]
GET /v3/jobs/4991d854-0f68-4003-94f8-49f54c99e963 HTTP/1.1
Host: api.button-taker.sapi.cf-app.com
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
User-Agent: cf/6.39.0+607d4f8be.2018-09-11 (go1.10.3; amd64 darwin)

RESPONSE: [2018-09-12T17:23:25+02:00]
HTTP/1.1 200 OK
Content-Length: 836
Content-Type: application/json; charset=utf-8
Date: Wed, 12 Sep 2018 15:23:25 GMT
Server: nginx
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Runtime: 0.003862
X-Vcap-Request-Id: 1984ded8-f6fd-4056-4222-f7456aa1941d::904185ec-f122-424a-a405-6d2df1c66f71
X-Xss-Protection: 1; mode=block
{
  "created_at": "2018-09-12T15:23:19Z",
  "errors": [
    {
      "code": 10008,
      "detail": "An operation for the service binding between app dora and service instance s1 is in progress.",
      "title": "CF-UnprocessableEntity"
    },
    {
      "code": 10008,
      "detail": "An operation for the service binding between app dora and service instance s2 is in progress.",
      "title": "CF-UnprocessableEntity"
    }
  ],
  "guid": "4991d854-0f68-4003-94f8-49f54c99e963",
  "links": {
    "app": {
      "href": "https://api.button-taker.sapi.cf-app.com/v3/apps/3aa7df1f-3122-4de8-a928-c68513046149"
    },
    "self": {
      "href": "https://api.button-taker.sapi.cf-app.com/v3/jobs/4991d854-0f68-4003-94f8-49f54c99e963"
    }
  },
  "operation": "app.delete",
  "state": "FAILED",
  "updated_at": "2018-09-12T15:23:19Z"
}

Job (4991d854-0f68-4003-94f8-49f54c99e963) failed: An operation for the service binding between app dora and service instance s1 is in progress.
FAILED

There might be easier ways to repro this, but this is the one we're familiar with. A simpler way to repro might be to just modify the response from the CC API for any call to the v3 jobs endpoint and add a second error.

cf-gitbot commented 6 years ago

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/160454522

The labels on this github issue will be updated when the story is started.

jenspinney commented 6 years ago

@abbyachau Hey Abby, sorry I misread your comment above and thought you said to reopen, but I see now you just said to make a new issue. It might be useful to have the full explanation in one place, so I'm going to leave this open instead of creating a second issue if that's alright.

abbyachau commented 6 years ago

Hey @jenspinney np at all. Thanks for reopening this again. Could you pls remind whether this is only an issue v3 CLI commands?

jenspinney commented 6 years ago

Yes, this should only commands that use the V3 API.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed.

joaopapereira commented 1 month ago

Thank you for your submission. If you still run into this issue with the latest CLI v8, please open a new ticket with the necessary information mentioned in our issue template.