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

Missing error handling in batch APIs #2210

Open
embano1 opened this issue Dec 15, 2020 · 5 comments
Open

Missing error handling in batch APIs #2210

embano1 opened this issue Dec 15, 2020 · 5 comments

Comments

@embano1
Copy link
Contributor

embano1 commented Dec 15, 2020

Currently only one VAPI batch operation is supported, i.e. attach-tag-to-multiple-objects. This VAPI operation returns a 200 even in case of partial tagging operation failures. This can lead to inconsistencies when assigning a tag to multiple objects, e.g. partial results. The caller is actually not aware of such an result because we don't inspect the response body (nil) from VAPI before returning:

return c.Do(ctx, url.Request(http.MethodPost, spec), nil)

This can (has?) lead to hidden bugs in production where individual failures go unnoticed. #2208 will fix this for the attach-multiple-tags-to-object action, but we should discuss first whether we break existing users of the call discussed in this issue when fixing the bug.

Related to this issue is that the VAPI simulator does not fully implement the vCenter VAPI behavior, e.g. missing validation for cardinality and missing object references, create tag by ID (URN), etc.

@github-actions
Copy link
Contributor

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.

@embano1
Copy link
Contributor Author

embano1 commented Mar 24, 2021

@dougm this might be a breaking change, not sure what you think about fixing this behavior?

@dougm
Copy link
Member

dougm commented Mar 24, 2021

@embano1 yes, I agree we should return the batch error from that method. Existing code should already check err != nil at least and the change won't break the method signature, so I think we're ok.

Improving the vcsim behavior would be great too.

@embano1
Copy link
Contributor Author

embano1 commented Mar 31, 2021

Existing code should already check err != nil at least

I don't think semantic (in response body) errors are surfaced by these methods currently:

		switch b := resBody.(type) {
		case io.Writer:
			_, err := io.Copy(b, res.Body)
			return err
		default:
			d := json.NewDecoder(res.Body)
			if isAPI(req.URL.Path) {
				// Responses from the /api endpoint are not wrapped
				return d.Decode(resBody)
			}
			// Responses from the /rest endpoint are wrapped in this structure
			val := struct {
				Value interface{} `json:"value,omitempty"`
			}{
				resBody,
			}
			return d.Decode(&val)
		}

func (c *Client) Do(ctx context.Context, req *http.Request, resBody interface{}) error {

That's why I think it would actually be a breaking change when we surface tagging specific errors into error.

@github-actions
Copy link
Contributor

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Mark as fresh by adding the comment /remove-lifecycle stale.

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

No branches or pull requests

2 participants