Skip to content

Commit 29e7c46

Browse files
committed
Address incorrect errors
1 parent 8134d1b commit 29e7c46

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

coderd/authzquery/authz.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func fetchWithPostFilter[ArgumentType any, ObjectType rbac.Objecter,
268268
// are predicated on the RBAC permissions of the related Template object.
269269
func queryWithRelated[ObjectType any, ArgumentType any, Related rbac.Objecter](
270270
// Arguments
271-
_ slog.Logger,
271+
logger slog.Logger,
272272
authorizer rbac.Authorizer,
273273
action rbac.Action,
274274
relatedFunc func(ObjectType, ArgumentType) (Related, error),
@@ -277,7 +277,7 @@ func queryWithRelated[ObjectType any, ArgumentType any, Related rbac.Objecter](
277277
// Fetch the rbac subject
278278
act, ok := ActorFromContext(ctx)
279279
if !ok {
280-
return empty, xerrors.Errorf("no authorization actor in context")
280+
return empty, NoActorError
281281
}
282282

283283
// Fetch the rbac object
@@ -295,7 +295,7 @@ func queryWithRelated[ObjectType any, ArgumentType any, Related rbac.Objecter](
295295
// Authorize the action
296296
err = authorizer.Authorize(ctx, act, action, rel.RBACObject())
297297
if err != nil {
298-
return empty, xerrors.Errorf("unauthorized: %w", err)
298+
return empty, LogNotAuthorizedError(ctx, logger, err)
299299
}
300300

301301
return obj, nil

coderd/authzquery/job.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (q *AuthzQuerier) GetProvisionerJobByID(ctx context.Context, id uuid.UUID)
100100
return database.ProvisionerJob{}, err
101101
}
102102
default:
103-
return database.ProvisionerJob{}, xerrors.Errorf("unknown job type: %q", job.Type)
103+
return database.ProvisionerJob{}, xerrors.Errorf("unknown job type: %q", job.Type)
104104
}
105105

106106
return job, nil

coderd/authzquery/workspace.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ func (q *AuthzQuerier) GetWorkspaceAgentsByResourceIDs(ctx context.Context, ids
8989
if err == nil {
9090
continue
9191
}
92-
if errors.Is(err, sql.ErrNoRows) {
92+
if errors.Is(err, sql.ErrNoRows) && !errors.As(err, &NotAuthorizedError{}) {
9393
// The agent is not tied to a workspace, likely from an orphaned template version.
9494
// Just return it.
9595
continue
9696
}
9797
// Otherwise, we cannot read the workspace, so we cannot read the agent.
98-
return nil, err
98+
return nil, LogNotAuthorizedError(ctx, q.log, err)
9999
}
100100
return agents, nil
101101
}
@@ -221,15 +221,15 @@ func (q *AuthzQuerier) GetWorkspaceResourceByID(ctx context.Context, id uuid.UUI
221221

222222
build, err := q.db.GetWorkspaceBuildByJobID(ctx, resource.JobID)
223223
if err != nil {
224-
return database.WorkspaceResource{}, nil
224+
return database.WorkspaceResource{}, err
225225
}
226226

227227
// If the workspace can be read, then the resource can be read.
228228
_, err = fetch(q.log, q.auth, q.db.GetWorkspaceByID)(ctx, build.WorkspaceID)
229229
if err != nil {
230-
return database.WorkspaceResource{}, nil
230+
return database.WorkspaceResource{}, err
231231
}
232-
return resource, err
232+
return resource, nil
233233
}
234234

235235
// GetWorkspaceResourceMetadataByResourceIDs is an all or nothing call. If a single resource is not authorized, then

0 commit comments

Comments
 (0)