From 5adb04909dedb8398f54c94d4a943a51b76d1d6b Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 28 Jan 2020 16:00:52 +0100 Subject: [PATCH] rados: standardize error naming RadosError-prefixes are not recommended, instead just Err as prefix is used. Also, errors are constants, not variables. For existing users, backwards compatible constants are available. These will need to be removed in a future go-ceph release. Signed-off-by: Niels de Vos --- rados/ioctx.go | 2 +- rados/rados.go | 31 ++++++++++++++++++++++++------- rados/rados_test.go | 18 +++++++++--------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/rados/ioctx.go b/rados/ioctx.go index 903ebf8..e5b9ada 100644 --- a/rados/ioctx.go +++ b/rados/ioctx.go @@ -686,7 +686,7 @@ func (iter *Iter) Namespace() string { // Err checks whether the iterator has encountered an error. func (iter *Iter) Err() error { - if iter.err == RadosErrorNotFound { + if iter.err == ErrNotFound { return nil } return iter.err diff --git a/rados/rados.go b/rados/rados.go index 686cc88..2e4a487 100644 --- a/rados/rados.go +++ b/rados/rados.go @@ -26,16 +26,33 @@ func (e RadosError) Error() string { return fmt.Sprintf("rados: ret=%d, %s", errno, s) } -var ( - // RadosAllNamespaces is used to reset a selected namespace to all namespaces. See the IOContext SetNamespace function. - RadosAllNamespaces = C.LIBRADOS_ALL_NSPACES +const ( + // AllNamespaces is used to reset a selected namespace to all + // namespaces. See the IOContext SetNamespace function. + AllNamespaces = C.LIBRADOS_ALL_NSPACES - // RadosErrorNotFound indicates a missing resource. - RadosErrorNotFound = RadosError(-C.ENOENT) - // RadosErrorPermissionDenied indicates a permissions issue. - RadosErrorPermissionDenied = RadosError(-C.EPERM) + // ErrNotFound indicates a missing resource. + ErrNotFound = RadosError(-C.ENOENT) + // ErrPermissionDenied indicates a permissions issue. + ErrPermissionDenied = RadosError(-C.EPERM) // ErrObjectExists indicates that an exclusive object creation failed. ErrObjectExists = RadosError(-C.EEXIST) + + // FIXME: for backwards compatibility + + // RadosAllNamespaces is used to reset a selected namespace to all + // namespaces. See the IOContext SetNamespace function. + // + // Deprecated: use AllNamespaces instead + RadosAllNamespaces = AllNamespaces + // RadosErrorNotFound indicates a missing resource. + // + // Deprecated: use ErrNotFound instead + RadosErrorNotFound = ErrNotFound + // RadosErrorPermissionDenied indicates a permissions issue. + // + // Deprecated: use ErrPermissionDenied instead + RadosErrorPermissionDenied = ErrPermissionDenied ) func getRadosError(err int) error { diff --git a/rados/rados_test.go b/rados/rados_test.go index f4c1971..9af6afa 100644 --- a/rados/rados_test.go +++ b/rados/rados_test.go @@ -514,7 +514,7 @@ func (suite *RadosTestSuite) TestReadNotFound() { var bytes []byte oid := suite.GenObjectName() _, err := suite.ioctx.Read(oid, bytes, 0) - assert.Equal(suite.T(), err, RadosErrorNotFound) + assert.Equal(suite.T(), err, ErrNotFound) } func (suite *RadosTestSuite) TestDeleteNotFound() { @@ -522,7 +522,7 @@ func (suite *RadosTestSuite) TestDeleteNotFound() { oid := suite.GenObjectName() err := suite.ioctx.Delete(oid) - assert.Equal(suite.T(), err, RadosErrorNotFound) + assert.Equal(suite.T(), err, ErrNotFound) } func (suite *RadosTestSuite) TestStatNotFound() { @@ -530,7 +530,7 @@ func (suite *RadosTestSuite) TestStatNotFound() { oid := suite.GenObjectName() _, err := suite.ioctx.Stat(oid) - assert.Equal(suite.T(), err, RadosErrorNotFound) + assert.Equal(suite.T(), err, ErrNotFound) } func (suite *RadosTestSuite) TestObjectStat() { @@ -763,7 +763,7 @@ func (suite *RadosTestSuite) TestObjectIteratorAcrossNamespaces() { objectListNS2 := []string{} // populate list of current objects - suite.ioctx.SetNamespace(RadosAllNamespaces) + suite.ioctx.SetNamespace(AllNamespaces) existingList := []string{} iter, err := suite.ioctx.Iter() assert.NoError(suite.T(), err) @@ -796,7 +796,7 @@ func (suite *RadosTestSuite) TestObjectIteratorAcrossNamespaces() { } assert.True(suite.T(), len(createdList) == 20) - suite.ioctx.SetNamespace(RadosAllNamespaces) + suite.ioctx.SetNamespace(AllNamespaces) iter, err = suite.ioctx.Iter() assert.NoError(suite.T(), err) rogueList := []string{} @@ -1033,7 +1033,7 @@ func (suite *RadosTestSuite) TestSetNamespace() { // oid isn't seen in space1 ns suite.ioctx.SetNamespace("space1") stat, err = suite.ioctx.Stat(oid) - assert.Equal(suite.T(), err, RadosErrorNotFound) + assert.Equal(suite.T(), err, ErrNotFound) // create oid2 in space1 ns oid2 := suite.GenObjectName() @@ -1043,7 +1043,7 @@ func (suite *RadosTestSuite) TestSetNamespace() { suite.ioctx.SetNamespace("") stat, err = suite.ioctx.Stat(oid2) - assert.Equal(suite.T(), err, RadosErrorNotFound) + assert.Equal(suite.T(), err, ErrNotFound) stat, err = suite.ioctx.Stat(oid) assert.Equal(suite.T(), uint64(len(bytes_in)), stat.Size) @@ -1081,7 +1081,7 @@ func (suite *RadosTestSuite) TestListAcrossNamespaces() { assert.EqualValues(suite.T(), 1, nsFoundObjects) // count objects in pool - suite.ioctx.SetNamespace(RadosAllNamespaces) + suite.ioctx.SetNamespace(AllNamespaces) allFoundObjects := 0 err = suite.ioctx.ListObjects(func(oid string) { allFoundObjects++ @@ -1184,7 +1184,7 @@ func (suite *RadosTestSuite) TestOmapOnNonexistentObjectError() { suite.SetupConnection() oid := suite.GenObjectName() _, err := suite.ioctx.GetAllOmapValues(oid, "", "", 100) - assert.Equal(suite.T(), err, RadosErrorNotFound) + assert.Equal(suite.T(), err, ErrNotFound) } func (suite *RadosTestSuite) TestOpenIOContextInvalidPool() {