Wrap some errors with InvalidArgument status in apemanager service #1651

Merged
fyrchik merged 1 commit from aarifullin/frostfs-node:feat/improve_apemngr_errors into master 2025-02-27 18:25:10 +00:00
Member

ErrAPEManagerInvalidArgument has been introduced for ape-manager service

`ErrAPEManagerInvalidArgument` has been introduced for ape-manager service
aarifullin added 1 commit 2025-02-20 14:51:39 +00:00
[#xx] apemanager: Wrap some errors with InvalidArgument status
Some checks failed
DCO action / DCO (pull_request) Failing after 37s
Tests and linters / Run gofumpt (pull_request) Successful in 51s
Vulncheck / Vulncheck (pull_request) Failing after 1m8s
Build / Build Components (pull_request) Successful in 2m1s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m22s
Tests and linters / Staticcheck (pull_request) Successful in 2m48s
Tests and linters / Tests (pull_request) Successful in 2m29s
Tests and linters / Tests with -race (pull_request) Successful in 3m18s
Tests and linters / gopls check (pull_request) Successful in 3m25s
Tests and linters / Lint (pull_request) Successful in 3m49s
aea6f53edf
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
requested reviews from storage-core-committers, storage-core-developers 2025-02-20 14:51:39 +00:00
aarifullin force-pushed feat/improve_apemngr_errors from aea6f53edf to 1884ba4ce8 2025-02-20 14:52:17 +00:00 Compare
achuprov approved these changes 2025-02-20 15:22:43 +00:00
Dismissed
dstepanov-yadro reviewed 2025-02-21 06:40:36 +00:00
@ -10,2 +10,4 @@
return err
}
func ErrAPEManagerInvalidArgument(msg string) error {

Please write down the motivation for this change. In particular, I am interested in using status.Error(codes.InvalidArgument...) vs apemanager_errors.ErrAPEManagerInvalidArgument

Please write down the motivation for this change. In particular, I am interested in using `status.Error(codes.InvalidArgument...)` vs `apemanager_errors.ErrAPEManagerInvalidArgument`
Author
Member

status.Error(codes.InvalidArgument...) - probably, you're talking about the status from grpc-package (used in control services).
ErrAPEManagerInvalidArgument wraps into frostfs-api status

`status.Error(codes.InvalidArgument...)` - probably, you're talking about the status from `grpc`-package (used in control services). `ErrAPEManagerInvalidArgument` wraps into frostfs-api status

Got it, thanks

Got it, thanks
dstepanov-yadro marked this conversation as resolved
dstepanov-yadro approved these changes 2025-02-21 11:46:29 +00:00
Dismissed
acid-ant approved these changes 2025-02-21 13:21:29 +00:00
Dismissed
elebedeva approved these changes 2025-02-24 07:43:49 +00:00
Dismissed
fyrchik reviewed 2025-02-26 12:25:28 +00:00
@ -82,3 +82,3 @@
var cidSDK cidSDK.ID
if err := cidSDK.DecodeString(cid); err != nil {
return fmt.Errorf("invalid CID format: %w", err)
err = fmt.Errorf("invalid CID format: %w", err)
Owner

fmt.Errorf("... %w", err).Error() is equivalent to fmt.Sprintf("... %v", err)
bdcd6d1b65/src/fmt/print.go (L1063)
bdcd6d1b65/src/fmt/errors.go (L31)

For %s it is even easier.

`fmt.Errorf("... %w", err).Error()` is equivalent to `fmt.Sprintf("... %v", err)` https://github.com/golang/go/blob/bdcd6d1b653dd7a5b3eb9a053623f85433ff9e6b/src/fmt/print.go#L1063 https://github.com/golang/go/blob/bdcd6d1b653dd7a5b3eb9a053623f85433ff9e6b/src/fmt/errors.go#L31 For `%s` it is even easier.
Author
Member

fixed to %s

fixed to `%s`
Owner

That is not what I wanted to say:

err = fmt.Errorf("...: %w", err)
return apemanager_errors.ErrAPEManagerInvalidArgument(err.Error())

is equivalent to

return apemanager_errors.ErrAPEManagerInvalidArgument(fmt.Sprintf("...: %v", err))

So no intermediate error (via fmt.Errorf) is needed.
The same could be done in multiple other places in this PR

That is not what I wanted to say: ```go err = fmt.Errorf("...: %w", err) return apemanager_errors.ErrAPEManagerInvalidArgument(err.Error()) ``` is equivalent to ```go return apemanager_errors.ErrAPEManagerInvalidArgument(fmt.Sprintf("...: %v", err)) ``` So no intermediate error (via `fmt.Errorf`) is needed. The same could be done in multiple other places in this PR
Author
Member

Ah. Okay. Fixed

Ah. Okay. Fixed
fyrchik marked this conversation as resolved
aarifullin force-pushed feat/improve_apemngr_errors from 1884ba4ce8 to 6c38deb36b 2025-02-27 08:49:02 +00:00 Compare
aarifullin dismissed achuprov's review 2025-02-27 08:49:03 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

aarifullin dismissed dstepanov-yadro's review 2025-02-27 08:49:03 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

aarifullin dismissed acid-ant's review 2025-02-27 08:49:03 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

aarifullin dismissed elebedeva's review 2025-02-27 08:49:03 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

requested reviews from storage-core-committers, storage-core-developers 2025-02-27 08:49:24 +00:00
aarifullin force-pushed feat/improve_apemngr_errors from 6c38deb36b to e65d8666c7 2025-02-27 14:32:44 +00:00 Compare
fyrchik approved these changes 2025-02-27 14:56:50 +00:00
@ -194,3 +194,3 @@
target = policy_engine.ContainerTarget(reqCID)
default:
return nil, fmt.Errorf("unsupported target type: %s", targetType)
return nil, apemanager_errors.ErrAPEManagerInvalidArgument(fmt.Sprintf("unsupported target type: %s", targetType))
Owner

4 lines above we also return an error, but do not wrap it, why?

4 lines above we also return an error, but do not wrap it, why?
Author
Member

validateContainerTargetRequest?

You can see it already wraps errors within

// validateContainerTargetRequest validates request for the container target.
// It checks if request actor is the owner of the container, otherwise it denies the request.
func (s *Service) validateContainerTargetRequest(ctx context.Context, cid string, pubKey *keys.PublicKey) error {
	var cidSDK cidSDK.ID
	if err := cidSDK.DecodeString(cid); err != nil {
		return apemanager_errors.ErrAPEManagerInvalidArgument(fmt.Sprintf("invalid CID format: %v", err))
	}
	isOwner, err := s.isActorContainerOwner(ctx, cidSDK, pubKey)
	if err != nil {
		return fmt.Errorf("failed to check owner: %w", err)
	}
	if !isOwner {
		return apemanager_errors.ErrAPEManagerAccessDenied("actor must be container owner")
	}
	return nil
}

I know this is not a good approach when you wrap errors within call. But

  1. validateContainerTargetRequest is the internal method used only in ape-manager anyway
  2. If we need to wrap outside, then I need to introduce new error types to return them from invocation. Then categorize them outside of invocation to select proper wrapper ErrAPEManagerInvalidArgument and ErrAPEManagerAccessDenied

In this case I suppose it's not worth it

`validateContainerTargetRequest`? You can see it already wraps errors within ```go // validateContainerTargetRequest validates request for the container target. // It checks if request actor is the owner of the container, otherwise it denies the request. func (s *Service) validateContainerTargetRequest(ctx context.Context, cid string, pubKey *keys.PublicKey) error { var cidSDK cidSDK.ID if err := cidSDK.DecodeString(cid); err != nil { return apemanager_errors.ErrAPEManagerInvalidArgument(fmt.Sprintf("invalid CID format: %v", err)) } isOwner, err := s.isActorContainerOwner(ctx, cidSDK, pubKey) if err != nil { return fmt.Errorf("failed to check owner: %w", err) } if !isOwner { return apemanager_errors.ErrAPEManagerAccessDenied("actor must be container owner") } return nil } ``` I know this is not a good approach when you wrap errors within call. But 1. `validateContainerTargetRequest` is the internal method used only in ape-manager anyway 2. If we need to wrap outside, then I need to introduce new error types to return them from invocation. Then categorize them outside of invocation to select proper wrapper `ErrAPEManagerInvalidArgument` and `ErrAPEManagerAccessDenied` In this case I suppose it's not worth it
fyrchik merged commit 9a0507704a into master 2025-02-27 18:25:10 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
6 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#1651
No description provided.