Skip to content

Commit

Permalink
fix: improve error message for ListArchivedWorkflows (#7345)
Browse files Browse the repository at this point in the history
* fix: improve error message for ListArchivedWorkflows

Error message that is returned when user tries to list archived workflows and doesn't specify a namespace is very generic and hard to understand. This PR tries to make it a bit more clear as to what might be the cause of the issue, to help guide the user.

I thought that it might be a good idea to check if `namespace` is an empty string, and if it is, return a custom error for this case, telling user that `namespace` can't be empty. But I assume that this would not be correct for cases when Argo-Workflows runs with ClusterRole permissions?

Signed-off-by: Dominik Deren <dominik.deren@live.com>

* Fixing test & adding string formatting.

Signed-off-by: Dominik Deren <dominik.deren@live.com>
  • Loading branch information
domderen authored and sarabala1979 committed Dec 15, 2021
1 parent 5a472dd commit 3911d09
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/workflowarchive/archived_workflow_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (w *archivedWorkflowServer) ListArchivedWorkflows(ctx context.Context, req
return nil, err
}
if !allowed {
return nil, status.Error(codes.PermissionDenied, "permission denied")
return nil, status.Error(codes.PermissionDenied, fmt.Sprintf("Permission denied, you are not allowed to list workflows in namespace \"%s\". Maybe you want to specify a namespace with `listOptions.fieldSelector=metadata.namespace=your-ns`?", namespace))
}

// When the zero value is passed, we should treat this as returning all results
Expand Down
2 changes: 1 addition & 1 deletion server/workflowarchive/archived_workflow_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Test_archivedWorkflowServer(t *testing.T) {
t.Run("ListArchivedWorkflows", func(t *testing.T) {
allowed = false
_, err := w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{ListOptions: &metav1.ListOptions{Limit: 1}})
assert.Equal(t, err, status.Error(codes.PermissionDenied, "permission denied"))
assert.Equal(t, err, status.Error(codes.PermissionDenied, "Permission denied, you are not allowed to list workflows in namespace \"\". Maybe you want to specify a namespace with `listOptions.fieldSelector=metadata.namespace=your-ns`?"))
allowed = true
resp, err := w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{ListOptions: &metav1.ListOptions{Limit: 1}})
if assert.NoError(t, err) {
Expand Down

0 comments on commit 3911d09

Please sign in to comment.