Repository: ceph/go-ceph
Pull request #998 (2024-06-13 09:54:16)

rgw/admin: Add ErrNoSuchSubUser
<!--
Thank you for opening a pull request. Please provide:

- A clear summary of your changes

- Descriptive and succinct commit messages with the format:
  """
  [topic]: [short description]

  [Longer description]

  Signed-off-by: [Your Name] <[your email]>
  """

  Topic will generally be the go ceph package dir you are working in.

- Ensure checklist items listed below are accounted for
-->

There was no Error for comparing the `NoSuchSubUser` code.

Example error: 

```
error(github.com/ceph/go-ceph/rgw/admin.statusError) {Code: "NoSuchSubUser", RequestID: "tx0000074e0db2ad9281b8f-00666abc30-10b8-dev1", HostID: "10b8-dev1-dev"}
```

Reference:

https://github.com/ceph/ceph/blob/8a2a786e62ba1577dde990fef49d18f75efdd023/src/rgw/rgw_common.cc#L106C1-L106C52

## Checklist
- [ ] Added tests for features and functional changes
- [ ] Public functions and types are documented
- [x] Standard formatting is applied to Go code
- [ ] Is this a new API? Added a new file that begins with `//go:build ceph_preview`
- [ ] Ran `make api-update` to record new APIs

New or infrequent contributors may want to review the go-ceph [Developer's Guide](https://github.com/ceph/go-ceph/blob/master/docs/development.md) including the section on how we track [API Status](https://github.com/ceph/go-ceph/blob/master/docs/development.md#api-status) and the [API Stability Plan](https://github.com/ceph/go-ceph/blob/master/docs/api-stability.md).

The go-ceph project uses mergify. View the [mergify command guide](https://docs.mergify.com/commands/#commands) for information on how to interact with mergify. Add a comment with `@Mergifyio` `rebase` to rebase your PR when github indicates that the PR is out of date with the base branch.


sj14: Added. Unfortunately, I can't test it even though `ceph-client` is installed via homebrew:

```
# github.com/ceph/go-ceph/rados
some/path/go-ceph/rados/alloc_hint_flags.go:4:11: fatal error: 'rados/librados.h' file not found
 #include <rados/librados.h>
          ^~~~~~~~~~~~~~~~~~
1 error generated.
FAIL	github.com/ceph/go-ceph/rgw/admin [build failed]
```

Patch:
diff --git a/rgw/admin/errors.go b/rgw/admin/errors.go
index 332d779..6f63e2c 100644
--- a/rgw/admin/errors.go
+++ b/rgw/admin/errors.go
@@ -10,7 +10,7 @@ const (
 	// ErrUserExists - Attempt to create existing user
 	ErrUserExists errorReason = "UserAlreadyExists"
 
-	// ErrNoSuchUser - Attempt to create existing user
+	// ErrNoSuchUser - User does not exist
 	ErrNoSuchUser errorReason = "NoSuchUser"
 
 	// ErrInvalidAccessKey - Invalid access key specified
@@ -34,6 +34,9 @@ const (
 	// ErrSubuserExists - Specified subuser exists
 	ErrSubuserExists errorReason = "SubuserExists"
 
+	// ErrNoSuchSubUser - SubUser does not exist
+	ErrNoSuchSubUser errorReason = "NoSuchSubUser"
+
 	// ErrInvalidAccess - Invalid subuser access specified
 	ErrInvalidAccess errorReason = "InvalidAccess"
 


Test patch:
diff --git a/rgw/admin/errors_test.go b/rgw/admin/errors_test.go
index 8dabe0e..c3a1bf9 100644
--- a/rgw/admin/errors_test.go
+++ b/rgw/admin/errors_test.go
@@ -8,11 +8,16 @@ import (
 )
 
 var (
-	fakeGetUserError = []byte(`{"Code":"NoSuchUser","RequestId":"tx0000000000000000005a9-00608957a2-10496-my-store","HostId":"10496-my-store-my-store"}`)
+	fakeGetUserError    = []byte(`{"Code":"NoSuchUser","RequestId":"tx0000000000000000005a9-00608957a2-10496-my-store","HostId":"10496-my-store-my-store"}`)
+	fakeGetSubUserError = []byte(`{"Code":"NoSuchSubUser","RequestId":"tx0000000000000000005a9-00608957a2-10496-my-store","HostId":"10496-my-store-my-store"}`)
 )
 
 func TestHandleStatusError(t *testing.T) {
 	err := handleStatusError(fakeGetUserError)
 	assert.Error(t, err)
 	assert.True(t, errors.Is(err, ErrNoSuchUser), err)
+
+	err = handleStatusError(fakeGetSubUserError)
+	assert.Error(t, err)
+	assert.True(t, errors.Is(err, ErrNoSuchSubUser), err)
 }