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

Refactoring + error handling fixes #159

Merged
merged 9 commits into from
Nov 6, 2024
Merged

Conversation

jmigueprieto
Copy link
Contributor

@jmigueprieto jmigueprieto commented Nov 5, 2024

Follow up of #157

Changes in this PR

  1. Refactored http status code checking logic and fixed error handling in clients.
  2. Removed dead code.
  3. Fixes in executor + executor tests.
  4. Fixed tests.
  5. Fixed UserClient.GetGrantedPermissions() implementation.

For more details take a look at the comments.

TODO: More testing (in a next PR)

@jmigueprieto jmigueprieto self-assigned this Nov 5, 2024
err = decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"))
if err == nil {
return localVarReturnValue, localVarHttpResponse, err
}
}
if localVarHttpResponse.StatusCode >= 300 {
newErr := fmt.Errorf(string(localVarBody))
if localVarHttpResponse.StatusCode == 200 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more dead code

assert.Fail(t, "err is not of type GenericSwaggerError")
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some tests to check executor error responses

@@ -426,7 +427,10 @@ func (e *WorkflowExecutor) UpdateTask(taskId string, workflowInstanceId string,
return err
}
taskResult.Status = status
e.taskClient.UpdateTask(context.Background(), taskResult)
_, _, err = e.taskClient.UpdateTask(context.Background(), taskResult)
if err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

executor.UpdateTask was not handling errors properly

context.Background(),
overwrite,
*workflow,
)
if err != nil {
return err
}
if response.StatusCode > 299 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks after

if err != nil {
	return err
}

don't make sense. err is going to be not nil and this line won't be reached.

@jmigueprieto jmigueprieto force-pushed the fix/improve-error-handling branch from 1c79d79 to e25db64 Compare November 6, 2024 00:45
if err != nil {
return err
}
if response.StatusCode != 200 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unreachable code

)

type UserClient interface {
CheckPermissions(ctx context.Context, userId string, type_ string, id string) (map[string]interface{}, *http.Response, error)
DeleteUser(ctx context.Context, id string) (*http.Response, error)
GetGrantedPermissions(ctx context.Context, userId string) ([]rbac.GrantedAccess, *http.Response, error)
GetGrantedPermissions(ctx context.Context, userId string) (rbac.GrantedAccessResponse, *http.Response, error)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type was wrong. Because of buggy error handling this was not caught by the tests before

@@ -33,7 +33,7 @@ func TestDeleteEnvVariable(t *testing.T) {
message, resp, err := envClient.DeleteEnvVariable(ctx, "testKey")
assert.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, "", message)
assert.Equal(t, "test value", message)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"test value" should have been the expected value of the test.

But, the backend is returning the environment variable value when deleting as string but the content-type is application/json

@jmigueprieto jmigueprieto marked this pull request as ready for review November 6, 2024 01:24
@jmigueprieto jmigueprieto requested review from v1r3n, c4lm and a team November 6, 2024 01:24
@jmigueprieto jmigueprieto changed the title (WIP) Fix error handling Refactoring + error handling fixes Nov 6, 2024
@jmigueprieto jmigueprieto force-pushed the fix/improve-error-handling branch from 7bf109d to 365e1a6 Compare November 6, 2024 01:29
@jmigueprieto jmigueprieto merged commit fe8fd81 into main Nov 6, 2024
3 checks passed
@jmigueprieto jmigueprieto deleted the fix/improve-error-handling branch November 6, 2024 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants