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

Introduce common cephError type to compare errors between packages #1032

Merged
merged 6 commits into from
Oct 14, 2024

Conversation

nixpanic
Copy link
Member

@nixpanic nixpanic commented Oct 2, 2024

A new internal/errutil.cephError can be used as a common type to replace all error types that are specific to the different packages (cephfsError, radosError, rbdError). By using the new cephError type everywhere, it becomes possible to match rados.ErrNotFound and rbd.ErrNotFound with the standard errors.Is() function.

Some go-ceph functions from the cephfs and rbd packages can return errors generated by the lower-level rados package. In such a case, a caller may need to check for e.g. rados.ErrNotFound as well as rbd.ErrNotFound, depending on the function that was called. This is prone to errors, as users of go-ceph may not inspect what the go-ceph function does and which error type it could return.

Closes: #1031

Checklist

  • Added tests for features and functional changes
  • Public functions and types are documented
  • 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 including the section on how we track API Status and the API Stability Plan.

The go-ceph project uses mergify. View the mergify command guide 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.

@nixpanic nixpanic requested review from ansiwen and anoopcs9 October 3, 2024 08:09
Copy link
Collaborator

@anoopcs9 anoopcs9 left a comment

Choose a reason for hiding this comment

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

Generally looks good to me.

Shouldn't we consider updating the API docs about those older implementations getting removed?

Copy link
Collaborator

@anoopcs9 anoopcs9 left a comment

Choose a reason for hiding this comment

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

We could also either:

  • rename and move internal/errors_test.go to internal/errutil/error_test.go
    OR
  • rename internal/errutil/error.go to internal/errutil/errors.go and move internal/errutil/errors_test.go to internal/errutil/errors_test.go

@nixpanic
Copy link
Member Author

nixpanic commented Oct 8, 2024

@anoopcs9 the file naming an location is actually intentional, because of two reasons:

  1. the tests do not really test the errutil package but users of the package,
  2. importing the rados package in the errutil package that gets imported by rados causes recursive imports (although that may be allowed for tests?)

If you insist on renaming/moving, I'll do that. Please state your preference in that case. Thanks!

@nixpanic
Copy link
Member Author

nixpanic commented Oct 8, 2024

Shouldn't we consider updating the API docs about those older implementations getting removed?

The implementation is an internal-only change. I do not expect any visible changes on the outside, all should be backwards compatible.

@anoopcs9
Copy link
Collaborator

anoopcs9 commented Oct 9, 2024

@anoopcs9 the file naming an location is actually intentional, because of two reasons:

  1. the tests do not really test the errutil package but users of the package,
  2. importing the rados package in the errutil package that gets imported by rados causes recursive imports (although that may be allowed for tests?)

In that case how about we rewrite errors_test.go in the direction of strerror_test.go and put in under internal/errutil?

Shouldn't we consider updating the API docs about those older implementations getting removed?

The implementation is an internal-only change. I do not expect any visible changes on the outside, all should be backwards compatible.

I agree but those APIs would still remain listed in docs/api-status.json.

@nixpanic
Copy link
Member Author

I agree but those APIs would still remain listed in docs/api-status.json.

oh, right, I see rbdError and so on there 🤔

@nixpanic
Copy link
Member Author

Hey @anoopcs9,

* rename and move _internal/errors_test.go_ to _internal/errutil/error_test.go_

Just to confirm, also tests may not do the 2-way imports:

# github.com/ceph/go-ceph/internal/errutil
package github.com/ceph/go-ceph/internal/errutil
	imports github.com/ceph/go-ceph/cephfs
	imports github.com/ceph/go-ceph/internal/errutil: import cycle not allowed in test
*** ERROR: returned 1
*** ERROR: internal/errutil tests failed

In that case how about we rewrite errors_test.go in the direction of strerror_test.go and put in under internal/errutil?

The main thing it tests is comparing errors between the rados, rbd and cephfs packages. Such a test needs to live outside of the internal/errutil package to prevent the import cycle.

Do you have an other idea where to place errors_test.go?

I agree but those APIs would still remain listed in docs/api-status.json.

The references to internal error types have been removed now.

@anoopcs9
Copy link
Collaborator

anoopcs9 commented Oct 10, 2024

Do you have an other idea where to place errors_test.go?

May be we choose option 1 to rename and move internal/errors_test.go to internal/errutil/error_test.go as follows:

package errutil

import (
	"errors"
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestCephError(t *testing.T) {
	errstr := cephErrno(107).Error()
	assert.Equal(t, "Transport endpoint is not connected", errstr)

	cephFSErr := GetError("cephfs", 2)
	assert.Equal(t, "cephfs: ret=2, No such file or directory",
		cephFSErr.Error())

	rbdErr := fmt.Errorf("RBD image not found: %w",
			GetError("rbd", 2))
	assert.True(t, errors.Is(cephFSErr, errors.Unwrap(rbdErr)))
}

I agree but those APIs would still remain listed in docs/api-status.json.

The references to internal error types have been removed now.

Are you sure you pushed those changes? I don't see any update here.

@phlogistonjohn
Copy link
Collaborator

Gentle reminder that the next release is on 2024-10-15. @anoopcs9 and @ansiwen please provide any feedback & @nixpanic check existing feedback please. If it misses the train, it misses the train (there will be another coming along later).

@anoopcs9 anoopcs9 self-requested a review October 14, 2024 05:38
@anoopcs9 anoopcs9 dismissed their stale review October 14, 2024 05:41

Updated with required changes.

Copy link
Member Author

@nixpanic nixpanic left a comment

Choose a reason for hiding this comment

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

Great, looks good to me 👍

Thanks for the changes!

@anoopcs9
Copy link
Collaborator

@Mergifyio rebase

Copy link

mergify bot commented Oct 14, 2024

rebase

✅ Branch has been successfully rebased

anoopcs9
anoopcs9 previously approved these changes Oct 14, 2024
Copy link
Collaborator

@anoopcs9 anoopcs9 left a comment

Choose a reason for hiding this comment

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

lgtm, thanks.

@anoopcs9
Copy link
Collaborator

I agree but those APIs would still remain listed in docs/api-status.json.

The references to internal error types have been removed now.

Are you sure you pushed those changes? I don't see any update here.

Oh..I totally forgot this afterwards. Do you want to take this final step?

@mergify mergify bot dismissed anoopcs9’s stale review October 14, 2024 14:57

Pull request has been modified.

@anoopcs9
Copy link
Collaborator

@Mergifyio rebase

nixpanic and others added 2 commits October 14, 2024 15:23
Signed-off-by: Niels de Vos <[email protected]>
Signed-off-by: Anoop C S <[email protected]>
Following APIs have been replaced with more generic cephError type to
jointly indicate the source and error.

cephFSError.Error
cephFSError.ErrorCode
radosError.Error
radosError.ErrorCode
rbdError.Error
rbdError.ErrorCode

Therefore remove corresponding entries from API docs.

Signed-off-by: Anoop C S <[email protected]>
Copy link

mergify bot commented Oct 14, 2024

rebase

✅ Branch has been successfully rebased

@anoopcs9 anoopcs9 added the no-API This PR does not include any changes to the public API of a go-ceph package label Oct 14, 2024
@mergify mergify bot merged commit 10ec360 into ceph:master Oct 14, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-API This PR does not include any changes to the public API of a go-ceph package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to match errors between rados and rbd package
3 participants