From 984ba515877df727a0f3684c73e012c154c0bce1 Mon Sep 17 00:00:00 2001 From: Nicolas JUHEL Date: Fri, 25 Aug 2023 15:48:35 +0200 Subject: [PATCH] Rework Error interface Package Errors: - add function to check & cast error interface into golib Error interface - update CodeError type to simplify management & error creation - add function to simplify call of Error function from a generic error interface - remove some useless function from Error interface All Other Packages: - apply change of package Errors into all other packages --- archive/archive.go | 36 +-- archive/bz2/reader.go | 8 +- archive/gzip/reader.go | 10 +- archive/gzip/writer.go | 14 +- archive/tar/reader.go | 38 +-- archive/tar/writer.go | 16 +- archive/zip/reader.go | 40 +-- archive/zip/writer.go | 12 +- artifact/artifact.go | 8 +- artifact/client/interface.go | 13 +- artifact/client/model.go | 17 +- artifact/github/github.go | 5 +- artifact/github/model.go | 27 +- artifact/gitlab/gitlab.go | 17 +- artifact/gitlab/model.go | 27 +- artifact/jfrog/artifactory.go | 5 +- artifact/jfrog/model.go | 47 ++- artifact/s3aws/model.go | 49 ++-- artifact/s3aws/s3aws.go | 5 +- aws/bucket/acl.go | 23 +- aws/bucket/bucket.go | 19 +- aws/bucket/cors.go | 5 +- aws/bucket/interface.go | 49 ++-- aws/bucket/lifecycle.go | 17 +- aws/bucket/replication.go | 7 +- aws/bucket/version.go | 5 +- aws/bucket/website.go | 5 +- aws/configAws/interface.go | 13 +- aws/configAws/models.go | 26 +- aws/configCustom/interface.go | 11 +- aws/configCustom/models.go | 37 ++- aws/group/group.go | 21 +- aws/group/interface.go | 27 +- aws/group/policy.go | 13 +- aws/group/user.go | 33 +-- aws/helper/error.go | 6 - aws/helper/interface.go | 23 +- aws/interface.go | 21 +- aws/model.go | 17 +- aws/object/find.go | 4 +- aws/object/interface.go | 69 +++-- aws/object/lifecycle.go | 9 +- aws/object/multipart.go | 9 +- aws/object/object.go | 25 +- aws/object/tags.go | 5 +- aws/object/version.go | 17 +- aws/object/website.go | 5 +- aws/policy/interface.go | 21 +- aws/policy/policies.go | 13 +- aws/policy/versions.go | 13 +- aws/role/interface.go | 21 +- aws/role/policy.go | 13 +- aws/role/role.go | 31 +- aws/user/access.go | 9 +- aws/user/interface.go | 35 ++- aws/user/login.go | 29 +- aws/user/policy.go | 13 +- aws/user/user.go | 35 ++- certificates/config.go | 4 +- certificates/model.go | 8 +- cluster/async.go | 8 +- cluster/cluster.go | 22 +- cluster/config.go | 4 +- cluster/configCluster.go | 4 +- cluster/configEngine.go | 4 +- cluster/configExpert.go | 4 +- cluster/configGossip.go | 4 +- cluster/configNode.go | 4 +- cluster/interface.go | 2 +- cluster/local.go | 4 +- cluster/sync.go | 22 +- config/components.go | 15 +- config/components/aws/client.go | 23 +- config/components/aws/component.go | 7 +- config/components/aws/config.go | 21 +- config/components/aws/driver.go | 7 +- config/components/aws/interface.go | 3 +- config/components/aws/model.go | 3 +- config/components/database/client.go | 11 +- config/components/database/component.go | 7 +- config/components/database/config.go | 7 +- config/components/head/client.go | 7 +- config/components/head/component.go | 7 +- config/components/head/config.go | 7 +- config/components/http/client.go | 15 +- config/components/http/component.go | 7 +- config/components/http/config.go | 11 +- config/components/http/monitor.go | 8 +- config/components/ldap/client.go | 11 +- config/components/ldap/component.go | 7 +- config/components/ldap/config.go | 7 +- config/components/log/client.go | 11 +- config/components/log/component.go | 7 +- config/components/log/config.go | 7 +- config/components/log/interface.go | 3 +- config/components/log/model.go | 5 +- config/components/mail/client.go | 9 +- config/components/mail/component.go | 7 +- config/components/mail/config.go | 7 +- config/components/mail/interface.go | 3 +- config/components/mail/model.go | 3 +- config/components/request/client.go | 15 +- config/components/request/component.go | 7 +- config/components/request/config.go | 7 +- config/components/smtp/client.go | 11 +- config/components/smtp/component.go | 7 +- config/components/smtp/config.go | 7 +- config/components/smtp/interface.go | 3 +- config/components/smtp/model.go | 3 +- config/components/tls/client.go | 9 +- config/components/tls/component.go | 7 +- config/components/tls/config.go | 7 +- config/events.go | 6 +- config/interface.go | 7 +- config/manage.go | 13 +- config/model.go | 5 +- config/types/component.go | 9 +- config/types/componentList.go | 5 +- console/color.go | 4 +- crypt/crypt.go | 20 +- database/gorm/config.go | 8 +- database/gorm/model.go | 4 +- errors/code.go | 18 +- errors/errors.go | 374 ++++++++++++------------ errors/mode.go | 17 +- file/progress/model.go | 2 +- ftpclient/config.go | 8 +- ftpclient/model.go | 38 +-- httpcli/cli.go | 2 +- httpcli/options.go | 4 +- httpserver/config.go | 8 +- httpserver/pool/config.go | 4 +- httpserver/pool/model.go | 2 +- httpserver/pool/server.go | 6 +- httpserver/run.go | 4 +- httpserver/server.go | 2 +- httpserver/serverOpt.go | 2 +- ioutils/fileDescriptor_ok.go | 4 +- ioutils/tempFile.go | 8 +- ldap/ldap.go | 26 +- ldap/model.go | 4 +- logger/config/model.go | 4 +- logger/entry/errors.go | 18 +- logger/entry/interface.go | 2 - mail/config.go | 8 +- mail/interface.go | 6 +- mail/mail.go | 6 +- mail/sender.go | 65 ++-- mailPooler/config.go | 4 +- mailPooler/counter.go | 14 +- mailPooler/interface.go | 3 +- mailPooler/model.go | 17 +- mailer/config.go | 4 +- mailer/render.go | 2 +- monitor/internalConfig.go | 2 +- monitor/model.go | 2 +- monitor/types/config.go | 4 +- nats/client.go | 6 +- nats/config.go | 30 +- nats/server.go | 2 +- network/network.go | 6 +- nutsdb/client.go | 32 +- nutsdb/config.go | 4 +- nutsdb/configDb.go | 4 +- nutsdb/configFs.go | 10 +- nutsdb/entryKv.go | 12 +- nutsdb/node.go | 10 +- nutsdb/options.go | 10 +- nutsdb/snap.go | 10 +- oauth/client.go | 2 +- request/interface.go | 7 +- request/monitor.go | 23 +- request/options.go | 13 +- request/request.go | 26 +- router/auth.go | 11 +- semaphore/semaphore.go | 4 +- smtp/client.go | 35 +-- smtp/config/config.go | 8 +- smtp/config/interface.go | 2 +- smtp/dial.go | 12 +- smtp/interface.go | 9 +- smtp/model.go | 3 +- static/pathfile.go | 34 +-- status/config.go | 4 +- status/encode.go | 2 +- version/version.go | 6 +- viper/config.go | 6 +- viper/model.go | 4 +- viper/remote.go | 8 +- 189 files changed, 1278 insertions(+), 1430 deletions(-) diff --git a/archive/archive.go b/archive/archive.go index e5dfd111..3e73b1a5 100644 --- a/archive/archive.go +++ b/archive/archive.go @@ -68,47 +68,47 @@ func ExtractFile(src, dst libfpg.Progress, fileNameContain, fileNameRegex string }() if tmp, e = libfpg.Temp(""); e != nil { - return ErrorFileOpen.ErrorParent(e) + return ErrorFileOpen.Error(e) } else { dst.SetRegisterProgress(tmp) } if _, e = src.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) // #nosec } if err = libbz2.GetFile(src, tmp); err == nil { //logger.DebugLevel.Log("try another archive...") return ExtractFile(tmp, dst, fileNameContain, fileNameRegex) - } else if err.IsCodeError(libbz2.ErrorIOCopy) { + } else if err.IsCode(libbz2.ErrorIOCopy) { return err } if err = libgzp.GetFile(src, tmp); err == nil { //logger.DebugLevel.Log("try another archive...") return ExtractFile(tmp, dst, fileNameContain, fileNameRegex) - } else if !err.IsCodeError(libgzp.ErrorGZReader) { + } else if !err.IsCode(libgzp.ErrorGZReader) { return err } if err = libtar.GetFile(src, tmp, fileNameContain, fileNameRegex); err == nil { //logger.DebugLevel.Log("try another archive...") return ExtractFile(tmp, dst, fileNameContain, fileNameRegex) - } else if !err.IsCodeError(libtar.ErrorTarNext) { + } else if !err.IsCode(libtar.ErrorTarNext) { return err } if err = libzip.GetFile(src, tmp, fileNameContain, fileNameRegex); err == nil { //logger.DebugLevel.Log("try another archive...") return ExtractFile(tmp, dst, fileNameContain, fileNameRegex) - } else if !err.IsCodeError(libzip.ErrorZipOpen) { + } else if !err.IsCode(libzip.ErrorZipOpen) { return err } if _, e = dst.ReadFrom(src); e != nil { //logger.ErrorLevel.LogErrorCtx(logger.DebugLevel, "reopening file", err) - return ErrorIOCopy.ErrorParent(e) + return ErrorIOCopy.Error(e) } return nil @@ -137,20 +137,20 @@ func ExtractAll(src libfpg.Progress, originalName, outputPath string, defaultDir }() if tmp, e = libfpg.Temp(""); e != nil { - return ErrorFileOpen.ErrorParent(e) + return ErrorFileOpen.Error(e) } else { src.SetRegisterProgress(tmp) } if err = libbz2.GetFile(src, tmp); err == nil { return ExtractAll(tmp, originalName, outputPath, defaultDirPerm) - } else if !err.IsCodeError(libbz2.ErrorIOCopy) { + } else if !err.IsCode(libbz2.ErrorIOCopy) { return err } if err = libgzp.GetFile(src, tmp); err == nil { return ExtractAll(tmp, originalName, outputPath, defaultDirPerm) - } else if !err.IsCodeError(libgzp.ErrorGZReader) { + } else if !err.IsCode(libgzp.ErrorGZReader) { return err } @@ -162,36 +162,36 @@ func ExtractAll(src libfpg.Progress, originalName, outputPath string, defaultDir //nolint #nosec /* #nosec */ if e = os.MkdirAll(outputPath, permDir); e != nil { - return ErrorDirCreate.ErrorParent(e) + return ErrorDirCreate.Error(e) } } else if e != nil { - return ErrorDirStat.ErrorParent(e) + return ErrorDirStat.Error(e) } else if !i.IsDir() { return ErrorDirNotDir.Error(nil) } if err = libtar.GetAll(src, outputPath, defaultDirPerm); err == nil { return nil - } else if !err.IsCodeError(libtar.ErrorTarNext) { + } else if !err.IsCode(libtar.ErrorTarNext) { return err } if err = libzip.GetAll(src, outputPath, defaultDirPerm); err == nil { return nil - } else if !err.IsCodeError(libzip.ErrorZipOpen) { + } else if !err.IsCode(libzip.ErrorZipOpen) { return err } if dst, e = libfpg.New(filepath.Join(outputPath, originalName), os.O_RDWR|os.O_CREATE|os.O_TRUNC, permFile); e != nil { - return ErrorFileOpen.ErrorParent(e) + return ErrorFileOpen.Error(e) } else { src.SetRegisterProgress(dst) } if _, e = src.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } else if _, e = dst.ReadFrom(src); e != nil { - return ErrorIOCopy.ErrorParent(e) + return ErrorIOCopy.Error(e) } return nil @@ -200,7 +200,7 @@ func ExtractAll(src libfpg.Progress, originalName, outputPath string, defaultDir func CreateArchive(archiveType ArchiveType, archive libfpg.Progress, stripPath string, comment string, pathContent ...string) (created bool, err liberr.Error) { if len(pathContent) < 1 { //nolint #goerr113 - return false, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathContent is empty")) + return false, ErrorParamEmpty.Error(fmt.Errorf("pathContent is empty")) } switch archiveType { diff --git a/archive/bz2/reader.go b/archive/bz2/reader.go index 18d0f74e..f45db154 100644 --- a/archive/bz2/reader.go +++ b/archive/bz2/reader.go @@ -34,9 +34,9 @@ import ( func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error { if _, e := src.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } else if _, e = dst.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } r := bzip2.NewReader(src) @@ -44,9 +44,9 @@ func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error { //nolint #nosec /* #nosec */ if _, e := io.Copy(dst, r); e != nil { - return ErrorIOCopy.ErrorParent(e) + return ErrorIOCopy.Error(e) } else if _, e = dst.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } else { return nil } diff --git a/archive/gzip/reader.go b/archive/gzip/reader.go index 23abc6a4..4987c81a 100644 --- a/archive/gzip/reader.go +++ b/archive/gzip/reader.go @@ -34,14 +34,14 @@ import ( func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error { if _, e := src.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } else if _, e = dst.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } r, e := gz.NewReader(src) if e != nil { - return ErrorGZReader.ErrorParent(e) + return ErrorGZReader.Error(e) } defer func() { @@ -51,9 +51,9 @@ func GetFile(src io.ReadSeeker, dst io.WriteSeeker) errors.Error { //nolint #nosec /* #nosec */ if _, e = io.Copy(dst, r); e != nil { - return ErrorIOCopy.ErrorParent(e) + return ErrorIOCopy.Error(e) } else if _, e := dst.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } else { return nil } diff --git a/archive/gzip/writer.go b/archive/gzip/writer.go index a65057b1..514c838e 100644 --- a/archive/gzip/writer.go +++ b/archive/gzip/writer.go @@ -46,15 +46,15 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content .. if len(content) != 1 { //nolint #goerr113 - return false, ErrorParamMismatching.ErrorParent(fmt.Errorf("content path must be limited to strictly one contents")) + return false, ErrorParamMismatching.Error(fmt.Errorf("content path must be limited to strictly one contents")) } if _, err = archive.Seek(0, io.SeekStart); err != nil { - return false, ErrorFileSeek.ErrorParent(err) + return false, ErrorFileSeek.Error(err) } if _, err = os.Stat(content[0]); err != nil { - return false, ErrorParamEmpty.ErrorParent(err) + return false, ErrorParamEmpty.Error(err) } w = gzip.NewWriter(archive) @@ -66,7 +66,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content .. }() if f, err = os.Open(content[0]); err != nil { - return false, ErrorFileOpen.ErrorParent(err) + return false, ErrorFileOpen.Error(err) } defer func() { @@ -76,15 +76,15 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content .. }() if _, err = io.Copy(w, f); err != nil { - return false, ErrorIOCopy.ErrorParent(err) + return false, ErrorIOCopy.Error(err) } if err = w.Close(); err != nil { - return false, ErrorGZCreate.ErrorParent(err) + return false, ErrorGZCreate.Error(err) } if _, err = archive.Seek(0, io.SeekStart); err != nil { - return false, ErrorFileSeek.ErrorParent(err) + return false, ErrorFileSeek.Error(err) } return true, nil diff --git a/archive/tar/reader.go b/archive/tar/reader.go index 6c5c8bcc..1dc92e69 100644 --- a/archive/tar/reader.go +++ b/archive/tar/reader.go @@ -42,9 +42,9 @@ import ( func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) liberr.Error { if _, e := src.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } else if _, e = dst.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } r := tar.NewReader(src) @@ -54,7 +54,7 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li if e != nil && e == io.EOF { return nil } else if e != nil { - return ErrorTarNext.ErrorParent(e) + return ErrorTarNext.Error(e) } if h.FileInfo().Mode()&os.ModeType == os.ModeType { @@ -67,9 +67,9 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li /* #nosec */ if f.MatchingFullPath(filenameContain) || f.RegexFullPath(filenameRegex) { if _, e = dst.ReadFrom(r); e != nil { - return ErrorIOCopy.ErrorParent(e) + return ErrorIOCopy.Error(e) } else if _, e = dst.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } else { return nil } @@ -80,7 +80,7 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li func GetAll(src io.ReadSeeker, outputFolder string, defaultDirPerm os.FileMode) liberr.Error { if _, e := src.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } r := tar.NewReader(src) @@ -90,7 +90,7 @@ func GetAll(src io.ReadSeeker, outputFolder string, defaultDirPerm os.FileMode) if e != nil && e == io.EOF { return nil } else if e != nil { - return ErrorTarNext.ErrorParent(e) + return ErrorTarNext.Error(e) } //nolint #nosec @@ -116,8 +116,8 @@ func writeContent(r io.Reader, h *tar.Header, out string, defaultDirPerm os.File defer func() { if dst != nil { if e := dst.Close(); e != nil { - err = ErrorFileClose.ErrorParent(e) - err.AddParentError(err) + err = ErrorFileClose.Error(e) + err.Add(err) } } }() @@ -134,11 +134,11 @@ func writeContent(r io.Reader, h *tar.Header, out string, defaultDirPerm os.File } if dst, e = libfpg.New(out, os.O_RDWR|os.O_CREATE|os.O_TRUNC, inf.Mode()); e != nil { - return ErrorFileOpen.ErrorParent(e) + return ErrorFileOpen.Error(e) } else if _, e = io.Copy(dst, r); e != nil { - return ErrorIOCopy.ErrorParent(e) + return ErrorIOCopy.Error(e) } else if e = dst.Close(); e != nil { - return ErrorFileClose.ErrorParent(e) + return ErrorFileClose.Error(e) } return nil @@ -147,10 +147,10 @@ func writeContent(r io.Reader, h *tar.Header, out string, defaultDirPerm os.File func dirIsExistOrCreate(dirname string, dirPerm os.FileMode) liberr.Error { if i, e := os.Stat(dirname); e != nil && os.IsNotExist(e) { if e = os.MkdirAll(dirname, dirPerm); e != nil { - return ErrorDirCreate.ErrorParent(e) + return ErrorDirCreate.Error(e) } } else if e != nil { - return ErrorDestinationStat.ErrorParent(e) + return ErrorDestinationStat.Error(e) } else if !i.IsDir() { return ErrorDestinationIsNotDir.Error(nil) } @@ -170,7 +170,7 @@ func notDirExistCannotClean(filename string, flag byte, targetLink string) liber if _, e := os.Stat(filename); e != nil && os.IsNotExist(e) { return nil } else if e != nil { - return ErrorDestinationStat.ErrorParent(e) + return ErrorDestinationStat.Error(e) } else if flag&tar.TypeLink == tar.TypeLink || flag&tar.TypeSymlink == tar.TypeSymlink { if hasFSLink(filename) && compareLinkTarget(filename, targetLink) { return nil @@ -178,7 +178,7 @@ func notDirExistCannotClean(filename string, flag byte, targetLink string) liber } if e := os.Remove(filename); e != nil { - err := ErrorDestinationRemove.ErrorParent(e) + err := ErrorDestinationRemove.Error(e) return err } @@ -201,7 +201,7 @@ func createLink(link, target string, sym bool) liberr.Error { } if _, e := os.Stat(link); e != nil && !os.IsNotExist(e) { - return ErrorDestinationStat.ErrorParent(e) + return ErrorDestinationStat.Error(e) } else if e == nil { return nil } else if compareLinkTarget(link, target) { @@ -211,12 +211,12 @@ func createLink(link, target string, sym bool) liberr.Error { if sym { err := os.Symlink(libarc.CleanPath(target), libarc.CleanPath(link)) if err != nil { - return ErrorLinkCreate.ErrorParent(err) + return ErrorLinkCreate.Error(err) } } else { err := os.Link(libarc.CleanPath(target), libarc.CleanPath(link)) if err != nil { - return ErrorLinkCreate.ErrorParent(err) + return ErrorLinkCreate.Error(err) } } diff --git a/archive/tar/writer.go b/archive/tar/writer.go index 4ff9db21..cdf03d6d 100644 --- a/archive/tar/writer.go +++ b/archive/tar/writer.go @@ -42,7 +42,7 @@ import ( func Create(archive io.WriteSeeker, stripPath string, comment string, content ...string) (bool, liberr.Error) { if _, err := archive.Seek(0, io.SeekStart); err != nil { - return false, ErrorFileSeek.ErrorParent(err) + return false, ErrorFileSeek.Error(err) } if ok, err := createTar(archive, stripPath, content...); err != nil || !ok { @@ -50,7 +50,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content .. } if _, err := archive.Seek(0, io.SeekStart); err != nil { - return false, ErrorFileSeek.ErrorParent(err) + return false, ErrorFileSeek.Error(err) } return true, nil @@ -59,7 +59,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content .. func CreateGzip(archive io.WriteSeeker, stripPath string, comment string, content ...string) (bool, liberr.Error) { if _, err := archive.Seek(0, io.SeekStart); err != nil { - return false, ErrorFileSeek.ErrorParent(err) + return false, ErrorFileSeek.Error(err) } z := gzip.NewWriter(archive) @@ -69,11 +69,11 @@ func CreateGzip(archive io.WriteSeeker, stripPath string, comment string, conten } if err := z.Close(); err != nil { - return false, ErrorGzipCreate.ErrorParent(err) + return false, ErrorGzipCreate.Error(err) } if _, err := archive.Seek(0, io.SeekStart); err != nil { - return false, ErrorFileSeek.ErrorParent(err) + return false, ErrorFileSeek.Error(err) } return true, nil @@ -147,7 +147,7 @@ func createTar(w io.Writer, stripPath string, content ...string) (bool, liberr.E }) if err != nil { - lEr.AddParent(err) + lEr.Add(err) continue } } @@ -158,13 +158,13 @@ func createTar(w io.Writer, stripPath string, content ...string) (bool, liberr.E } //nolint #goerr113 - return false, ErrorTarCreate.ErrorParent(fmt.Errorf("no file to add in archive")) + return false, ErrorTarCreate.Error(fmt.Errorf("no file to add in archive")) } else if !lEr.HasParent() { lEr = nil } if err = t.Close(); err != nil { - return false, ErrorTarCreate.ErrorParent(err) + return false, ErrorTarCreate.Error(err) } return true, lEr diff --git a/archive/zip/reader.go b/archive/zip/reader.go index 70de2d22..746a5633 100644 --- a/archive/zip/reader.go +++ b/archive/zip/reader.go @@ -45,13 +45,13 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li ) if _, err = src.Seek(0, io.SeekStart); err != nil { - return ErrorFileSeek.ErrorParent(err) + return ErrorFileSeek.Error(err) } else if _, err = dst.Seek(0, io.SeekStart); err != nil { - return ErrorFileSeek.ErrorParent(err) + return ErrorFileSeek.Error(err) } else if inf, err = src.Stat(); err != nil { - return ErrorFileStat.ErrorParent(err) + return ErrorFileStat.Error(err) } else if arc, err = zip.NewReader(src, inf.Size()); err != nil { - return ErrorZipOpen.ErrorParent(err) + return ErrorZipOpen.Error(err) } for _, f := range arc.File { @@ -73,7 +73,7 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li if r, e = f.Open(); e != nil { //logger.ErrorLevel.LogErrorCtx(logger.DebugLevel, "open zipped file reader", err) - return ErrorZipFileOpen.ErrorParent(e) + return ErrorZipFileOpen.Error(e) } defer func() { @@ -84,12 +84,12 @@ func GetFile(src, dst libfpg.Progress, filenameContain, filenameRegex string) li /* #nosec */ if _, e = dst.ReadFrom(r); e != nil { //logger.ErrorLevel.LogErrorCtx(logger.DebugLevel, "copy buffer from archive reader", err) - return ErrorIOCopy.ErrorParent(e) + return ErrorIOCopy.Error(e) } if _, e = dst.Seek(0, io.SeekStart); e != nil { //logger.ErrorLevel.LogErrorCtx(logger.DebugLevel, "seeking temp file", err) - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } return nil @@ -107,11 +107,11 @@ func GetAll(src libfpg.Progress, outputFolder string, defaultDirPerm os.FileMode ) if _, e = src.Seek(0, io.SeekStart); e != nil { - return ErrorFileSeek.ErrorParent(e) + return ErrorFileSeek.Error(e) } else if i, e = src.Stat(); e != nil { - return ErrorFileStat.ErrorParent(e) + return ErrorFileStat.Error(e) } else if r, e = zip.NewReader(src, i.Size()); e != nil { - return ErrorZipOpen.ErrorParent(e) + return ErrorZipOpen.Error(e) } for _, f := range r.File { @@ -145,8 +145,8 @@ func writeContent(f *zip.File, out string, defaultDirPerm os.FileMode) (err libe defer func() { if dst != nil { if e = dst.Close(); e != nil { - err = ErrorFileClose.ErrorParent(e) - err.AddParentError(err) + err = ErrorFileClose.Error(e) + err.Add(err) } } if r != nil { @@ -166,21 +166,21 @@ func writeContent(f *zip.File, out string, defaultDirPerm os.FileMode) (err libe } if dst, e = libfpg.New(out, os.O_RDWR|os.O_CREATE|os.O_TRUNC, inf.Mode()); e != nil { - return ErrorFileOpen.ErrorParent(e) + return ErrorFileOpen.Error(e) } else { } if r, e = f.Open(); e != nil { - return ErrorZipFileOpen.ErrorParent(e) + return ErrorZipFileOpen.Error(e) } //nolint #nosec /* #nosec */ if _, e = io.Copy(dst, r); e != nil { - return ErrorIOCopy.ErrorParent(e) + return ErrorIOCopy.Error(e) } else if e = dst.Close(); e != nil { - return ErrorFileClose.ErrorParent(e) + return ErrorFileClose.Error(e) } return nil @@ -189,10 +189,10 @@ func writeContent(f *zip.File, out string, defaultDirPerm os.FileMode) (err libe func dirIsExistOrCreate(dirname string, dirPerm os.FileMode) liberr.Error { if i, e := os.Stat(filepath.Dir(dirname)); e != nil && os.IsNotExist(e) { if e = os.MkdirAll(filepath.Dir(dirname), dirPerm); e != nil { - return ErrorDirCreate.ErrorParent(e) + return ErrorDirCreate.Error(e) } } else if e != nil { - return ErrorDestinationStat.ErrorParent(e) + return ErrorDestinationStat.Error(e) } else if !i.IsDir() { return ErrorDestinationIsNotDir.Error(nil) } @@ -202,12 +202,12 @@ func dirIsExistOrCreate(dirname string, dirPerm os.FileMode) liberr.Error { func notDirExistCannotClean(filename string) liberr.Error { if i, e := os.Stat(filename); e != nil && !os.IsNotExist(e) { - return ErrorDestinationStat.ErrorParent(e) + return ErrorDestinationStat.Error(e) } else if e == nil && i.IsDir() { return ErrorDestinationIsDir.Error(nil) } else if e == nil { if e = os.Remove(filename); e != nil { - return ErrorDestinationRemove.ErrorParent(e) + return ErrorDestinationRemove.Error(e) } } return nil diff --git a/archive/zip/writer.go b/archive/zip/writer.go index 9b71c32c..44104ba4 100644 --- a/archive/zip/writer.go +++ b/archive/zip/writer.go @@ -40,7 +40,7 @@ import ( func Create(archive io.WriteSeeker, stripPath string, comment string, content ...string) (bool, liberr.Error) { if _, err := archive.Seek(0, io.SeekStart); err != nil { - return false, ErrorFileSeek.ErrorParent(err) + return false, ErrorFileSeek.Error(err) } var ( @@ -57,7 +57,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content .. if comment != "" { if e := z.SetComment(comment); e != nil { - return false, ErrorZipComment.ErrorParent(e) + return false, ErrorZipComment.Error(e) } } @@ -66,7 +66,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content .. } if _, err := archive.Seek(0, io.SeekStart); err != nil { - return false, ErrorFileSeek.ErrorParent(err) + return false, ErrorFileSeek.Error(err) } return true, nil @@ -138,7 +138,7 @@ func addFileToZip(z *zip.Writer, stripPath string, content ...string) (bool, lib }) if err != nil { - lEr.AddParent(err) + lEr.Add(err) continue } } @@ -148,13 +148,13 @@ func addFileToZip(z *zip.Writer, stripPath string, content ...string) (bool, lib return false, lEr } - return false, ErrorZipCreate.ErrorParent(fmt.Errorf("no file to add in archive")) + return false, ErrorZipCreate.Error(fmt.Errorf("no file to add in archive")) } else if !lEr.HasParent() { lEr = nil } if err = z.Close(); err != nil { - return false, ErrorZipCreate.ErrorParent(err) + return false, ErrorZipCreate.Error(err) } return true, lEr diff --git a/artifact/artifact.go b/artifact/artifact.go index ed6a2d5d..0edf2c6e 100644 --- a/artifact/artifact.go +++ b/artifact/artifact.go @@ -48,9 +48,9 @@ const ( type Client interface { artcli.ArtifactManagement - ListReleases() (releases hscvrs.Collection, err liberr.Error) - GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err liberr.Error) - Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) liberr.Error + ListReleases() (releases hscvrs.Collection, err error) + GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err error) + Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) error } func CheckRegex(name, regex string) bool { @@ -61,7 +61,7 @@ func CheckRegex(name, regex string) bool { return false } -func DownloadRelease(link string) (file os.File, err liberr.Error) { +func DownloadRelease(link string) (file os.File, err error) { panic("not implemented") } diff --git a/artifact/client/interface.go b/artifact/client/interface.go index 9081552c..e1e77bdb 100644 --- a/artifact/client/interface.go +++ b/artifact/client/interface.go @@ -27,15 +27,14 @@ package client import ( hscvrs "github.com/hashicorp/go-version" - liberr "github.com/nabbar/golib/errors" ) type ArtifactManagement interface { - ListReleasesOrder() (releases map[int]map[int]hscvrs.Collection, err liberr.Error) - ListReleasesMajor(major int) (releases hscvrs.Collection, err liberr.Error) - ListReleasesMinor(major, minor int) (releases hscvrs.Collection, err liberr.Error) + ListReleasesOrder() (releases map[int]map[int]hscvrs.Collection, err error) + ListReleasesMajor(major int) (releases hscvrs.Collection, err error) + ListReleasesMinor(major, minor int) (releases hscvrs.Collection, err error) - GetLatest() (release *hscvrs.Version, err liberr.Error) - GetLatestMajor(major int) (release *hscvrs.Version, err liberr.Error) - GetLatestMinor(major, minor int) (release *hscvrs.Version, err liberr.Error) + GetLatest() (release *hscvrs.Version, err error) + GetLatestMajor(major int) (release *hscvrs.Version, err error) + GetLatestMinor(major, minor int) (release *hscvrs.Version, err error) } diff --git a/artifact/client/model.go b/artifact/client/model.go index a3cb5493..6e217159 100644 --- a/artifact/client/model.go +++ b/artifact/client/model.go @@ -29,14 +29,13 @@ import ( "sort" hscvrs "github.com/hashicorp/go-version" - liberr "github.com/nabbar/golib/errors" ) type ClientHelper struct { - F func() (releases hscvrs.Collection, err liberr.Error) + F func() (releases hscvrs.Collection, err error) } -func (g *ClientHelper) listReleasesOrderMajor() (releases map[int]hscvrs.Collection, err liberr.Error) { +func (g *ClientHelper) listReleasesOrderMajor() (releases map[int]hscvrs.Collection, err error) { var ( vers hscvrs.Collection ) @@ -58,7 +57,7 @@ func (g *ClientHelper) listReleasesOrderMajor() (releases map[int]hscvrs.Collect return } -func (g *ClientHelper) ListReleasesOrder() (releases map[int]map[int]hscvrs.Collection, err liberr.Error) { +func (g *ClientHelper) ListReleasesOrder() (releases map[int]map[int]hscvrs.Collection, err error) { var ( vers map[int]hscvrs.Collection ) @@ -86,7 +85,7 @@ func (g *ClientHelper) ListReleasesOrder() (releases map[int]map[int]hscvrs.Coll return } -func (g *ClientHelper) ListReleasesMajor(major int) (releases hscvrs.Collection, err liberr.Error) { +func (g *ClientHelper) ListReleasesMajor(major int) (releases hscvrs.Collection, err error) { var ( vers map[int]hscvrs.Collection ) @@ -106,7 +105,7 @@ func (g *ClientHelper) ListReleasesMajor(major int) (releases hscvrs.Collection, return } -func (g *ClientHelper) ListReleasesMinor(major, minor int) (releases hscvrs.Collection, err liberr.Error) { +func (g *ClientHelper) ListReleasesMinor(major, minor int) (releases hscvrs.Collection, err error) { var ( vers map[int]map[int]hscvrs.Collection ) @@ -130,7 +129,7 @@ func (g *ClientHelper) ListReleasesMinor(major, minor int) (releases hscvrs.Coll return } -func (g *ClientHelper) GetLatest() (release *hscvrs.Version, err liberr.Error) { +func (g *ClientHelper) GetLatest() (release *hscvrs.Version, err error) { var ( vers map[int]map[int]hscvrs.Collection major int @@ -156,7 +155,7 @@ func (g *ClientHelper) GetLatest() (release *hscvrs.Version, err liberr.Error) { return g.GetLatestMinor(major, minor) } -func (g *ClientHelper) GetLatestMajor(major int) (release *hscvrs.Version, err liberr.Error) { +func (g *ClientHelper) GetLatestMajor(major int) (release *hscvrs.Version, err error) { var ( vers map[int]map[int]hscvrs.Collection minor int @@ -179,7 +178,7 @@ func (g *ClientHelper) GetLatestMajor(major int) (release *hscvrs.Version, err l return g.GetLatestMinor(major, minor) } -func (g *ClientHelper) GetLatestMinor(major, minor int) (release *hscvrs.Version, err liberr.Error) { +func (g *ClientHelper) GetLatestMinor(major, minor int) (release *hscvrs.Version, err error) { var ( vers hscvrs.Collection ) diff --git a/artifact/github/github.go b/artifact/github/github.go index da25eecf..6eeadb21 100644 --- a/artifact/github/github.go +++ b/artifact/github/github.go @@ -33,7 +33,6 @@ import ( github "github.com/google/go-github/v33/github" libart "github.com/nabbar/golib/artifact" artcli "github.com/nabbar/golib/artifact/client" - liberr "github.com/nabbar/golib/errors" ) func getOrgProjectFromRepos(repos string) (owner string, project string) { @@ -45,7 +44,7 @@ func getOrgProjectFromRepos(repos string) (owner string, project string) { return lst[0], lst[1] } -func NewGithub(ctx context.Context, httpcli *http.Client, repos string) (cli libart.Client, err liberr.Error) { +func NewGithub(ctx context.Context, httpcli *http.Client, repos string) (cli libart.Client, err error) { o, p := getOrgProjectFromRepos(repos) a := &githubModel{ @@ -61,7 +60,7 @@ func NewGithub(ctx context.Context, httpcli *http.Client, repos string) (cli lib return a, err } -func NewGithubWithTokenOAuth(ctx context.Context, repos string, oauth2client *http.Client) (cli libart.Client, err liberr.Error) { +func NewGithubWithTokenOAuth(ctx context.Context, repos string, oauth2client *http.Client) (cli libart.Client, err error) { o, p := getOrgProjectFromRepos(repos) a := &githubModel{ diff --git a/artifact/github/model.go b/artifact/github/model.go index 10332145..800531a2 100644 --- a/artifact/github/model.go +++ b/artifact/github/model.go @@ -36,7 +36,6 @@ import ( hscvrs "github.com/hashicorp/go-version" libart "github.com/nabbar/golib/artifact" artcli "github.com/nabbar/golib/artifact/client" - liberr "github.com/nabbar/golib/errors" libfpg "github.com/nabbar/golib/file/progress" ) @@ -53,7 +52,7 @@ type githubModel struct { p string } -func (g *githubModel) ListReleases() (releases hscvrs.Collection, err liberr.Error) { +func (g *githubModel) ListReleases() (releases hscvrs.Collection, err error) { var ( e error lopt = &github.ListOptions{ @@ -70,7 +69,7 @@ func (g *githubModel) ListReleases() (releases hscvrs.Collection, err liberr.Err ) if rels, resp, e = g.c.Repositories.ListReleases(g.x, g.o, g.p, lopt); e != nil { - return nil, ErrorGithubList.ErrorParent(e) + return nil, ErrorGithubList.Error(e) } else { curr++ } @@ -92,14 +91,14 @@ func (g *githubModel) ListReleases() (releases hscvrs.Collection, err liberr.Err } } -func (g *githubModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err liberr.Error) { +func (g *githubModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err error) { var ( rels *github.RepositoryRelease e error ) if rels, _, e = g.c.Repositories.GetReleaseByTag(g.x, g.o, g.p, release.Original()); e != nil { - return "", ErrorGithubGetRelease.ErrorParent(e) + return "", ErrorGithubGetRelease.Error(e) } for _, a := range rels.Assets { @@ -113,13 +112,13 @@ func (g *githubModel) GetArtifact(containName string, regexName string, release return "", ErrorGithubNotFound.Error(nil) } -func (g *githubModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) liberr.Error { +func (g *githubModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) error { var ( uri string rsp *github.Response req *http.Request err error - e liberr.Error + e error n int64 ) @@ -135,23 +134,23 @@ func (g *githubModel) Download(dst libfpg.Progress, containName string, regexNam if uri, e = g.GetArtifact(containName, regexName, release); e != nil { return e } else if req, err = g.c.NewRequest(http.MethodGet, uri, nil); err != nil { - return ErrorGithubRequestNew.ErrorParent(err) + return ErrorGithubRequestNew.Error(err) } else if rsp, err = g.c.Do(g.x, req, nil); err != nil { - return ErrorGithubRequestRun.ErrorParent(err) + return ErrorGithubRequestRun.Error(err) } else if rsp.StatusCode < 200 || rsp.StatusCode > 299 { - return ErrorGithubResponse.ErrorParent(errResponseCode) + return ErrorGithubResponse.Error(errResponseCode) } else if rsp.ContentLength < 1 { - return ErrorGithubResponse.ErrorParent(errResponseContents) + return ErrorGithubResponse.Error(errResponseContents) } else if rsp.Body == nil { - return ErrorGithubResponse.ErrorParent(errResponseBodyEmpty) + return ErrorGithubResponse.Error(errResponseBodyEmpty) } else { dst.Reset(rsp.ContentLength) } if n, err = io.Copy(dst, rsp.Body); err != nil { - return ErrorGithubIOCopy.ErrorParent(err) + return ErrorGithubIOCopy.Error(err) } else if n != rsp.ContentLength { - return ErrorDestinationSize.ErrorParent(errMisMatchingSize) + return ErrorDestinationSize.Error(errMisMatchingSize) } return nil diff --git a/artifact/gitlab/gitlab.go b/artifact/gitlab/gitlab.go index 81e261a5..ee1d93af 100644 --- a/artifact/gitlab/gitlab.go +++ b/artifact/gitlab/gitlab.go @@ -33,7 +33,6 @@ import ( libart "github.com/nabbar/golib/artifact" artcli "github.com/nabbar/golib/artifact/client" - liberr "github.com/nabbar/golib/errors" gitlab "github.com/xanzy/go-gitlab" ) @@ -42,7 +41,7 @@ const ( GitlabAPIVersion = "/v4" ) -func getGitlbaOptions(baseUrl string, httpcli *http.Client) (opt []gitlab.ClientOptionFunc, err liberr.Error) { +func getGitlbaOptions(baseUrl string, httpcli *http.Client) (opt []gitlab.ClientOptionFunc, err error) { var ( u *url.URL e error @@ -51,7 +50,7 @@ func getGitlbaOptions(baseUrl string, httpcli *http.Client) (opt []gitlab.Client opt = make([]gitlab.ClientOptionFunc, 0) if u, e = url.Parse(baseUrl); e != nil { - return opt, ErrorURLParse.ErrorParent(e) + return opt, ErrorURLParse.Error(e) } if !strings.Contains(u.Path, GitlabAPIBase) { @@ -84,7 +83,7 @@ func newGitlab(ctx context.Context, c *gitlab.Client, projectId int) libart.Clie return a } -func NewGitlabAuthUser(ctx context.Context, httpcli *http.Client, user, pass, baseUrl string, projectId int) (cli libart.Client, err liberr.Error) { +func NewGitlabAuthUser(ctx context.Context, httpcli *http.Client, user, pass, baseUrl string, projectId int) (cli libart.Client, err error) { var ( o []gitlab.ClientOptionFunc c *gitlab.Client @@ -96,13 +95,13 @@ func NewGitlabAuthUser(ctx context.Context, httpcli *http.Client, user, pass, ba } if c, e = gitlab.NewBasicAuthClient(user, pass, o...); e != nil { - return nil, ErrorClientInit.ErrorParent(e) + return nil, ErrorClientInit.Error(e) } return newGitlab(ctx, c, projectId), err } -func NewGitlabOAuth(ctx context.Context, httpcli *http.Client, oAuthToken, baseUrl string, projectId int) (cli libart.Client, err liberr.Error) { +func NewGitlabOAuth(ctx context.Context, httpcli *http.Client, oAuthToken, baseUrl string, projectId int) (cli libart.Client, err error) { var ( o []gitlab.ClientOptionFunc c *gitlab.Client @@ -114,13 +113,13 @@ func NewGitlabOAuth(ctx context.Context, httpcli *http.Client, oAuthToken, baseU } if c, e = gitlab.NewOAuthClient(oAuthToken, o...); e != nil { - return nil, ErrorClientInit.ErrorParent(e) + return nil, ErrorClientInit.Error(e) } return newGitlab(ctx, c, projectId), err } -func NewGitlabPrivateToken(ctx context.Context, httpcli *http.Client, token, baseUrl string, projectId int) (cli libart.Client, err liberr.Error) { +func NewGitlabPrivateToken(ctx context.Context, httpcli *http.Client, token, baseUrl string, projectId int) (cli libart.Client, err error) { var ( o []gitlab.ClientOptionFunc c *gitlab.Client @@ -132,7 +131,7 @@ func NewGitlabPrivateToken(ctx context.Context, httpcli *http.Client, token, bas } if c, e = gitlab.NewClient(token, o...); e != nil { - return nil, ErrorClientInit.ErrorParent(e) + return nil, ErrorClientInit.Error(e) } return newGitlab(ctx, c, projectId), err diff --git a/artifact/gitlab/model.go b/artifact/gitlab/model.go index efe4d0bf..0d7aacc8 100644 --- a/artifact/gitlab/model.go +++ b/artifact/gitlab/model.go @@ -36,7 +36,6 @@ import ( hscvrs "github.com/hashicorp/go-version" libart "github.com/nabbar/golib/artifact" artcli "github.com/nabbar/golib/artifact/client" - liberr "github.com/nabbar/golib/errors" libfpg "github.com/nabbar/golib/file/progress" gitlab "github.com/xanzy/go-gitlab" ) @@ -53,7 +52,7 @@ type gitlabModel struct { p int } -func (g *gitlabModel) ListReleases() (releases hscvrs.Collection, err liberr.Error) { +func (g *gitlabModel) ListReleases() (releases hscvrs.Collection, err error) { var ( e error lopt = &gitlab.ListReleasesOptions{ @@ -71,7 +70,7 @@ func (g *gitlabModel) ListReleases() (releases hscvrs.Collection, err liberr.Err ) if rels, resp, e = g.c.Releases.ListReleases(g.p, lopt, gitlab.WithContext(g.x)); e != nil { - return nil, ErrorGitlabList.ErrorParent(e) + return nil, ErrorGitlabList.Error(e) } for _, r := range rels { @@ -91,14 +90,14 @@ func (g *gitlabModel) ListReleases() (releases hscvrs.Collection, err liberr.Err } } -func (g *gitlabModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err liberr.Error) { +func (g *gitlabModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err error) { var ( vers *gitlab.Release e error ) if vers, _, e = g.c.Releases.GetRelease(g.p, release.Original(), gitlab.WithContext(g.x)); e != nil { - return "", ErrorGitlabGetRelease.ErrorParent(e) + return "", ErrorGitlabGetRelease.Error(e) } for _, l := range vers.Assets.Links { @@ -112,13 +111,13 @@ func (g *gitlabModel) GetArtifact(containName string, regexName string, release return "", ErrorGitlabNotFound.Error(nil) } -func (g *gitlabModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) liberr.Error { +func (g *gitlabModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) error { var ( uri string rsp *gitlab.Response req *hschtc.Request err error - e liberr.Error + e error n int64 ) @@ -134,23 +133,23 @@ func (g *gitlabModel) Download(dst libfpg.Progress, containName string, regexNam if uri, e = g.GetArtifact(containName, regexName, release); e != nil { return e } else if req, err = g.c.NewRequest(http.MethodGet, uri, nil, nil); err != nil { - return ErrorGitlabRequestNew.ErrorParent(err) + return ErrorGitlabRequestNew.Error(err) } else if rsp, err = g.c.Do(req, nil); err != nil { - return ErrorGitlabRequestRun.ErrorParent(err) + return ErrorGitlabRequestRun.Error(err) } else if rsp.StatusCode < 200 || rsp.StatusCode > 299 { - return ErrorGitlabResponse.ErrorParent(errResponseCode) + return ErrorGitlabResponse.Error(errResponseCode) } else if rsp.ContentLength < 1 { - return ErrorGitlabResponse.ErrorParent(errResponseContents) + return ErrorGitlabResponse.Error(errResponseContents) } else if rsp.Body == nil { - return ErrorGitlabResponse.ErrorParent(errResponseBodyEmpty) + return ErrorGitlabResponse.Error(errResponseBodyEmpty) } else { dst.Reset(rsp.ContentLength) } if n, err = io.Copy(dst, rsp.Body); err != nil { - return ErrorGitlabIOCopy.ErrorParent(err) + return ErrorGitlabIOCopy.Error(err) } else if n != rsp.ContentLength { - return ErrorDestinationSize.ErrorParent(errMisMatchingSize) + return ErrorDestinationSize.Error(errMisMatchingSize) } return nil diff --git a/artifact/jfrog/artifactory.go b/artifact/jfrog/artifactory.go index 68cb94ef..95d5727f 100644 --- a/artifact/jfrog/artifactory.go +++ b/artifact/jfrog/artifactory.go @@ -32,12 +32,11 @@ import ( libart "github.com/nabbar/golib/artifact" artcli "github.com/nabbar/golib/artifact/client" - liberr "github.com/nabbar/golib/errors" ) -func NewArtifactory(ctx context.Context, Do func(req *http.Request) (*http.Response, error), uri, releaseRegex string, releaseGroup int, reposPath ...string) (libart.Client, liberr.Error) { +func NewArtifactory(ctx context.Context, Do func(req *http.Request) (*http.Response, error), uri, releaseRegex string, releaseGroup int, reposPath ...string) (libart.Client, error) { if u, e := url.Parse(uri); e != nil { - return nil, ErrorURLParse.ErrorParent(e) + return nil, ErrorURLParse.Error(e) } else { a := &artifactoryModel{ ClientHelper: artcli.ClientHelper{}, diff --git a/artifact/jfrog/model.go b/artifact/jfrog/model.go index 8c872099..a7cb19ae 100644 --- a/artifact/jfrog/model.go +++ b/artifact/jfrog/model.go @@ -42,7 +42,6 @@ import ( hscvrs "github.com/hashicorp/go-version" libart "github.com/nabbar/golib/artifact" artcli "github.com/nabbar/golib/artifact/client" - liberr "github.com/nabbar/golib/errors" libfpg "github.com/nabbar/golib/file/progress" ) @@ -97,7 +96,7 @@ type ResponseReposStorage struct { Children []ResponseReposChildrenStorage } -func (a *artifactoryModel) request(uri string, bodyResponse interface{}) liberr.Error { +func (a *artifactoryModel) request(uri string, bodyResponse interface{}) error { var ( ctx context.Context cnl context.CancelFunc @@ -138,7 +137,7 @@ func (a *artifactoryModel) request(uri string, bodyResponse interface{}) liberr. u.Path = path.Clean(u.Path) if req, e = http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil); e != nil { - return ErrorRequestInit.ErrorParent(e) + return ErrorRequestInit.Error(e) } defer func() { @@ -148,7 +147,7 @@ func (a *artifactoryModel) request(uri string, bodyResponse interface{}) liberr. }() if rsp, e = a.Do(req); e != nil { - return ErrorRequestDo.ErrorParent(e) + return ErrorRequestDo.Error(e) } defer func() { @@ -159,18 +158,18 @@ func (a *artifactoryModel) request(uri string, bodyResponse interface{}) liberr. if rsp.StatusCode >= http.StatusBadRequest { //nolint #goerr113 - return ErrorRequestResponse.ErrorParent(fmt.Errorf("status: %v", rsp.Status)) + return ErrorRequestResponse.Error(fmt.Errorf("status: %v", rsp.Status)) } if rsp.Body == nil { //nolint #goerr113 - return ErrorRequestResponseBodyEmpty.ErrorParent(fmt.Errorf("status: %v", rsp.Status)) + return ErrorRequestResponseBodyEmpty.Error(fmt.Errorf("status: %v", rsp.Status)) } if buf, e := ioutil.ReadAll(rsp.Body); e != nil { - return ErrorRequestResponseBodyDecode.ErrorParent(e) + return ErrorRequestResponseBodyDecode.Error(e) } else if e = json.Unmarshal(buf, bodyResponse); e != nil { - return ErrorRequestResponseBodyDecode.ErrorParent(e) + return ErrorRequestResponseBodyDecode.Error(e) } cnl() @@ -180,7 +179,7 @@ func (a *artifactoryModel) request(uri string, bodyResponse interface{}) liberr. } -func (a *artifactoryModel) getStorageList() (sto []ResponseStorage, err liberr.Error) { +func (a *artifactoryModel) getStorageList() (sto []ResponseStorage, err error) { var ( lst = ResponseReposStorage{} reg = regexp.MustCompile(a.regex) @@ -188,12 +187,12 @@ func (a *artifactoryModel) getStorageList() (sto []ResponseStorage, err liberr.E if a.regex == "" { //nolint #goerr113 - return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("regex is empty: %s", a.regex)) + return nil, ErrorParamEmpty.Error(fmt.Errorf("regex is empty: %s", a.regex)) } if a.group < 1 { //nolint #goerr113 - return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("group extracted from regex is empty: %s - %v", a.regex, a.group)) + return nil, ErrorParamEmpty.Error(fmt.Errorf("group extracted from regex is empty: %s - %v", a.regex, a.group)) } if err = a.request("", &lst); err != nil { @@ -223,7 +222,7 @@ func (a *artifactoryModel) getStorageList() (sto []ResponseStorage, err liberr.E } if res.size, e = strconv.ParseInt(res.Size, 10, 64); e != nil { - return nil, ErrorRequestResponseBodyDecode.ErrorParent(e) + return nil, ErrorRequestResponseBodyDecode.Error(e) } sto = append(sto, res) @@ -242,7 +241,7 @@ func (a *artifactoryModel) releasesAppendNotExist(releases hscvrs.Collection, ve return append(releases, vers) } -func (a *artifactoryModel) ListReleases() (releases hscvrs.Collection, err liberr.Error) { +func (a *artifactoryModel) ListReleases() (releases hscvrs.Collection, err error) { var ( reg = regexp.MustCompile(a.regex) sto []ResponseStorage @@ -271,7 +270,7 @@ func (a *artifactoryModel) ListReleases() (releases hscvrs.Collection, err liber return releases, nil } -func (a *artifactoryModel) getArtifact(containName string, regexName string, release *hscvrs.Version) (art *ResponseStorage, err liberr.Error) { +func (a *artifactoryModel) getArtifact(containName string, regexName string, release *hscvrs.Version) (art *ResponseStorage, err error) { var ( reg = regexp.MustCompile(a.regex) rg2 *regexp.Regexp @@ -312,7 +311,7 @@ func (a *artifactoryModel) getArtifact(containName string, regexName string, rel return nil, ErrorArtifactoryNotFound.Error(nil) } -func (a *artifactoryModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err liberr.Error) { +func (a *artifactoryModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err error) { if art, err := a.getArtifact(containName, regexName, release); err != nil { return "", err } else { @@ -320,13 +319,13 @@ func (a *artifactoryModel) GetArtifact(containName string, regexName string, rel } } -func (a *artifactoryModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) liberr.Error { +func (a *artifactoryModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) error { var ( e error n int64 art *ResponseStorage - err liberr.Error + err error req *http.Request rsp *http.Response ) @@ -348,21 +347,21 @@ func (a *artifactoryModel) Download(dst libfpg.Progress, containName string, reg } if req, e = http.NewRequestWithContext(a.ctx, http.MethodGet, art.DownloadUri, nil); e != nil { - return ErrorRequestInit.ErrorParent(e) + return ErrorRequestInit.Error(e) } else if rsp, e = a.Do(req); e != nil { - return ErrorRequestDo.ErrorParent(e) + return ErrorRequestDo.Error(e) } else if rsp.StatusCode >= http.StatusBadRequest { //nolint #goerr113 - return ErrorRequestResponse.ErrorParent(fmt.Errorf("status: %v", rsp.Status)) + return ErrorRequestResponse.Error(fmt.Errorf("status: %v", rsp.Status)) } else if rsp.Body == nil { //nolint #goerr113 - return ErrorRequestResponseBodyEmpty.ErrorParent(fmt.Errorf("status: %v", rsp.Status)) + return ErrorRequestResponseBodyEmpty.Error(fmt.Errorf("status: %v", rsp.Status)) } else if n, e = io.Copy(dst, rsp.Body); e != nil { - return ErrorArtifactoryDownload.ErrorParent(e) + return ErrorArtifactoryDownload.Error(e) } else if n != art.size { - return ErrorDestinationSize.ErrorParent(errMisMatchingSize) + return ErrorDestinationSize.Error(errMisMatchingSize) } else if n != rsp.ContentLength { - return ErrorDestinationSize.ErrorParent(errMisMatchingSize) + return ErrorDestinationSize.Error(errMisMatchingSize) } return nil diff --git a/artifact/s3aws/model.go b/artifact/s3aws/model.go index 732fa1ea..055da9cb 100644 --- a/artifact/s3aws/model.go +++ b/artifact/s3aws/model.go @@ -36,7 +36,6 @@ import ( libart "github.com/nabbar/golib/artifact" artcli "github.com/nabbar/golib/artifact/client" libaws "github.com/nabbar/golib/aws" - liberr "github.com/nabbar/golib/errors" libfpg "github.com/nabbar/golib/file/progress" ) @@ -49,9 +48,9 @@ type s3awsModel struct { group int } -func (s *s3awsModel) ListReleases() (releases hscvrs.Collection, err liberr.Error) { +func (s *s3awsModel) ListReleases() (releases hscvrs.Collection, err error) { var ( - e liberr.Error + e error r *regexp.Regexp l []string ) @@ -70,7 +69,7 @@ func (s *s3awsModel) ListReleases() (releases hscvrs.Collection, err liberr.Erro grp := r.FindStringSubmatch(o) if len(grp) < s.group { - return nil, ErrorS3AWSRegex.ErrorParent(getError(errRegexGroup, s.regex, len(grp), s.group)) + return nil, ErrorS3AWSRegex.Error(getError(errRegexGroup, s.regex, len(grp), s.group)) } if v, e := hscvrs.NewVersion(grp[s.group]); e != nil { @@ -94,7 +93,7 @@ func (s *s3awsModel) ListReleases() (releases hscvrs.Collection, err liberr.Erro return releases, nil } -func (s *s3awsModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err liberr.Error) { +func (s *s3awsModel) GetArtifact(containName string, regexName string, release *hscvrs.Version) (link string, err error) { var ( e error k bool @@ -117,11 +116,11 @@ func (s *s3awsModel) GetArtifact(containName string, regexName string, release * grp := r.FindStringSubmatch(o) if len(grp) < s.group { - return "", ErrorS3AWSRegex.ErrorParent(getError(errRegexGroup, s.regex, len(grp), s.group)) + return "", ErrorS3AWSRegex.Error(getError(errRegexGroup, s.regex, len(grp), s.group)) } if v, e = hscvrs.NewVersion(grp[s.group]); e != nil { - return "", ErrorS3AWSNewVers.ErrorParent(getError(errVersion, grp[s.group]), e) + return "", ErrorS3AWSNewVers.Error(getError(errVersion, grp[s.group]), e) } else if v.Equal(release) { uri := s.c.Config().GetEndpoint() uri.Path += "/" + s.c.GetBucketName() + "/" + o @@ -143,10 +142,10 @@ func (s *s3awsModel) GetArtifact(containName string, regexName string, release * } } - return "", ErrorS3AWSNotFound.ErrorParent(getError(errVersRequest, release.String())) + return "", ErrorS3AWSNotFound.Error(getError(errVersRequest, release.String())) } -func (s *s3awsModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) liberr.Error { +func (s *s3awsModel) Download(dst libfpg.Progress, containName string, regexName string, release *hscvrs.Version) error { var ( e error r *regexp.Regexp @@ -154,7 +153,7 @@ func (s *s3awsModel) Download(dst libfpg.Progress, containName string, regexName v *hscvrs.Version k bool - err liberr.Error + err error ) if s.regex == "" { @@ -171,11 +170,11 @@ func (s *s3awsModel) Download(dst libfpg.Progress, containName string, regexName grp := r.FindStringSubmatch(o) if len(grp) < s.group { - return ErrorS3AWSRegex.ErrorParent(getError(errRegexGroup, s.regex, len(grp), s.group)) + return ErrorS3AWSRegex.Error(getError(errRegexGroup, s.regex, len(grp), s.group)) } if v, e = hscvrs.NewVersion(grp[s.group]); e != nil { - return ErrorS3AWSNewVers.ErrorParent(getError(errVersion, grp[s.group]), e) + return ErrorS3AWSNewVers.Error(getError(errVersion, grp[s.group]), e) } else if v.Equal(release) { if containName != "" && strings.Contains(o, containName) { return s.downloadObject(dst, o) @@ -193,17 +192,17 @@ func (s *s3awsModel) Download(dst libfpg.Progress, containName string, regexName } } - return ErrorS3AWSNotFound.ErrorParent(getError(errVersRequest, release.String())) + return ErrorS3AWSNotFound.Error(getError(errVersRequest, release.String())) } -func (s *s3awsModel) downloadObject(dst libfpg.Progress, object string) liberr.Error { +func (s *s3awsModel) downloadObject(dst libfpg.Progress, object string) error { var ( r *sdksss.GetObjectOutput e error j int64 n int64 - err liberr.Error + err error ) defer func() { @@ -213,25 +212,25 @@ func (s *s3awsModel) downloadObject(dst libfpg.Progress, object string) liberr.E }() if j, err = s.c.Object().Size(object); err != nil { - err = ErrorS3AWSDownloadError.ErrorParent(getError(errObject, object)) - err.AddParentError(err) - return err + er := ErrorS3AWSDownloadError.Error(getError(errObject, object)) + er.Add(err) + return er } else if j < 1 { - return ErrorS3AWSDownloadError.ErrorParent(getError(errObjectEmpty, object)) + return ErrorS3AWSDownloadError.Error(getError(errObjectEmpty, object)) } else { dst.Reset(j) } if r, err = s.c.Object().Get(object); err != nil { - err = ErrorS3AWSDownloadError.ErrorParent(getError(errObject, object)) - err.AddParentError(err) - return err + er := ErrorS3AWSDownloadError.Error(getError(errObject, object)) + er.Add(err) + return er } else if r.Body == nil { - return ErrorS3AWSIOReaderError.ErrorParent(getError(errObject, object)) + return ErrorS3AWSIOReaderError.Error(getError(errObject, object)) } else if n, e = io.Copy(dst, r.Body); e != nil { - return ErrorS3AWSDownloadError.ErrorParent(getError(errObject, object), e) + return ErrorS3AWSDownloadError.Error(getError(errObject, object), e) } else if n != j { - return ErrorS3AWSDownloadError.ErrorParent(getError(errObjectSize, object)) + return ErrorS3AWSDownloadError.Error(getError(errObjectSize, object)) } return nil diff --git a/artifact/s3aws/s3aws.go b/artifact/s3aws/s3aws.go index 45876eb2..c95a0684 100644 --- a/artifact/s3aws/s3aws.go +++ b/artifact/s3aws/s3aws.go @@ -32,13 +32,12 @@ import ( libart "github.com/nabbar/golib/artifact" artcli "github.com/nabbar/golib/artifact/client" libaws "github.com/nabbar/golib/aws" - liberr "github.com/nabbar/golib/errors" ) -func NewS3AWS(ctx context.Context, cfg libaws.Config, httpcli *http.Client, forceModePath bool, releaseRegex string, releaseGroup int) (cli libart.Client, err liberr.Error) { +func NewS3AWS(ctx context.Context, cfg libaws.Config, httpcli *http.Client, forceModePath bool, releaseRegex string, releaseGroup int) (cli libart.Client, err error) { var ( c libaws.AWS - e liberr.Error + e error ) if c, e = libaws.New(ctx, cfg, httpcli); e != nil { diff --git a/aws/bucket/acl.go b/aws/bucket/acl.go index db3b9f9b..b0b993ea 100644 --- a/aws/bucket/acl.go +++ b/aws/bucket/acl.go @@ -26,11 +26,10 @@ package bucket import ( - adkaws "github.com/aws/aws-sdk-go-v2/aws" + sdkaws "github.com/aws/aws-sdk-go-v2/aws" sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) type ACLHeader uint8 @@ -49,7 +48,7 @@ type ACLHeaders map[ACLHeader]string // for GetACL // see : https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketAcl.html -func (cli *client) GetACL() (*sdkstp.AccessControlPolicy, liberr.Error) { +func (cli *client) GetACL() (*sdkstp.AccessControlPolicy, error) { out, err := cli.s3.GetBucketAcl(cli.GetContext(), &sdksss.GetBucketAclInput{ Bucket: cli.GetBucketAws(), }) @@ -83,7 +82,7 @@ func (cli *client) GetACL() (*sdkstp.AccessControlPolicy, liberr.Error) { //example value : uri="http://acs.amazonaws.com/groups/s3/LogDelivery", emailAddress="xyz@amazon.com" // for more info, see : https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketAcl.html#API_PutBucketAcl_RequestSyntax -func (cli *client) SetACL(ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) liberr.Error { +func (cli *client) SetACL(ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) error { in := &sdksss.PutBucketAclInput{ Bucket: cli.GetBucketAws(), } @@ -91,7 +90,7 @@ func (cli *client) SetACL(ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.Buck return cli.setACLInput(in, ACP, cannedACL, header) } -func (cli *client) SetACLPolicy(ACP *sdkstp.AccessControlPolicy) liberr.Error { +func (cli *client) SetACLPolicy(ACP *sdkstp.AccessControlPolicy) error { in := &sdksss.PutBucketAclInput{ Bucket: cli.GetBucketAws(), } @@ -99,7 +98,7 @@ func (cli *client) SetACLPolicy(ACP *sdkstp.AccessControlPolicy) liberr.Error { return cli.setACLInput(in, ACP, "", nil) } -func (cli *client) SetACLHeader(cannedACL sdkstp.BucketCannedACL, header ACLHeaders) liberr.Error { +func (cli *client) SetACLHeader(cannedACL sdkstp.BucketCannedACL, header ACLHeaders) error { in := &sdksss.PutBucketAclInput{ Bucket: cli.GetBucketAws(), } @@ -107,7 +106,7 @@ func (cli *client) SetACLHeader(cannedACL sdkstp.BucketCannedACL, header ACLHead return cli.setACLInput(in, nil, cannedACL, header) } -func (cli *client) setACLInput(in *sdksss.PutBucketAclInput, ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) liberr.Error { +func (cli *client) setACLInput(in *sdksss.PutBucketAclInput, ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) error { if ACP != nil { in.AccessControlPolicy = ACP } @@ -120,15 +119,15 @@ func (cli *client) setACLInput(in *sdksss.PutBucketAclInput, ACP *sdkstp.AccessC for k, v := range header { switch k { case ACLHeaderFullControl: - in.GrantFullControl = adkaws.String(v) + in.GrantFullControl = sdkaws.String(v) case ACLHeaderRead: - in.GrantRead = adkaws.String(v) + in.GrantRead = sdkaws.String(v) case ACLHeaderWrite: - in.GrantWrite = adkaws.String(v) + in.GrantWrite = sdkaws.String(v) case ACLHeaderReadACP: - in.GrantReadACP = adkaws.String(v) + in.GrantReadACP = sdkaws.String(v) case ACLHeaderWriteACP: - in.GrantWriteACP = adkaws.String(v) + in.GrantWriteACP = sdkaws.String(v) } } } diff --git a/aws/bucket/bucket.go b/aws/bucket/bucket.go index b34b0358..30303ba5 100644 --- a/aws/bucket/bucket.go +++ b/aws/bucket/bucket.go @@ -31,10 +31,9 @@ import ( sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) Check() liberr.Error { +func (cli *client) Check() error { out, err := cli.s3.HeadBucket(cli.GetContext(), &sdksss.HeadBucketInput{ Bucket: cli.GetBucketAws(), }) @@ -43,21 +42,21 @@ func (cli *client) Check() liberr.Error { return cli.GetError(err) } else if out == nil { //nolint #goerr113 - return libhlp.ErrorBucketNotFound.ErrorParent(fmt.Errorf("bucket: %s", cli.GetBucketName())) + return libhlp.ErrorBucketNotFound.Error(fmt.Errorf("bucket: %s", cli.GetBucketName())) } return nil } -func (cli *client) Create(RegionConstraint string) liberr.Error { +func (cli *client) Create(RegionConstraint string) error { return cli._create(RegionConstraint, false) } -func (cli *client) CreateWithLock(RegionConstraint string) liberr.Error { +func (cli *client) CreateWithLock(RegionConstraint string) error { return cli._create(RegionConstraint, true) } -func (cli *client) _create(RegionConstraint string, lockEnable bool) liberr.Error { +func (cli *client) _create(RegionConstraint string, lockEnable bool) error { in := &sdksss.CreateBucketInput{ Bucket: cli.GetBucketAws(), CreateBucketConfiguration: &sdkstp.CreateBucketConfiguration{}, @@ -83,7 +82,7 @@ func (cli *client) _create(RegionConstraint string, lockEnable bool) liberr.Erro } -func (cli *client) Delete() liberr.Error { +func (cli *client) Delete() error { _, err := cli.s3.DeleteBucket(cli.GetContext(), &sdksss.DeleteBucketInput{ Bucket: cli.GetBucketAws(), }) @@ -91,7 +90,7 @@ func (cli *client) Delete() liberr.Error { return cli.GetError(err) } -func (cli *client) List() ([]sdkstp.Bucket, liberr.Error) { +func (cli *client) List() ([]sdkstp.Bucket, error) { out, err := cli.s3.ListBuckets(cli.GetContext(), nil) if err != nil { @@ -103,7 +102,7 @@ func (cli *client) List() ([]sdkstp.Bucket, liberr.Error) { return out.Buckets, nil } -func (cli *client) Walk(f WalkFunc) liberr.Error { +func (cli *client) Walk(f WalkFunc) error { out, err := cli.s3.ListBuckets(cli.GetContext(), nil) if err != nil { @@ -112,7 +111,7 @@ func (cli *client) Walk(f WalkFunc) liberr.Error { return libhlp.ErrorAwsEmpty.Error(nil) } - var e liberr.Error + var e error for _, b := range out.Buckets { if b.Name == nil || b.CreationDate == nil || len(*b.Name) < 3 || b.CreationDate.IsZero() { continue diff --git a/aws/bucket/cors.go b/aws/bucket/cors.go index c23d1ab4..b7155a19 100644 --- a/aws/bucket/cors.go +++ b/aws/bucket/cors.go @@ -29,10 +29,9 @@ import ( sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) GetCORS() ([]sdkstp.CORSRule, liberr.Error) { +func (cli *client) GetCORS() ([]sdkstp.CORSRule, error) { out, err := cli.s3.GetBucketCors(cli.GetContext(), &sdksss.GetBucketCorsInput{ Bucket: cli.GetBucketAws(), }) @@ -49,7 +48,7 @@ func (cli *client) GetCORS() ([]sdkstp.CORSRule, liberr.Error) { return out.CORSRules, nil } -func (cli *client) SetCORS(cors []sdkstp.CORSRule) liberr.Error { +func (cli *client) SetCORS(cors []sdkstp.CORSRule) error { _, err := cli.s3.PutBucketCors(cli.GetContext(), &sdksss.PutBucketCorsInput{ Bucket: cli.GetBucketAws(), CORSConfiguration: &sdkstp.CORSConfiguration{ diff --git a/aws/bucket/interface.go b/aws/bucket/interface.go index ad40cd44..67bf34e7 100644 --- a/aws/bucket/interface.go +++ b/aws/bucket/interface.go @@ -32,7 +32,6 @@ import ( sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) type client struct { @@ -41,41 +40,41 @@ type client struct { s3 *sdksss.Client } -type WalkFunc func(err liberr.Error, bucket sdkstp.Bucket) liberr.Error +type WalkFunc func(err error, bucket sdkstp.Bucket) error type Bucket interface { - Check() liberr.Error + Check() error - List() ([]sdkstp.Bucket, liberr.Error) - Walk(f WalkFunc) liberr.Error - Create(RegionConstraint string) liberr.Error - CreateWithLock(RegionConstraint string) liberr.Error - Delete() liberr.Error + List() ([]sdkstp.Bucket, error) + Walk(f WalkFunc) error + Create(RegionConstraint string) error + CreateWithLock(RegionConstraint string) error + Delete() error //FindObject(pattern string) ([]string, errors.Error) - SetVersioning(state bool) liberr.Error - GetVersioning() (string, liberr.Error) + SetVersioning(state bool) error + GetVersioning() (string, error) - LoadReplication() (*sdkstp.ReplicationConfiguration, liberr.Error) - EnableReplication(srcRoleARN, dstRoleARN, dstBucketName string) liberr.Error - DeleteReplication() liberr.Error + LoadReplication() (*sdkstp.ReplicationConfiguration, error) + EnableReplication(srcRoleARN, dstRoleARN, dstBucketName string) error + DeleteReplication() error - PutWebsite(index, error string) liberr.Error - GetWebsite() (*sdksss.GetBucketWebsiteOutput, liberr.Error) + PutWebsite(index, error string) error + GetWebsite() (*sdksss.GetBucketWebsiteOutput, error) - SetCORS(cors []sdkstp.CORSRule) liberr.Error - GetCORS() ([]sdkstp.CORSRule, liberr.Error) + SetCORS(cors []sdkstp.CORSRule) error + GetCORS() ([]sdkstp.CORSRule, error) - GetACL() (*sdkstp.AccessControlPolicy, liberr.Error) - SetACL(ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) liberr.Error - SetACLPolicy(ACP *sdkstp.AccessControlPolicy) liberr.Error - SetACLHeader(cannedACL sdkstp.BucketCannedACL, header ACLHeaders) liberr.Error + GetACL() (*sdkstp.AccessControlPolicy, error) + SetACL(ACP *sdkstp.AccessControlPolicy, cannedACL sdkstp.BucketCannedACL, header ACLHeaders) error + SetACLPolicy(ACP *sdkstp.AccessControlPolicy) error + SetACLHeader(cannedACL sdkstp.BucketCannedACL, header ACLHeaders) error - GetLifeCycle() ([]sdkstp.LifecycleRule, liberr.Error) - SetLifeCycle(rules ...sdkstp.LifecycleRule) liberr.Error - GetLock() (*sdkstp.ObjectLockConfiguration, liberr.Error) - SetLock(cfg sdkstp.ObjectLockConfiguration, token string) liberr.Error + GetLifeCycle() ([]sdkstp.LifecycleRule, error) + SetLifeCycle(rules ...sdkstp.LifecycleRule) error + GetLock() (*sdkstp.ObjectLockConfiguration, error) + SetLock(cfg sdkstp.ObjectLockConfiguration, token string) error } func New(ctx context.Context, bucket, region string, iam *sdkiam.Client, s3 *sdksss.Client) Bucket { diff --git a/aws/bucket/lifecycle.go b/aws/bucket/lifecycle.go index e13db39d..2163772b 100644 --- a/aws/bucket/lifecycle.go +++ b/aws/bucket/lifecycle.go @@ -33,10 +33,9 @@ import ( sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) GetLifeCycle() ([]sdkstp.LifecycleRule, liberr.Error) { +func (cli *client) GetLifeCycle() ([]sdkstp.LifecycleRule, error) { out, err := cli.s3.GetBucketLifecycleConfiguration(cli.GetContext(), &sdksss.GetBucketLifecycleConfigurationInput{ Bucket: cli.GetBucketAws(), }) @@ -45,13 +44,13 @@ func (cli *client) GetLifeCycle() ([]sdkstp.LifecycleRule, liberr.Error) { return nil, cli.GetError(err) } else if out == nil { //nolint #goerr113 - return nil, libhlp.ErrorBucketNotFound.ErrorParent(fmt.Errorf("bucket: %s", cli.GetBucketName())) + return nil, libhlp.ErrorBucketNotFound.Error(fmt.Errorf("bucket: %s", cli.GetBucketName())) } return out.Rules, nil } -func (cli *client) SetLifeCycle(rules ...sdkstp.LifecycleRule) liberr.Error { +func (cli *client) SetLifeCycle(rules ...sdkstp.LifecycleRule) error { out, err := cli.s3.PutBucketLifecycleConfiguration(cli.GetContext(), &sdksss.PutBucketLifecycleConfigurationInput{ Bucket: cli.GetBucketAws(), LifecycleConfiguration: &sdkstp.BucketLifecycleConfiguration{ @@ -63,13 +62,13 @@ func (cli *client) SetLifeCycle(rules ...sdkstp.LifecycleRule) liberr.Error { return cli.GetError(err) } else if out == nil { //nolint #goerr113 - return libhlp.ErrorBucketNotFound.ErrorParent(fmt.Errorf("bucket: %s", cli.GetBucketName())) + return libhlp.ErrorBucketNotFound.Error(fmt.Errorf("bucket: %s", cli.GetBucketName())) } return nil } -func (cli *client) GetLock() (*sdkstp.ObjectLockConfiguration, liberr.Error) { +func (cli *client) GetLock() (*sdkstp.ObjectLockConfiguration, error) { out, err := cli.s3.GetObjectLockConfiguration(cli.GetContext(), &sdksss.GetObjectLockConfigurationInput{ Bucket: cli.GetBucketAws(), }) @@ -78,13 +77,13 @@ func (cli *client) GetLock() (*sdkstp.ObjectLockConfiguration, liberr.Error) { return nil, cli.GetError(err) } else if out == nil { //nolint #goerr113 - return nil, libhlp.ErrorBucketNotFound.ErrorParent(fmt.Errorf("bucket: %s", cli.GetBucketName())) + return nil, libhlp.ErrorBucketNotFound.Error(fmt.Errorf("bucket: %s", cli.GetBucketName())) } return out.ObjectLockConfiguration, nil } -func (cli *client) SetLock(cfg sdkstp.ObjectLockConfiguration, token string) liberr.Error { +func (cli *client) SetLock(cfg sdkstp.ObjectLockConfiguration, token string) error { in := &sdksss.PutObjectLockConfigurationInput{ Bucket: cli.GetBucketAws(), ObjectLockConfiguration: &cfg, @@ -100,7 +99,7 @@ func (cli *client) SetLock(cfg sdkstp.ObjectLockConfiguration, token string) lib return cli.GetError(err) } else if out == nil { //nolint #goerr113 - return libhlp.ErrorBucketNotFound.ErrorParent(fmt.Errorf("bucket: %s", cli.GetBucketName())) + return libhlp.ErrorBucketNotFound.Error(fmt.Errorf("bucket: %s", cli.GetBucketName())) } return nil diff --git a/aws/bucket/replication.go b/aws/bucket/replication.go index 824e97bd..f33fc6b7 100644 --- a/aws/bucket/replication.go +++ b/aws/bucket/replication.go @@ -30,10 +30,9 @@ import ( sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) LoadReplication() (*sdkstp.ReplicationConfiguration, liberr.Error) { +func (cli *client) LoadReplication() (*sdkstp.ReplicationConfiguration, error) { in := sdksss.GetBucketReplicationInput{ Bucket: cli.GetBucketAws(), } @@ -49,7 +48,7 @@ func (cli *client) LoadReplication() (*sdkstp.ReplicationConfiguration, liberr.E } } -func (cli *client) EnableReplication(srcRoleARN, dstRoleARN, dstBucketName string) liberr.Error { +func (cli *client) EnableReplication(srcRoleARN, dstRoleARN, dstBucketName string) error { var status sdkstp.ReplicationRuleStatus = libhlp.STATE_ENABLED _, err := cli.s3.PutBucketReplication(cli.GetContext(), &sdksss.PutBucketReplicationInput{ @@ -71,7 +70,7 @@ func (cli *client) EnableReplication(srcRoleARN, dstRoleARN, dstBucketName strin return cli.GetError(err) } -func (cli *client) DeleteReplication() liberr.Error { +func (cli *client) DeleteReplication() error { _, err := cli.s3.DeleteBucketReplication(cli.GetContext(), &sdksss.DeleteBucketReplicationInput{ Bucket: cli.GetBucketAws(), }) diff --git a/aws/bucket/version.go b/aws/bucket/version.go index 647b95d6..69ae2a66 100644 --- a/aws/bucket/version.go +++ b/aws/bucket/version.go @@ -29,10 +29,9 @@ import ( sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) SetVersioning(state bool) liberr.Error { +func (cli *client) SetVersioning(state bool) error { var status sdkstp.BucketVersioningStatus = libhlp.STATE_ENABLED if !state { status = libhlp.STATE_SUSPENDED @@ -48,7 +47,7 @@ func (cli *client) SetVersioning(state bool) liberr.Error { return cli.GetError(err) } -func (cli *client) GetVersioning() (string, liberr.Error) { +func (cli *client) GetVersioning() (string, error) { out, err := cli.s3.GetBucketVersioning(cli.GetContext(), &sdksss.GetBucketVersioningInput{ Bucket: cli.GetBucketAws(), }) diff --git a/aws/bucket/website.go b/aws/bucket/website.go index 1090ad1d..f702e983 100644 --- a/aws/bucket/website.go +++ b/aws/bucket/website.go @@ -30,10 +30,9 @@ import ( sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdkstp "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) PutWebsite(index, error string) liberr.Error { +func (cli *client) PutWebsite(index, error string) error { _, err := cli.s3.PutBucketWebsite(cli.GetContext(), &sdksss.PutBucketWebsiteInput{ Bucket: cli.GetBucketAws(), WebsiteConfiguration: &sdkstp.WebsiteConfiguration{ @@ -49,7 +48,7 @@ func (cli *client) PutWebsite(index, error string) liberr.Error { return cli.GetError(err) } -func (cli *client) GetWebsite() (*sdksss.GetBucketWebsiteOutput, liberr.Error) { +func (cli *client) GetWebsite() (*sdksss.GetBucketWebsiteOutput, error) { out, err := cli.s3.GetBucketWebsite(cli.GetContext(), &sdksss.GetBucketWebsiteInput{ Bucket: cli.GetBucketAws(), }) diff --git a/aws/configAws/interface.go b/aws/configAws/interface.go index 58e98366..1d8a566c 100644 --- a/aws/configAws/interface.go +++ b/aws/configAws/interface.go @@ -34,17 +34,16 @@ import ( sdkcfg "github.com/aws/aws-sdk-go-v2/config" sdkcrd "github.com/aws/aws-sdk-go-v2/credentials" libaws "github.com/nabbar/golib/aws" - "github.com/nabbar/golib/errors" ) func GetConfigModel() interface{} { return Model{} } -func NewConfigJsonUnmashal(p []byte) (libaws.Config, errors.Error) { +func NewConfigJsonUnmashal(p []byte) (libaws.Config, error) { c := Model{} if err := json.Unmarshal(p, &c); err != nil { - return nil, ErrorConfigJsonUnmarshall.ErrorParent(err) + return nil, ErrorConfigJsonUnmarshall.Error(err) } return &awsModel{ @@ -53,10 +52,10 @@ func NewConfigJsonUnmashal(p []byte) (libaws.Config, errors.Error) { }, nil } -func NewConfigStatusJsonUnmashal(p []byte) (libaws.Config, errors.Error) { +func NewConfigStatusJsonUnmashal(p []byte) (libaws.Config, error) { c := ModelStatus{} if err := json.Unmarshal(p, &c); err != nil { - return nil, ErrorConfigJsonUnmarshall.ErrorParent(err) + return nil, ErrorConfigJsonUnmarshall.Error(err) } return &awsModel{ @@ -89,14 +88,14 @@ func (c *awsModel) Clone() libaws.Config { } } -func (c *awsModel) GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, errors.Error) { +func (c *awsModel) GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, error) { var ( cfg sdkaws.Config err error ) if cfg, err = sdkcfg.LoadDefaultConfig(ctx); err != nil { - return nil, ErrorConfigLoader.ErrorParent(err) + return nil, ErrorConfigLoader.Error(err) } if c.AccessKey != "" && c.SecretKey != "" { diff --git a/aws/configAws/models.go b/aws/configAws/models.go index 26c8ab86..56cb89c7 100644 --- a/aws/configAws/models.go +++ b/aws/configAws/models.go @@ -31,12 +31,10 @@ import ( "net" "net/url" - libreq "github.com/nabbar/golib/request" - sdkaws "github.com/aws/aws-sdk-go-v2/aws" libval "github.com/go-playground/validator/v10" - liberr "github.com/nabbar/golib/errors" libhtc "github.com/nabbar/golib/httpcli" + libreq "github.com/nabbar/golib/request" ) type Model struct { @@ -57,17 +55,17 @@ type awsModel struct { retryer func() sdkaws.Retryer } -func (c *awsModel) Validate() liberr.Error { +func (c *awsModel) Validate() error { err := ErrorConfigValidator.Error(nil) if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag())) } } @@ -90,11 +88,11 @@ func (c *awsModel) SetCredentials(accessKey, secretKey string) { func (c *awsModel) ResetRegionEndpoint() { } -func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) liberr.Error { +func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) error { return nil } -func (c *awsModel) RegisterRegionAws(endpoint *url.URL) liberr.Error { +func (c *awsModel) RegisterRegionAws(endpoint *url.URL) error { return nil } @@ -137,14 +135,14 @@ func (c *awsModel) SetRetryer(retryer func() sdkaws.Retryer) { c.retryer = retryer } -func (c *awsModel) Check(ctx context.Context) liberr.Error { +func (c *awsModel) Check(ctx context.Context) error { var ( cfg *sdkaws.Config con net.Conn end sdkaws.Endpoint adr *url.URL err error - e liberr.Error + e error ) if cfg, e = c.GetConfig(ctx, nil); e != nil { @@ -156,15 +154,15 @@ func (c *awsModel) Check(ctx context.Context) liberr.Error { } if end, err = cfg.EndpointResolverWithOptions.ResolveEndpoint("s3", c.GetRegion()); err != nil { - return ErrorEndpointInvalid.ErrorParent(err) + return ErrorEndpointInvalid.Error(err) } if adr, err = url.Parse(end.URL); err != nil { - return ErrorEndpointInvalid.ErrorParent(err) + return ErrorEndpointInvalid.Error(err) } if _, err = cfg.Credentials.Retrieve(ctx); err != nil { - return ErrorCredentialsInvalid.ErrorParent(err) + return ErrorCredentialsInvalid.Error(err) } d := net.Dialer{ @@ -181,7 +179,7 @@ func (c *awsModel) Check(ctx context.Context) liberr.Error { }() if err != nil { - return ErrorEndpointInvalid.ErrorParent(err) + return ErrorEndpointInvalid.Error(err) } return nil diff --git a/aws/configCustom/interface.go b/aws/configCustom/interface.go index 09ff8424..174399e9 100644 --- a/aws/configCustom/interface.go +++ b/aws/configCustom/interface.go @@ -35,17 +35,16 @@ import ( sdkaws "github.com/aws/aws-sdk-go-v2/aws" sdkcrd "github.com/aws/aws-sdk-go-v2/credentials" libaws "github.com/nabbar/golib/aws" - liberr "github.com/nabbar/golib/errors" ) func GetConfigModel() interface{} { return Model{} } -func NewConfigJsonUnmashal(p []byte) (libaws.Config, liberr.Error) { +func NewConfigJsonUnmashal(p []byte) (libaws.Config, error) { c := Model{} if err := json.Unmarshal(p, &c); err != nil { - return nil, ErrorConfigJsonUnmarshall.ErrorParent(err) + return nil, ErrorConfigJsonUnmarshall.Error(err) } return &awsModel{ @@ -55,10 +54,10 @@ func NewConfigJsonUnmashal(p []byte) (libaws.Config, liberr.Error) { }, nil } -func NewConfigStatusJsonUnmashal(p []byte) (libaws.Config, liberr.Error) { +func NewConfigStatusJsonUnmashal(p []byte) (libaws.Config, error) { c := ModelStatus{} if err := json.Unmarshal(p, &c); err != nil { - return nil, ErrorConfigJsonUnmarshall.ErrorParent(err) + return nil, ErrorConfigJsonUnmarshall.Error(err) } return &awsModel{ @@ -104,7 +103,7 @@ func (c *awsModel) Clone() libaws.Config { } } -func (c *awsModel) GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, liberr.Error) { +func (c *awsModel) GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, error) { cfg := sdkaws.NewConfig() diff --git a/aws/configCustom/models.go b/aws/configCustom/models.go index 0dc6f02e..4c5c333a 100644 --- a/aws/configCustom/models.go +++ b/aws/configCustom/models.go @@ -34,7 +34,6 @@ import ( sdkaws "github.com/aws/aws-sdk-go-v2/aws" libval "github.com/go-playground/validator/v10" - liberr "github.com/nabbar/golib/errors" libhtc "github.com/nabbar/golib/httpcli" libreq "github.com/nabbar/golib/request" ) @@ -61,26 +60,26 @@ type awsModel struct { mapRegion map[string]*url.URL } -func (c *awsModel) Validate() liberr.Error { +func (c *awsModel) Validate() error { err := ErrorConfigValidator.Error(nil) if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag())) } } if c.Endpoint != "" && c.endpoint == nil { var e error if c.endpoint, e = url.Parse(c.Endpoint); e != nil { - err.AddParent(e) + err.Add(e) } else if er := c.RegisterRegionAws(c.endpoint); er != nil { - err.AddParentError(er) + err.Add(er) } } else if !err.HasParent() && c.endpoint != nil && c.Endpoint == "" { c.Endpoint = c.endpoint.String() @@ -88,7 +87,7 @@ func (c *awsModel) Validate() liberr.Error { if !err.HasParent() && c.endpoint != nil && c.Region != "" { if e := c.RegisterRegionEndpoint("", c.endpoint); e != nil { - err.AddParentError(e) + err.Add(e) } } @@ -112,13 +111,13 @@ func (c *awsModel) ResetRegionEndpoint() { c.mapRegion = make(map[string]*url.URL) } -func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) liberr.Error { +func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) error { if endpoint == nil && c.endpoint != nil { endpoint = c.endpoint } else if endpoint == nil && c.Endpoint != "" { var err error if endpoint, err = url.Parse(c.Endpoint); err != nil { - return ErrorEndpointInvalid.ErrorParent(err) + return ErrorEndpointInvalid.Error(err) } } @@ -133,9 +132,9 @@ func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) libe val := libval.New() if err := val.Var(endpoint, "url,required"); err != nil { - return ErrorEndpointInvalid.ErrorParent(err) + return ErrorEndpointInvalid.Error(err) } else if err := val.Var(region, "printascii,required"); err != nil { - return ErrorRegionInvalid.ErrorParent(err) + return ErrorRegionInvalid.Error(err) } if c.mapRegion == nil { @@ -147,13 +146,13 @@ func (c *awsModel) RegisterRegionEndpoint(region string, endpoint *url.URL) libe return nil } -func (c *awsModel) RegisterRegionAws(endpoint *url.URL) liberr.Error { +func (c *awsModel) RegisterRegionAws(endpoint *url.URL) error { if endpoint == nil && c.endpoint != nil { endpoint = c.endpoint } else if endpoint == nil && c.Endpoint != "" { var err error if endpoint, err = url.Parse(c.Endpoint); err != nil { - return ErrorEndpointInvalid.ErrorParent(err) + return ErrorEndpointInvalid.Error(err) } } @@ -163,7 +162,7 @@ func (c *awsModel) RegisterRegionAws(endpoint *url.URL) liberr.Error { val := libval.New() if err := val.Var(endpoint, "url,required"); err != nil { - return ErrorEndpointInvalid.ErrorParent(err) + return ErrorEndpointInvalid.Error(err) } if c.Region == "" { @@ -264,12 +263,12 @@ func (c *awsModel) SetRetryer(retryer func() sdkaws.Retryer) { c.retryer = retryer } -func (c *awsModel) Check(ctx context.Context) liberr.Error { +func (c *awsModel) Check(ctx context.Context) error { var ( cfg *sdkaws.Config con net.Conn err error - e liberr.Error + e error ) if cfg, e = c.GetConfig(ctx, nil); e != nil { @@ -281,11 +280,11 @@ func (c *awsModel) Check(ctx context.Context) liberr.Error { } if _, err = cfg.EndpointResolverWithOptions.ResolveEndpoint("s3", c.GetRegion()); err != nil { - return ErrorEndpointInvalid.ErrorParent(err) + return ErrorEndpointInvalid.Error(err) } if _, err = cfg.Credentials.Retrieve(ctx); err != nil { - return ErrorCredentialsInvalid.ErrorParent(err) + return ErrorCredentialsInvalid.Error(err) } d := net.Dialer{ @@ -308,7 +307,7 @@ func (c *awsModel) Check(ctx context.Context) liberr.Error { }() if err != nil { - return ErrorEndpointInvalid.ErrorParent(err) + return ErrorEndpointInvalid.Error(err) } return nil diff --git a/aws/group/group.go b/aws/group/group.go index 1c336b44..2a6293f3 100644 --- a/aws/group/group.go +++ b/aws/group/group.go @@ -26,13 +26,12 @@ package group import ( - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/iam" - "github.com/nabbar/golib/errors" + sdkaws "github.com/aws/aws-sdk-go-v2/aws" + sdkiam "github.com/aws/aws-sdk-go-v2/service/iam" ) -func (cli *client) List() (map[string]string, errors.Error) { - if out, err := cli.iam.ListGroups(cli.GetContext(), &iam.ListGroupsInput{}); err != nil { +func (cli *client) List() (map[string]string, error) { + if out, err := cli.iam.ListGroups(cli.GetContext(), &sdkiam.ListGroupsInput{}); err != nil { return nil, cli.GetError(err) } else { var res = make(map[string]string) @@ -45,17 +44,17 @@ func (cli *client) List() (map[string]string, errors.Error) { } } -func (cli *client) Add(groupName string) errors.Error { - _, err := cli.iam.CreateGroup(cli.GetContext(), &iam.CreateGroupInput{ - GroupName: aws.String(groupName), +func (cli *client) Add(groupName string) error { + _, err := cli.iam.CreateGroup(cli.GetContext(), &sdkiam.CreateGroupInput{ + GroupName: sdkaws.String(groupName), }) return cli.GetError(err) } -func (cli *client) Remove(groupName string) errors.Error { - _, err := cli.iam.DeleteGroup(cli.GetContext(), &iam.DeleteGroupInput{ - GroupName: aws.String(groupName), +func (cli *client) Remove(groupName string) error { + _, err := cli.iam.DeleteGroup(cli.GetContext(), &sdkiam.DeleteGroupInput{ + GroupName: sdkaws.String(groupName), }) return cli.GetError(err) diff --git a/aws/group/interface.go b/aws/group/interface.go index 9795a266..a0eef466 100644 --- a/aws/group/interface.go +++ b/aws/group/interface.go @@ -32,7 +32,6 @@ import ( sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types" sdksss "github.com/aws/aws-sdk-go-v2/service/s3" awshlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) type client struct { @@ -41,23 +40,23 @@ type client struct { s3 *sdksss.Client } -type PoliciesWalkFunc func(err liberr.Error, pol sdktps.AttachedPolicy) liberr.Error +type PoliciesWalkFunc func(err error, pol sdktps.AttachedPolicy) error type Group interface { - UserList(username string) ([]string, liberr.Error) - UserCheck(username, groupName string) (liberr.Error, bool) - UserAdd(username, groupName string) liberr.Error - UserRemove(username, groupName string) liberr.Error + UserList(username string) ([]string, error) + UserCheck(username, groupName string) (error, bool) + UserAdd(username, groupName string) error + UserRemove(username, groupName string) error - List() (map[string]string, liberr.Error) - Add(groupName string) liberr.Error - Remove(groupName string) liberr.Error + List() (map[string]string, error) + Add(groupName string) error + Remove(groupName string) error - PolicyList(groupName string) (map[string]string, liberr.Error) - PolicyAttach(groupName, polArn string) liberr.Error - PolicyDetach(groupName, polArn string) liberr.Error - PolicyAttachedList(groupName, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error) - PolicyAttachedWalk(groupName string, fct PoliciesWalkFunc) liberr.Error + PolicyList(groupName string) (map[string]string, error) + PolicyAttach(groupName, polArn string) error + PolicyDetach(groupName, polArn string) error + PolicyAttachedList(groupName, marker string) ([]sdktps.AttachedPolicy, string, error) + PolicyAttachedWalk(groupName string, fct PoliciesWalkFunc) error } func New(ctx context.Context, bucket, region string, iam *sdkiam.Client, s3 *sdksss.Client) Group { diff --git a/aws/group/policy.go b/aws/group/policy.go index 78db5e9e..2b45f3f8 100644 --- a/aws/group/policy.go +++ b/aws/group/policy.go @@ -29,10 +29,9 @@ import ( sdkaws "github.com/aws/aws-sdk-go-v2/aws" sdkiam "github.com/aws/aws-sdk-go-v2/service/iam" sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) PolicyList(groupName string) (map[string]string, liberr.Error) { +func (cli *client) PolicyList(groupName string) (map[string]string, error) { out, _, err := cli.PolicyAttachedList(groupName, "") if err != nil { @@ -48,7 +47,7 @@ func (cli *client) PolicyList(groupName string) (map[string]string, liberr.Error } } -func (cli *client) PolicyAttach(groupName, polArn string) liberr.Error { +func (cli *client) PolicyAttach(groupName, polArn string) error { _, err := cli.iam.AttachGroupPolicy(cli.GetContext(), &sdkiam.AttachGroupPolicyInput{ GroupName: sdkaws.String(groupName), PolicyArn: sdkaws.String(polArn), @@ -57,7 +56,7 @@ func (cli *client) PolicyAttach(groupName, polArn string) liberr.Error { return cli.GetError(err) } -func (cli *client) PolicyDetach(groupName, polArn string) liberr.Error { +func (cli *client) PolicyDetach(groupName, polArn string) error { _, err := cli.iam.DetachGroupPolicy(cli.GetContext(), &sdkiam.DetachGroupPolicyInput{ GroupName: sdkaws.String(groupName), PolicyArn: sdkaws.String(polArn), @@ -66,7 +65,7 @@ func (cli *client) PolicyDetach(groupName, polArn string) liberr.Error { return cli.GetError(err) } -func (cli *client) PolicyAttachedList(groupName, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error) { +func (cli *client) PolicyAttachedList(groupName, marker string) ([]sdktps.AttachedPolicy, string, error) { in := &sdkiam.ListAttachedGroupPoliciesInput{ GroupName: sdkaws.String(groupName), MaxItems: sdkaws.Int32(1000), @@ -89,7 +88,7 @@ func (cli *client) PolicyAttachedList(groupName, marker string) ([]sdktps.Attach } } -func (cli *client) PolicyAttachedWalk(groupName string, fct PoliciesWalkFunc) liberr.Error { +func (cli *client) PolicyAttachedWalk(groupName string, fct PoliciesWalkFunc) error { var m *string in := &sdkiam.ListAttachedGroupPoliciesInput{ @@ -112,7 +111,7 @@ func (cli *client) PolicyAttachedWalk(groupName string, fct PoliciesWalkFunc) li return nil } - var e liberr.Error + var e error for _, p := range lst.AttachedPolicies { e = fct(e, p) } diff --git a/aws/group/user.go b/aws/group/user.go index 2c21c178..0a2c200d 100644 --- a/aws/group/user.go +++ b/aws/group/user.go @@ -26,14 +26,13 @@ package group import ( - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/iam" - "github.com/nabbar/golib/errors" + sdkaws "github.com/aws/aws-sdk-go-v2/aws" + sdkiam "github.com/aws/aws-sdk-go-v2/service/iam" ) -func (cli *client) UserCheck(username, groupName string) (errors.Error, bool) { - out, err := cli.iam.ListGroupsForUser(cli.GetContext(), &iam.ListGroupsForUserInput{ - UserName: aws.String(username), +func (cli *client) UserCheck(username, groupName string) (error, bool) { + out, err := cli.iam.ListGroupsForUser(cli.GetContext(), &sdkiam.ListGroupsForUserInput{ + UserName: sdkaws.String(username), }) if err != nil { @@ -49,9 +48,9 @@ func (cli *client) UserCheck(username, groupName string) (errors.Error, bool) { return nil, false } -func (cli *client) UserList(username string) ([]string, errors.Error) { - out, err := cli.iam.ListGroupsForUser(cli.GetContext(), &iam.ListGroupsForUserInput{ - UserName: aws.String(username), +func (cli *client) UserList(username string) ([]string, error) { + out, err := cli.iam.ListGroupsForUser(cli.GetContext(), &sdkiam.ListGroupsForUserInput{ + UserName: sdkaws.String(username), }) if err != nil { @@ -67,19 +66,19 @@ func (cli *client) UserList(username string) ([]string, errors.Error) { } } -func (cli *client) UserAdd(username, groupName string) errors.Error { - _, err := cli.iam.AddUserToGroup(cli.GetContext(), &iam.AddUserToGroupInput{ - UserName: aws.String(username), - GroupName: aws.String(groupName), +func (cli *client) UserAdd(username, groupName string) error { + _, err := cli.iam.AddUserToGroup(cli.GetContext(), &sdkiam.AddUserToGroupInput{ + UserName: sdkaws.String(username), + GroupName: sdkaws.String(groupName), }) return cli.GetError(err) } -func (cli *client) UserRemove(username, groupName string) errors.Error { - _, err := cli.iam.RemoveUserFromGroup(cli.GetContext(), &iam.RemoveUserFromGroupInput{ - UserName: aws.String(username), - GroupName: aws.String(groupName), +func (cli *client) UserRemove(username, groupName string) error { + _, err := cli.iam.RemoveUserFromGroup(cli.GetContext(), &sdkiam.RemoveUserFromGroupInput{ + UserName: sdkaws.String(username), + GroupName: sdkaws.String(groupName), }) return cli.GetError(err) diff --git a/aws/helper/error.go b/aws/helper/error.go index 04d91bfc..58cab9c8 100644 --- a/aws/helper/error.go +++ b/aws/helper/error.go @@ -41,8 +41,6 @@ const ( ErrorParamsEmpty ) -var isErrInit = liberr.ExistInMapMessage(ErrorResponse) - func init() { if liberr.ExistInMapMessage(ErrorResponse) { panic(fmt.Errorf("error code collision with package golib/aws/helpers")) @@ -50,10 +48,6 @@ func init() { liberr.RegisterIdFctMessage(ErrorResponse, getMessage) } -func IsErrorInit() bool { - return isErrInit -} - func getMessage(code liberr.CodeError) string { switch code { case ErrorResponse: diff --git a/aws/helper/interface.go b/aws/helper/interface.go index 2052e0cd..f4ef9cc4 100644 --- a/aws/helper/interface.go +++ b/aws/helper/interface.go @@ -31,7 +31,6 @@ import ( "net/http" "github.com/aws/aws-sdk-go-v2/aws" - liberr "github.com/nabbar/golib/errors" ) const ( @@ -53,24 +52,12 @@ func New(ctx context.Context, bucket, region string) Helper { } } -func (cli Helper) GetError(err ...error) liberr.Error { - var er = ErrorAws.Error(nil) - - for _, e := range err { - if e == nil { - continue - } - if n, ok := e.(liberr.Error); ok { - er.AddParentError(n) - } else { - er.AddParent(e) - } +func (cli Helper) GetError(err ...error) error { + var e = ErrorAws.Error() + e.Add(err...) + if e.HasParent() { + return e } - - if er.HasParent() { - return er - } - return nil } diff --git a/aws/interface.go b/aws/interface.go index 96a82517..6545f1e6 100644 --- a/aws/interface.go +++ b/aws/interface.go @@ -42,18 +42,17 @@ import ( awspol "github.com/nabbar/golib/aws/policy" awsrol "github.com/nabbar/golib/aws/role" awsusr "github.com/nabbar/golib/aws/user" - liberr "github.com/nabbar/golib/errors" ) type Config interface { - Check(ctx context.Context) liberr.Error - Validate() liberr.Error + Check(ctx context.Context) error + Validate() error GetAccessKey() string SetCredentials(accessKey, secretKey string) ResetRegionEndpoint() - RegisterRegionEndpoint(region string, endpoint *url.URL) liberr.Error - RegisterRegionAws(endpoint *url.URL) liberr.Error + RegisterRegionEndpoint(region string, endpoint *url.URL) error + RegisterRegionAws(endpoint *url.URL) error SetRegion(region string) GetRegion() string SetEndpoint(endpoint *url.URL) @@ -66,7 +65,7 @@ type Config interface { GetResolvedRegion() string SetRetryer(retryer func() sdkaws.Retryer) - GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, liberr.Error) + GetConfig(ctx context.Context, cli *http.Client) (*sdkaws.Config, error) JSON() ([]byte, error) Clone() Config @@ -84,10 +83,10 @@ type AWS interface { Config() Config HTTPCli() *http.Client - Clone(ctx context.Context) (AWS, liberr.Error) - NewForConfig(ctx context.Context, cfg Config) (AWS, liberr.Error) - ForcePathStyle(ctx context.Context, enabled bool) liberr.Error - ForceSignerOptions(ctx context.Context, fct ...func(signer *sdksv4.SignerOptions)) liberr.Error + Clone(ctx context.Context) (AWS, error) + NewForConfig(ctx context.Context, cfg Config) (AWS, error) + ForcePathStyle(ctx context.Context, enabled bool) error + ForceSignerOptions(ctx context.Context, fct ...func(signer *sdksv4.SignerOptions)) error GetBucketName() string SetBucketName(bucket string) @@ -98,7 +97,7 @@ type AWS interface { SetClientIam(aws *sdkiam.Client) } -func New(ctx context.Context, cfg Config, httpClient *http.Client) (AWS, liberr.Error) { +func New(ctx context.Context, cfg Config, httpClient *http.Client) (AWS, error) { if cfg == nil { return nil, awshlp.ErrorConfigEmpty.Error(nil) } diff --git a/aws/model.go b/aws/model.go index d1346460..b0b0c9fc 100644 --- a/aws/model.go +++ b/aws/model.go @@ -40,7 +40,6 @@ import ( awspol "github.com/nabbar/golib/aws/policy" awsrol "github.com/nabbar/golib/aws/role" awsusr "github.com/nabbar/golib/aws/user" - liberr "github.com/nabbar/golib/errors" ) type client struct { @@ -54,11 +53,11 @@ type client struct { h *http.Client } -func (c *client) _NewClientIAM(ctx context.Context, httpClient *http.Client) (*sdkiam.Client, liberr.Error) { +func (c *client) _NewClientIAM(ctx context.Context, httpClient *http.Client) (*sdkiam.Client, error) { var ( cfg *sdkaws.Config iam *sdkiam.Client - err liberr.Error + err error ret sdkaws.Retryer sig *sdksv4.Signer ) @@ -97,10 +96,10 @@ func (c *client) _NewClientIAM(ctx context.Context, httpClient *http.Client) (*s return iam, nil } -func (c *client) _NewClientS3(ctx context.Context, httpClient *http.Client) (*sdksss.Client, liberr.Error) { +func (c *client) _NewClientS3(ctx context.Context, httpClient *http.Client) (*sdksss.Client, error) { var ( sss *sdksss.Client - err liberr.Error + err error ret sdkaws.Retryer cfg *sdkaws.Config sig *sdksv4.Signer @@ -141,7 +140,7 @@ func (c *client) _NewClientS3(ctx context.Context, httpClient *http.Client) (*sd return sss, nil } -func (c *client) NewForConfig(ctx context.Context, cfg Config) (AWS, liberr.Error) { +func (c *client) NewForConfig(ctx context.Context, cfg Config) (AWS, error) { c.m.Lock() defer c.m.Unlock() @@ -171,7 +170,7 @@ func (c *client) NewForConfig(ctx context.Context, cfg Config) (AWS, liberr.Erro return n, nil } -func (c *client) Clone(ctx context.Context) (AWS, liberr.Error) { +func (c *client) Clone(ctx context.Context) (AWS, error) { c.m.Lock() defer c.m.Unlock() @@ -205,7 +204,7 @@ func (c *client) Clone(ctx context.Context) (AWS, liberr.Error) { return n, nil } -func (c *client) ForcePathStyle(ctx context.Context, enabled bool) liberr.Error { +func (c *client) ForcePathStyle(ctx context.Context, enabled bool) error { c.m.Lock() defer c.m.Unlock() @@ -220,7 +219,7 @@ func (c *client) ForcePathStyle(ctx context.Context, enabled bool) liberr.Error return nil } -func (c *client) ForceSignerOptions(ctx context.Context, fct ...func(signer *sdksv4.SignerOptions)) liberr.Error { +func (c *client) ForceSignerOptions(ctx context.Context, fct ...func(signer *sdksv4.SignerOptions)) error { c.m.Lock() defer c.m.Unlock() diff --git a/aws/object/find.go b/aws/object/find.go index 1cfef802..145694d8 100644 --- a/aws/object/find.go +++ b/aws/object/find.go @@ -27,11 +27,9 @@ package object import ( "regexp" - - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) Find(regex string) ([]string, liberr.Error) { +func (cli *client) Find(regex string) ([]string, error) { var ( result = make([]string, 0) token = "" diff --git a/aws/object/interface.go b/aws/object/interface.go index 59e88569..e102c9ba 100644 --- a/aws/object/interface.go +++ b/aws/object/interface.go @@ -38,7 +38,6 @@ import ( sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) type client struct { @@ -47,52 +46,52 @@ type client struct { s3 *sdksss.Client } -type WalkFunc func(err liberr.Error, obj sdktps.Object) liberr.Error -type VersionWalkFunc func(err liberr.Error, obj sdktps.ObjectVersion) liberr.Error -type DelMakWalkFunc func(err liberr.Error, del sdktps.DeleteMarkerEntry) liberr.Error +type WalkFunc func(err error, obj sdktps.Object) error +type VersionWalkFunc func(err error, obj sdktps.ObjectVersion) error +type DelMakWalkFunc func(err error, del sdktps.DeleteMarkerEntry) error type Object interface { - Find(regex string) ([]string, liberr.Error) - Size(object string) (size int64, err liberr.Error) + Find(regex string) ([]string, error) + Size(object string) (size int64, err error) - List(continuationToken string) ([]sdktps.Object, string, int64, liberr.Error) - Walk(f WalkFunc) liberr.Error + List(continuationToken string) ([]sdktps.Object, string, int64, error) + Walk(f WalkFunc) error - ListPrefix(continuationToken string, prefix string) ([]sdktps.Object, string, int64, liberr.Error) - WalkPrefix(prefix string, f WalkFunc) liberr.Error + ListPrefix(continuationToken string, prefix string) ([]sdktps.Object, string, int64, error) + WalkPrefix(prefix string, f WalkFunc) error - Head(object string) (*sdksss.HeadObjectOutput, liberr.Error) - Get(object string) (*sdksss.GetObjectOutput, liberr.Error) - Put(object string, body io.Reader) liberr.Error - Delete(check bool, object string) liberr.Error - DeleteAll(objects *sdktps.Delete) ([]sdktps.DeletedObject, liberr.Error) - GetAttributes(object, version string) (*sdksss.GetObjectAttributesOutput, liberr.Error) + Head(object string) (*sdksss.HeadObjectOutput, error) + Get(object string) (*sdksss.GetObjectOutput, error) + Put(object string, body io.Reader) error + Delete(check bool, object string) error + DeleteAll(objects *sdktps.Delete) ([]sdktps.DeletedObject, error) + GetAttributes(object, version string) (*sdksss.GetObjectAttributesOutput, error) - MultipartList(keyMarker, markerId string) (uploads []sdktps.MultipartUpload, nextKeyMarker string, nextIdMarker string, count int64, e liberr.Error) + MultipartList(keyMarker, markerId string) (uploads []sdktps.MultipartUpload, nextKeyMarker string, nextIdMarker string, count int64, e error) MultipartNew(partSize libsiz.Size, object string) libmpu.MultiPart - MultipartPut(object string, body io.Reader) liberr.Error - MultipartPutCustom(partSize libsiz.Size, object string, body io.Reader) liberr.Error - MultipartCancel(uploadId, key string) liberr.Error + MultipartPut(object string, body io.Reader) error + MultipartPutCustom(partSize libsiz.Size, object string, body io.Reader) error + MultipartCancel(uploadId, key string) error - UpdateMetadata(meta *sdksss.CopyObjectInput) liberr.Error - SetWebsite(object, redirect string) liberr.Error + UpdateMetadata(meta *sdksss.CopyObjectInput) error + SetWebsite(object, redirect string) error - VersionList(prefix, keyMarker, markerId string) (version []sdktps.ObjectVersion, delMarker []sdktps.DeleteMarkerEntry, nextKeyMarker, nextMarkerId string, count int64, err liberr.Error) - VersionWalk(fv VersionWalkFunc, fd DelMakWalkFunc) liberr.Error - VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMakWalkFunc) liberr.Error + VersionList(prefix, keyMarker, markerId string) (version []sdktps.ObjectVersion, delMarker []sdktps.DeleteMarkerEntry, nextKeyMarker, nextMarkerId string, count int64, err error) + VersionWalk(fv VersionWalkFunc, fd DelMakWalkFunc) error + VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMakWalkFunc) error - VersionGet(object, version string) (*sdksss.GetObjectOutput, liberr.Error) - VersionHead(object, version string) (*sdksss.HeadObjectOutput, liberr.Error) - VersionSize(object, version string) (size int64, err liberr.Error) - VersionDelete(check bool, object, version string) liberr.Error + VersionGet(object, version string) (*sdksss.GetObjectOutput, error) + VersionHead(object, version string) (*sdksss.HeadObjectOutput, error) + VersionSize(object, version string) (size int64, err error) + VersionDelete(check bool, object, version string) error - GetRetention(object, version string) (until time.Time, mode string, err liberr.Error) - SetRetention(object, version string, bypass bool, until time.Time, mode string) liberr.Error - GetLegalHold(object, version string) (sdktps.ObjectLockLegalHoldStatus, liberr.Error) - SetLegalHold(object, version string, flag sdktps.ObjectLockLegalHoldStatus) liberr.Error + GetRetention(object, version string) (until time.Time, mode string, err error) + SetRetention(object, version string, bypass bool, until time.Time, mode string) error + GetLegalHold(object, version string) (sdktps.ObjectLockLegalHoldStatus, error) + SetLegalHold(object, version string, flag sdktps.ObjectLockLegalHoldStatus) error - GetTags(object, version string) ([]sdktps.Tag, liberr.Error) - SetTags(object, version string, tags ...sdktps.Tag) liberr.Error + GetTags(object, version string) ([]sdktps.Tag, error) + SetTags(object, version string, tags ...sdktps.Tag) error } func New(ctx context.Context, bucket, region string, iam *sdkiam.Client, s3 *sdksss.Client) Object { diff --git a/aws/object/lifecycle.go b/aws/object/lifecycle.go index 24b6e215..48c9b28c 100644 --- a/aws/object/lifecycle.go +++ b/aws/object/lifecycle.go @@ -32,10 +32,9 @@ import ( sdkaws "github.com/aws/aws-sdk-go-v2/aws" sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) GetRetention(object, version string) (until time.Time, mode string, err liberr.Error) { +func (cli *client) GetRetention(object, version string) (until time.Time, mode string, err error) { until = time.Time{} mode = "" @@ -66,7 +65,7 @@ func (cli *client) GetRetention(object, version string) (until time.Time, mode s return until, mode, nil } -func (cli *client) SetRetention(object, version string, bypass bool, until time.Time, mode string) liberr.Error { +func (cli *client) SetRetention(object, version string, bypass bool, until time.Time, mode string) error { in := sdksss.PutObjectRetentionInput{ Bucket: cli.GetBucketAws(), Key: sdkaws.String(object), @@ -99,7 +98,7 @@ func (cli *client) SetRetention(object, version string, bypass bool, until time. return nil } -func (cli *client) GetLegalHold(object, version string) (sdktps.ObjectLockLegalHoldStatus, liberr.Error) { +func (cli *client) GetLegalHold(object, version string) (sdktps.ObjectLockLegalHoldStatus, error) { in := sdksss.GetObjectLegalHoldInput{ Bucket: cli.GetBucketAws(), Key: sdkaws.String(object), @@ -118,7 +117,7 @@ func (cli *client) GetLegalHold(object, version string) (sdktps.ObjectLockLegalH return out.LegalHold.Status, nil } -func (cli *client) SetLegalHold(object, version string, flag sdktps.ObjectLockLegalHoldStatus) liberr.Error { +func (cli *client) SetLegalHold(object, version string, flag sdktps.ObjectLockLegalHoldStatus) error { in := sdksss.PutObjectLegalHoldInput{ Bucket: cli.GetBucketAws(), Key: sdkaws.String(object), diff --git a/aws/object/multipart.go b/aws/object/multipart.go index 5747e5b0..704ded1a 100644 --- a/aws/object/multipart.go +++ b/aws/object/multipart.go @@ -33,13 +33,12 @@ import ( sdktyp "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" libmpu "github.com/nabbar/golib/aws/multipart" - liberr "github.com/nabbar/golib/errors" libsiz "github.com/nabbar/golib/size" ) // MultipartList implement the ListMultipartUploads. // See docs for more infos : https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListMultipartUploads.html -func (cli *client) MultipartList(keyMarker, markerId string) (uploads []sdktyp.MultipartUpload, nextKeyMarker string, nextIdMarker string, count int64, e liberr.Error) { +func (cli *client) MultipartList(keyMarker, markerId string) (uploads []sdktyp.MultipartUpload, nextKeyMarker string, nextIdMarker string, count int64, e error) { in := &sdksss.ListMultipartUploadsInput{ Bucket: sdkaws.String(cli.GetBucketName()), MaxUploads: 1000, @@ -71,11 +70,11 @@ func (cli *client) MultipartNew(partSize libsiz.Size, object string) libmpu.Mult return m } -func (cli *client) MultipartPut(object string, body io.Reader) liberr.Error { +func (cli *client) MultipartPut(object string, body io.Reader) error { return cli.MultipartPutCustom(libmpu.DefaultPartSize, object, body) } -func (cli *client) MultipartPutCustom(partSize libsiz.Size, object string, body io.Reader) liberr.Error { +func (cli *client) MultipartPutCustom(partSize libsiz.Size, object string, body io.Reader) error { var ( e error m = cli.MultipartNew(partSize, object) @@ -100,7 +99,7 @@ func (cli *client) MultipartPutCustom(partSize libsiz.Size, object string, body return nil } -func (cli *client) MultipartCancel(uploadId, key string) liberr.Error { +func (cli *client) MultipartCancel(uploadId, key string) error { res, err := cli.s3.AbortMultipartUpload(cli.GetContext(), &sdksss.AbortMultipartUploadInput{ Bucket: sdkaws.String(cli.GetBucketName()), UploadId: sdkaws.String(uploadId), diff --git a/aws/object/object.go b/aws/object/object.go index 7018c8d7..e4e00464 100644 --- a/aws/object/object.go +++ b/aws/object/object.go @@ -35,14 +35,13 @@ import ( sdkaws "github.com/aws/aws-sdk-go-v2/aws" sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) List(continuationToken string) ([]sdktps.Object, string, int64, liberr.Error) { +func (cli *client) List(continuationToken string) ([]sdktps.Object, string, int64, error) { return cli.ListPrefix(continuationToken, "") } -func (cli *client) ListPrefix(continuationToken string, prefix string) ([]sdktps.Object, string, int64, liberr.Error) { +func (cli *client) ListPrefix(continuationToken string, prefix string) ([]sdktps.Object, string, int64, error) { in := sdksss.ListObjectsV2Input{ Bucket: cli.GetBucketAws(), } @@ -66,11 +65,11 @@ func (cli *client) ListPrefix(continuationToken string, prefix string) ([]sdktps } } -func (cli *client) Walk(f WalkFunc) liberr.Error { +func (cli *client) Walk(f WalkFunc) error { return cli.WalkPrefix("", f) } -func (cli *client) WalkPrefix(prefix string, f WalkFunc) liberr.Error { +func (cli *client) WalkPrefix(prefix string, f WalkFunc) error { in := sdksss.ListObjectsV2Input{ Bucket: cli.GetBucketAws(), } @@ -80,7 +79,7 @@ func (cli *client) WalkPrefix(prefix string, f WalkFunc) liberr.Error { } var ( - e liberr.Error + e error t = sdkaws.String("") ) @@ -113,23 +112,23 @@ func (cli *client) WalkPrefix(prefix string, f WalkFunc) liberr.Error { } } -func (cli *client) Get(object string) (*sdksss.GetObjectOutput, liberr.Error) { +func (cli *client) Get(object string) (*sdksss.GetObjectOutput, error) { return cli.VersionGet(object, "") } -func (cli *client) Head(object string) (*sdksss.HeadObjectOutput, liberr.Error) { +func (cli *client) Head(object string) (*sdksss.HeadObjectOutput, error) { return cli.VersionHead(object, "") } -func (cli *client) Size(object string) (size int64, err liberr.Error) { +func (cli *client) Size(object string) (size int64, err error) { return cli.VersionSize(object, "") } -func (cli *client) Delete(check bool, object string) liberr.Error { +func (cli *client) Delete(check bool, object string) error { return cli.VersionDelete(check, object, "") } -func (cli *client) Put(object string, body io.Reader) liberr.Error { +func (cli *client) Put(object string, body io.Reader) error { var tpe *string if t := mime.TypeByExtension(filepath.Ext(object)); t == "" { @@ -154,7 +153,7 @@ func (cli *client) Put(object string, body io.Reader) liberr.Error { return nil } -func (cli *client) DeleteAll(objects *sdktps.Delete) ([]sdktps.DeletedObject, liberr.Error) { +func (cli *client) DeleteAll(objects *sdktps.Delete) ([]sdktps.DeletedObject, error) { in := sdksss.DeleteObjectsInput{ Bucket: cli.GetBucketAws(), Delete: objects, @@ -171,7 +170,7 @@ func (cli *client) DeleteAll(objects *sdktps.Delete) ([]sdktps.DeletedObject, li } } -func (cli *client) GetAttributes(object, version string) (*sdksss.GetObjectAttributesOutput, liberr.Error) { +func (cli *client) GetAttributes(object, version string) (*sdksss.GetObjectAttributesOutput, error) { in := sdksss.GetObjectAttributesInput{ Bucket: cli.GetBucketAws(), Key: sdkaws.String(object), diff --git a/aws/object/tags.go b/aws/object/tags.go index 0a4c860f..e8fe4314 100644 --- a/aws/object/tags.go +++ b/aws/object/tags.go @@ -29,10 +29,9 @@ import ( sdkaws "github.com/aws/aws-sdk-go-v2/aws" sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) GetTags(object, version string) ([]sdktps.Tag, liberr.Error) { +func (cli *client) GetTags(object, version string) ([]sdktps.Tag, error) { in := sdksss.GetObjectTaggingInput{ Bucket: cli.GetBucketAws(), Key: sdkaws.String(object), @@ -51,7 +50,7 @@ func (cli *client) GetTags(object, version string) ([]sdktps.Tag, liberr.Error) return out.TagSet, nil } -func (cli *client) SetTags(object, version string, tags ...sdktps.Tag) liberr.Error { +func (cli *client) SetTags(object, version string, tags ...sdktps.Tag) error { in := sdksss.PutObjectTaggingInput{ Bucket: cli.GetBucketAws(), Key: sdkaws.String(object), diff --git a/aws/object/version.go b/aws/object/version.go index a15d1544..e0203d50 100644 --- a/aws/object/version.go +++ b/aws/object/version.go @@ -32,10 +32,9 @@ import ( sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) VersionList(prefix, keyMarker, markerId string) (version []sdktps.ObjectVersion, delMarker []sdktps.DeleteMarkerEntry, nextKeyMarker, nextMarkerId string, count int64, err liberr.Error) { +func (cli *client) VersionList(prefix, keyMarker, markerId string) (version []sdktps.ObjectVersion, delMarker []sdktps.DeleteMarkerEntry, nextKeyMarker, nextMarkerId string, count int64, err error) { in := sdksss.ListObjectVersionsInput{ Bucket: cli.GetBucketAws(), MaxKeys: 1000, @@ -61,11 +60,11 @@ func (cli *client) VersionList(prefix, keyMarker, markerId string) (version []sd } } -func (cli *client) VersionWalk(fv VersionWalkFunc, fd DelMakWalkFunc) liberr.Error { +func (cli *client) VersionWalk(fv VersionWalkFunc, fd DelMakWalkFunc) error { return cli.VersionWalkPrefix("", fv, fd) } -func (cli *client) VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMakWalkFunc) liberr.Error { +func (cli *client) VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMakWalkFunc) error { in := sdksss.ListObjectVersionsInput{ Bucket: cli.GetBucketAws(), MaxKeys: 1000, @@ -76,7 +75,7 @@ func (cli *client) VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMa } var ( - e liberr.Error + e error km = sdkaws.String("") mi = sdkaws.String("") ) @@ -126,7 +125,7 @@ func (cli *client) VersionWalkPrefix(prefix string, fv VersionWalkFunc, fd DelMa } } -func (cli *client) VersionGet(object, version string) (*sdksss.GetObjectOutput, liberr.Error) { +func (cli *client) VersionGet(object, version string) (*sdksss.GetObjectOutput, error) { in := sdksss.GetObjectInput{ Bucket: cli.GetBucketAws(), Key: sdkaws.String(object), @@ -153,7 +152,7 @@ func (cli *client) VersionGet(object, version string) (*sdksss.GetObjectOutput, } -func (cli *client) VersionHead(object, version string) (*sdksss.HeadObjectOutput, liberr.Error) { +func (cli *client) VersionHead(object, version string) (*sdksss.HeadObjectOutput, error) { in := sdksss.HeadObjectInput{ Bucket: cli.GetBucketAws(), Key: sdkaws.String(object), @@ -174,7 +173,7 @@ func (cli *client) VersionHead(object, version string) (*sdksss.HeadObjectOutput } } -func (cli *client) VersionSize(object, version string) (size int64, err liberr.Error) { +func (cli *client) VersionSize(object, version string) (size int64, err error) { var ( h *sdksss.HeadObjectOutput ) @@ -186,7 +185,7 @@ func (cli *client) VersionSize(object, version string) (size int64, err liberr.E } } -func (cli *client) VersionDelete(check bool, object, version string) liberr.Error { +func (cli *client) VersionDelete(check bool, object, version string) error { if check { if _, err := cli.VersionHead(object, version); err != nil { return err diff --git a/aws/object/website.go b/aws/object/website.go index 95d742b6..f71a0ebf 100644 --- a/aws/object/website.go +++ b/aws/object/website.go @@ -29,16 +29,15 @@ import ( sdkaws "github.com/aws/aws-sdk-go-v2/aws" sdksss "github.com/aws/aws-sdk-go-v2/service/s3" sdktps "github.com/aws/aws-sdk-go-v2/service/s3/types" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) UpdateMetadata(meta *sdksss.CopyObjectInput) liberr.Error { +func (cli *client) UpdateMetadata(meta *sdksss.CopyObjectInput) error { _, err := cli.s3.CopyObject(cli.GetContext(), meta) return cli.GetError(err) } -func (cli *client) SetWebsite(object, redirect string) liberr.Error { +func (cli *client) SetWebsite(object, redirect string) error { var err error _, err = cli.s3.PutObjectAcl(cli.GetContext(), &sdksss.PutObjectAclInput{ diff --git a/aws/policy/interface.go b/aws/policy/interface.go index 00183865..b2a65dc5 100644 --- a/aws/policy/interface.go +++ b/aws/policy/interface.go @@ -32,7 +32,6 @@ import ( "github.com/aws/aws-sdk-go-v2/service/iam/types" "github.com/aws/aws-sdk-go-v2/service/s3" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) type client struct { @@ -42,19 +41,19 @@ type client struct { } type Policy interface { - List() (map[string]string, liberr.Error) + List() (map[string]string, error) - Get(arn string) (*types.Policy, liberr.Error) - Add(name, desc, policy string) (string, liberr.Error) - Update(polArn, polContents string) liberr.Error - Delete(polArn string) liberr.Error + Get(arn string) (*types.Policy, error) + Add(name, desc, policy string) (string, error) + Update(polArn, polContents string) error + Delete(polArn string) error - VersionList(arn string, maxItem int32, noDefaultVersion bool) (map[string]string, liberr.Error) - VersionGet(arn string, vers string) (*types.PolicyVersion, liberr.Error) - VersionAdd(arn string, doc string) liberr.Error - VersionDel(arn string, vers string) liberr.Error + VersionList(arn string, maxItem int32, noDefaultVersion bool) (map[string]string, error) + VersionGet(arn string, vers string) (*types.PolicyVersion, error) + VersionAdd(arn string, doc string) error + VersionDel(arn string, vers string) error - CompareUpdate(arn string, doc string) (upd bool, err liberr.Error) + CompareUpdate(arn string, doc string) (upd bool, err error) } func New(ctx context.Context, bucket, region string, iam *iam.Client, s3 *s3.Client) Policy { diff --git a/aws/policy/policies.go b/aws/policy/policies.go index b09badeb..f0f49e9f 100644 --- a/aws/policy/policies.go +++ b/aws/policy/policies.go @@ -30,10 +30,9 @@ import ( "github.com/aws/aws-sdk-go-v2/service/iam" "github.com/aws/aws-sdk-go-v2/service/iam/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) List() (map[string]string, liberr.Error) { +func (cli *client) List() (map[string]string, error) { out, err := cli.iam.ListPolicies(cli.GetContext(), &iam.ListPoliciesInput{}) if err != nil { @@ -49,7 +48,7 @@ func (cli *client) List() (map[string]string, liberr.Error) { } } -func (cli *client) Get(arn string) (*types.Policy, liberr.Error) { +func (cli *client) Get(arn string) (*types.Policy, error) { out, err := cli.iam.GetPolicy(cli.GetContext(), &iam.GetPolicyInput{ PolicyArn: aws.String(arn), }) @@ -63,7 +62,7 @@ func (cli *client) Get(arn string) (*types.Policy, liberr.Error) { } } -func (cli *client) Add(name, desc, policy string) (string, liberr.Error) { +func (cli *client) Add(name, desc, policy string) (string, error) { out, err := cli.iam.CreatePolicy(cli.GetContext(), &iam.CreatePolicyInput{ PolicyName: aws.String(name), Description: aws.String(desc), @@ -77,11 +76,11 @@ func (cli *client) Add(name, desc, policy string) (string, liberr.Error) { } } -func (cli *client) Update(polArn, polContents string) liberr.Error { +func (cli *client) Update(polArn, polContents string) error { var ( pol *types.Policy lst map[string]string - err liberr.Error + err error ) if pol, err = cli.Get(polArn); err != nil { @@ -105,7 +104,7 @@ func (cli *client) Update(polArn, polContents string) liberr.Error { return cli.VersionAdd(polArn, polContents) } -func (cli *client) Delete(polArn string) liberr.Error { +func (cli *client) Delete(polArn string) error { out, err := cli.iam.ListPolicyVersions(cli.GetContext(), &iam.ListPolicyVersionsInput{ PolicyArn: aws.String(polArn), }) diff --git a/aws/policy/versions.go b/aws/policy/versions.go index 91802cf1..8b972b0c 100644 --- a/aws/policy/versions.go +++ b/aws/policy/versions.go @@ -35,15 +35,14 @@ import ( "github.com/aws/aws-sdk-go-v2/service/iam" "github.com/aws/aws-sdk-go-v2/service/iam/types" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) const maxItemList int32 = 1000 -func (cli *client) VersionList(arn string, maxItem int32, noDefaultVersion bool) (map[string]string, liberr.Error) { +func (cli *client) VersionList(arn string, maxItem int32, noDefaultVersion bool) (map[string]string, error) { if arn == "" { //nolint #goerr113 - return nil, libhlp.ErrorParamsEmpty.ErrorParent(fmt.Errorf("arn is empty")) + return nil, libhlp.ErrorParamsEmpty.Error(fmt.Errorf("arn is empty")) } if maxItem < 1 { @@ -105,7 +104,7 @@ func (cli *client) VersionList(arn string, maxItem int32, noDefaultVersion bool) return res, nil } -func (cli *client) VersionAdd(arn string, doc string) liberr.Error { +func (cli *client) VersionAdd(arn string, doc string) error { out, err := cli.iam.CreatePolicyVersion(cli.GetContext(), &iam.CreatePolicyVersionInput{ PolicyArn: aws.String(arn), PolicyDocument: aws.String(doc), @@ -121,7 +120,7 @@ func (cli *client) VersionAdd(arn string, doc string) liberr.Error { return nil } -func (cli *client) VersionGet(arn string, vers string) (*types.PolicyVersion, liberr.Error) { +func (cli *client) VersionGet(arn string, vers string) (*types.PolicyVersion, error) { out, err := cli.iam.GetPolicyVersion(cli.GetContext(), &iam.GetPolicyVersionInput{ PolicyArn: aws.String(arn), VersionId: aws.String(vers), @@ -136,7 +135,7 @@ func (cli *client) VersionGet(arn string, vers string) (*types.PolicyVersion, li } } -func (cli *client) VersionDel(arn string, vers string) liberr.Error { +func (cli *client) VersionDel(arn string, vers string) error { out, err := cli.iam.DeletePolicyVersion(cli.GetContext(), &iam.DeletePolicyVersionInput{ PolicyArn: aws.String(arn), VersionId: aws.String(vers), @@ -151,7 +150,7 @@ func (cli *client) VersionDel(arn string, vers string) liberr.Error { return nil } -func (cli *client) CompareUpdate(arn string, doc string) (upd bool, err liberr.Error) { +func (cli *client) CompareUpdate(arn string, doc string) (upd bool, err error) { var ( e error pol *types.Policy diff --git a/aws/role/interface.go b/aws/role/interface.go index 9dc21c86..56d685cb 100644 --- a/aws/role/interface.go +++ b/aws/role/interface.go @@ -32,7 +32,6 @@ import ( sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types" sdksss "github.com/aws/aws-sdk-go-v2/service/s3" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) type client struct { @@ -41,19 +40,19 @@ type client struct { s3 *sdksss.Client } -type PoliciesWalkFunc func(err liberr.Error, pol sdktps.AttachedPolicy) liberr.Error +type PoliciesWalkFunc func(err error, pol sdktps.AttachedPolicy) error type Role interface { - List() ([]sdktps.Role, liberr.Error) - Check(name string) (string, liberr.Error) - Add(name, role string) (string, liberr.Error) - Delete(roleName string) liberr.Error + List() ([]sdktps.Role, error) + Check(name string) (string, error) + Add(name, role string) (string, error) + Delete(roleName string) error - PolicyAttach(policyARN, roleName string) liberr.Error - PolicyDetach(policyARN, roleName string) liberr.Error - PolicyListAttached(roleName string) ([]sdktps.AttachedPolicy, liberr.Error) - PolicyAttachedList(roleName, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error) - PolicyAttachedWalk(roleName string, fct PoliciesWalkFunc) liberr.Error + PolicyAttach(policyARN, roleName string) error + PolicyDetach(policyARN, roleName string) error + PolicyListAttached(roleName string) ([]sdktps.AttachedPolicy, error) + PolicyAttachedList(roleName, marker string) ([]sdktps.AttachedPolicy, string, error) + PolicyAttachedWalk(roleName string, fct PoliciesWalkFunc) error } func New(ctx context.Context, bucket, region string, iam *sdkiam.Client, s3 *sdksss.Client) Role { diff --git a/aws/role/policy.go b/aws/role/policy.go index 10e4284c..830275d8 100644 --- a/aws/role/policy.go +++ b/aws/role/policy.go @@ -29,13 +29,12 @@ import ( sdkaws "github.com/aws/aws-sdk-go-v2/aws" sdkiam "github.com/aws/aws-sdk-go-v2/service/iam" sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types" - liberr "github.com/nabbar/golib/errors" ) /* @DEPRECATED: PolicyAttachedList */ -func (cli *client) PolicyListAttached(roleName string) ([]sdktps.AttachedPolicy, liberr.Error) { +func (cli *client) PolicyListAttached(roleName string) ([]sdktps.AttachedPolicy, error) { out, _, err := cli.PolicyAttachedList(roleName, "") if err != nil { @@ -45,7 +44,7 @@ func (cli *client) PolicyListAttached(roleName string) ([]sdktps.AttachedPolicy, } } -func (cli *client) PolicyAttach(policyARN, roleName string) liberr.Error { +func (cli *client) PolicyAttach(policyARN, roleName string) error { _, err := cli.iam.AttachRolePolicy(cli.GetContext(), &sdkiam.AttachRolePolicyInput{ PolicyArn: sdkaws.String(policyARN), RoleName: sdkaws.String(roleName), @@ -54,7 +53,7 @@ func (cli *client) PolicyAttach(policyARN, roleName string) liberr.Error { return cli.GetError(err) } -func (cli *client) PolicyDetach(policyARN, roleName string) liberr.Error { +func (cli *client) PolicyDetach(policyARN, roleName string) error { _, err := cli.iam.DetachRolePolicy(cli.GetContext(), &sdkiam.DetachRolePolicyInput{ PolicyArn: sdkaws.String(policyARN), RoleName: sdkaws.String(roleName), @@ -63,7 +62,7 @@ func (cli *client) PolicyDetach(policyARN, roleName string) liberr.Error { return cli.GetError(err) } -func (cli *client) PolicyAttachedList(roleName, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error) { +func (cli *client) PolicyAttachedList(roleName, marker string) ([]sdktps.AttachedPolicy, string, error) { in := &sdkiam.ListAttachedRolePoliciesInput{ RoleName: sdkaws.String(roleName), MaxItems: sdkaws.Int32(1000), @@ -86,7 +85,7 @@ func (cli *client) PolicyAttachedList(roleName, marker string) ([]sdktps.Attache } } -func (cli *client) PolicyAttachedWalk(roleName string, fct PoliciesWalkFunc) liberr.Error { +func (cli *client) PolicyAttachedWalk(roleName string, fct PoliciesWalkFunc) error { var m *string in := &sdkiam.ListAttachedRolePoliciesInput{ @@ -109,7 +108,7 @@ func (cli *client) PolicyAttachedWalk(roleName string, fct PoliciesWalkFunc) lib return nil } - var e liberr.Error + var e error for _, p := range lst.AttachedPolicies { e = fct(e, p) } diff --git a/aws/role/role.go b/aws/role/role.go index e5f1acd4..134ef61d 100644 --- a/aws/role/role.go +++ b/aws/role/role.go @@ -26,14 +26,13 @@ package role import ( - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/iam" - "github.com/aws/aws-sdk-go-v2/service/iam/types" - "github.com/nabbar/golib/errors" + sdkaws "github.com/aws/aws-sdk-go-v2/aws" + sdkiam "github.com/aws/aws-sdk-go-v2/service/iam" + iamtps "github.com/aws/aws-sdk-go-v2/service/iam/types" ) -func (cli *client) List() ([]types.Role, errors.Error) { - out, err := cli.iam.ListRoles(cli.GetContext(), &iam.ListRolesInput{}) +func (cli *client) List() ([]iamtps.Role, error) { + out, err := cli.iam.ListRoles(cli.GetContext(), &sdkiam.ListRolesInput{}) if err != nil { return nil, cli.GetError(err) @@ -42,9 +41,9 @@ func (cli *client) List() ([]types.Role, errors.Error) { } } -func (cli *client) Check(name string) (string, errors.Error) { - out, err := cli.iam.GetRole(cli.GetContext(), &iam.GetRoleInput{ - RoleName: aws.String(name), +func (cli *client) Check(name string) (string, error) { + out, err := cli.iam.GetRole(cli.GetContext(), &sdkiam.GetRoleInput{ + RoleName: sdkaws.String(name), }) if err != nil { @@ -54,10 +53,10 @@ func (cli *client) Check(name string) (string, errors.Error) { return *out.Role.Arn, nil } -func (cli *client) Add(name, role string) (string, errors.Error) { - out, err := cli.iam.CreateRole(cli.GetContext(), &iam.CreateRoleInput{ - AssumeRolePolicyDocument: aws.String(role), - RoleName: aws.String(name), +func (cli *client) Add(name, role string) (string, error) { + out, err := cli.iam.CreateRole(cli.GetContext(), &sdkiam.CreateRoleInput{ + AssumeRolePolicyDocument: sdkaws.String(role), + RoleName: sdkaws.String(name), }) if err != nil { @@ -67,9 +66,9 @@ func (cli *client) Add(name, role string) (string, errors.Error) { } } -func (cli *client) Delete(roleName string) errors.Error { - _, err := cli.iam.DeleteRole(cli.GetContext(), &iam.DeleteRoleInput{ - RoleName: aws.String(roleName), +func (cli *client) Delete(roleName string) error { + _, err := cli.iam.DeleteRole(cli.GetContext(), &sdkiam.DeleteRoleInput{ + RoleName: sdkaws.String(roleName), }) return cli.GetError(err) diff --git a/aws/user/access.go b/aws/user/access.go index e293fda7..7722c4ab 100644 --- a/aws/user/access.go +++ b/aws/user/access.go @@ -30,10 +30,9 @@ import ( sdkiam "github.com/aws/aws-sdk-go-v2/service/iam" sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types" awshlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) AccessListAll(username string) ([]sdktps.AccessKeyMetadata, liberr.Error) { +func (cli *client) AccessListAll(username string) ([]sdktps.AccessKeyMetadata, error) { var req = &sdkiam.ListAccessKeysInput{} if username != "" { @@ -53,7 +52,7 @@ func (cli *client) AccessListAll(username string) ([]sdktps.AccessKeyMetadata, l } } -func (cli *client) AccessList(username string) (map[string]bool, liberr.Error) { +func (cli *client) AccessList(username string) (map[string]bool, error) { var req = &sdkiam.ListAccessKeysInput{} if username != "" { @@ -84,7 +83,7 @@ func (cli *client) AccessList(username string) (map[string]bool, liberr.Error) { } } -func (cli *client) AccessCreate(username string) (string, string, liberr.Error) { +func (cli *client) AccessCreate(username string) (string, string, error) { var req = &sdkiam.CreateAccessKeyInput{} if username != "" { @@ -104,7 +103,7 @@ func (cli *client) AccessCreate(username string) (string, string, liberr.Error) } } -func (cli *client) AccessDelete(username, accessKey string) liberr.Error { +func (cli *client) AccessDelete(username, accessKey string) error { var req = &sdkiam.DeleteAccessKeyInput{ AccessKeyId: sdkaws.String(accessKey), } diff --git a/aws/user/interface.go b/aws/user/interface.go index 0b2f89ea..ce171751 100644 --- a/aws/user/interface.go +++ b/aws/user/interface.go @@ -32,7 +32,6 @@ import ( sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types" sdksss "github.com/aws/aws-sdk-go-v2/service/s3" libhlp "github.com/nabbar/golib/aws/helper" - liberr "github.com/nabbar/golib/errors" ) type client struct { @@ -41,28 +40,28 @@ type client struct { s3 *sdksss.Client } -type PoliciesWalkFunc func(err liberr.Error, pol sdktps.AttachedPolicy) liberr.Error +type PoliciesWalkFunc func(err error, pol sdktps.AttachedPolicy) error type User interface { - List() (map[string]string, liberr.Error) - Get(username string) (*sdktps.User, liberr.Error) - Create(username string) liberr.Error - Delete(username string) liberr.Error + List() (map[string]string, error) + Get(username string) (*sdktps.User, error) + Create(username string) error + Delete(username string) error - PolicyPut(policyDocument, policyName, username string) liberr.Error - PolicyAttach(policyARN, username string) liberr.Error - PolicyDetach(policyARN, username string) liberr.Error - PolicyAttachedList(username, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error) - PolicyAttachedWalk(username string, fct PoliciesWalkFunc) liberr.Error + PolicyPut(policyDocument, policyName, username string) error + PolicyAttach(policyARN, username string) error + PolicyDetach(policyARN, username string) error + PolicyAttachedList(username, marker string) ([]sdktps.AttachedPolicy, string, error) + PolicyAttachedWalk(username string, fct PoliciesWalkFunc) error - LoginCheck(username string) liberr.Error - LoginCreate(username, password string) liberr.Error - LoginDelete(username string) liberr.Error + LoginCheck(username string) error + LoginCreate(username, password string) error + LoginDelete(username string) error - AccessListAll(username string) ([]sdktps.AccessKeyMetadata, liberr.Error) - AccessList(username string) (map[string]bool, liberr.Error) - AccessCreate(username string) (string, string, liberr.Error) - AccessDelete(username, accessKey string) liberr.Error + AccessListAll(username string) ([]sdktps.AccessKeyMetadata, error) + AccessList(username string) (map[string]bool, error) + AccessCreate(username string) (string, string, error) + AccessDelete(username, accessKey string) error } func New(ctx context.Context, bucket, region string, iam *sdkiam.Client, s3 *sdksss.Client) User { diff --git a/aws/user/login.go b/aws/user/login.go index a22c9581..9495d7f1 100644 --- a/aws/user/login.go +++ b/aws/user/login.go @@ -26,39 +26,38 @@ package user import ( - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/iam" - "github.com/nabbar/golib/aws/helper" - "github.com/nabbar/golib/errors" + sdkaws "github.com/aws/aws-sdk-go-v2/aws" + sdkiam "github.com/aws/aws-sdk-go-v2/service/iam" + awshlp "github.com/nabbar/golib/aws/helper" ) -func (cli *client) LoginCheck(username string) errors.Error { - _, err := cli.iam.GetLoginProfile(cli.GetContext(), &iam.GetLoginProfileInput{ - UserName: aws.String(username), +func (cli *client) LoginCheck(username string) error { + _, err := cli.iam.GetLoginProfile(cli.GetContext(), &sdkiam.GetLoginProfileInput{ + UserName: sdkaws.String(username), }) return cli.GetError(err) } -func (cli *client) LoginCreate(username, password string) errors.Error { - out, err := cli.iam.CreateLoginProfile(cli.GetContext(), &iam.CreateLoginProfileInput{ - UserName: aws.String(username), - Password: aws.String(password), +func (cli *client) LoginCreate(username, password string) error { + out, err := cli.iam.CreateLoginProfile(cli.GetContext(), &sdkiam.CreateLoginProfileInput{ + UserName: sdkaws.String(username), + Password: sdkaws.String(password), PasswordResetRequired: false, }) if err != nil { return cli.GetError(err) } else if out.LoginProfile == nil { - return helper.ErrorResponse.Error(nil) + return awshlp.ErrorResponse.Error(nil) } return nil } -func (cli *client) LoginDelete(username string) errors.Error { - _, err := cli.iam.DeleteLoginProfile(cli.GetContext(), &iam.DeleteLoginProfileInput{ - UserName: aws.String(username), +func (cli *client) LoginDelete(username string) error { + _, err := cli.iam.DeleteLoginProfile(cli.GetContext(), &sdkiam.DeleteLoginProfileInput{ + UserName: sdkaws.String(username), }) return cli.GetError(err) diff --git a/aws/user/policy.go b/aws/user/policy.go index c902b57a..76424304 100644 --- a/aws/user/policy.go +++ b/aws/user/policy.go @@ -29,10 +29,9 @@ import ( sdkaws "github.com/aws/aws-sdk-go-v2/aws" sdkiam "github.com/aws/aws-sdk-go-v2/service/iam" sdktps "github.com/aws/aws-sdk-go-v2/service/iam/types" - liberr "github.com/nabbar/golib/errors" ) -func (cli *client) PolicyPut(policyDocument, policyName, username string) liberr.Error { +func (cli *client) PolicyPut(policyDocument, policyName, username string) error { _, err := cli.iam.PutUserPolicy(cli.GetContext(), &sdkiam.PutUserPolicyInput{ PolicyDocument: sdkaws.String(policyDocument), PolicyName: sdkaws.String(policyName), @@ -42,7 +41,7 @@ func (cli *client) PolicyPut(policyDocument, policyName, username string) liberr return cli.GetError(err) } -func (cli *client) PolicyAttachedList(username, marker string) ([]sdktps.AttachedPolicy, string, liberr.Error) { +func (cli *client) PolicyAttachedList(username, marker string) ([]sdktps.AttachedPolicy, string, error) { in := &sdkiam.ListAttachedUserPoliciesInput{ UserName: sdkaws.String(username), MaxItems: sdkaws.Int32(1000), @@ -65,7 +64,7 @@ func (cli *client) PolicyAttachedList(username, marker string) ([]sdktps.Attache } } -func (cli *client) PolicyAttachedWalk(username string, fct PoliciesWalkFunc) liberr.Error { +func (cli *client) PolicyAttachedWalk(username string, fct PoliciesWalkFunc) error { var m *string in := &sdkiam.ListAttachedUserPoliciesInput{ @@ -88,7 +87,7 @@ func (cli *client) PolicyAttachedWalk(username string, fct PoliciesWalkFunc) lib return nil } - var e liberr.Error + var e error for _, p := range lst.AttachedPolicies { e = fct(e, p) } @@ -105,7 +104,7 @@ func (cli *client) PolicyAttachedWalk(username string, fct PoliciesWalkFunc) lib } } -func (cli *client) PolicyAttach(policyARN, username string) liberr.Error { +func (cli *client) PolicyAttach(policyARN, username string) error { _, err := cli.iam.AttachUserPolicy(cli.GetContext(), &sdkiam.AttachUserPolicyInput{ PolicyArn: sdkaws.String(policyARN), UserName: sdkaws.String(username), @@ -114,7 +113,7 @@ func (cli *client) PolicyAttach(policyARN, username string) liberr.Error { return cli.GetError(err) } -func (cli *client) PolicyDetach(policyARN, username string) liberr.Error { +func (cli *client) PolicyDetach(policyARN, username string) error { _, err := cli.iam.DetachUserPolicy(cli.GetContext(), &sdkiam.DetachUserPolicyInput{ PolicyArn: sdkaws.String(policyARN), UserName: sdkaws.String(username), diff --git a/aws/user/user.go b/aws/user/user.go index bf57aada..e174d81f 100644 --- a/aws/user/user.go +++ b/aws/user/user.go @@ -26,20 +26,19 @@ package user import ( - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/iam" - "github.com/aws/aws-sdk-go-v2/service/iam/types" - "github.com/nabbar/golib/aws/helper" - "github.com/nabbar/golib/errors" + sdkaws "github.com/aws/aws-sdk-go-v2/aws" + sdkiam "github.com/aws/aws-sdk-go-v2/service/iam" + iamtps "github.com/aws/aws-sdk-go-v2/service/iam/types" + awshlp "github.com/nabbar/golib/aws/helper" ) -func (cli *client) List() (map[string]string, errors.Error) { - out, err := cli.iam.ListUsers(cli.GetContext(), &iam.ListUsersInput{}) +func (cli *client) List() (map[string]string, error) { + out, err := cli.iam.ListUsers(cli.GetContext(), &sdkiam.ListUsersInput{}) if err != nil { return nil, cli.GetError(err) } else if out.Users == nil { - return nil, helper.ErrorResponse.Error(nil) + return nil, awshlp.ErrorResponse.Error(nil) } else { var res = make(map[string]string) @@ -51,9 +50,9 @@ func (cli *client) List() (map[string]string, errors.Error) { } } -func (cli *client) Get(username string) (*types.User, errors.Error) { - out, err := cli.iam.GetUser(cli.GetContext(), &iam.GetUserInput{ - UserName: aws.String(username), +func (cli *client) Get(username string) (*iamtps.User, error) { + out, err := cli.iam.GetUser(cli.GetContext(), &sdkiam.GetUserInput{ + UserName: sdkaws.String(username), }) if err != nil { @@ -63,23 +62,23 @@ func (cli *client) Get(username string) (*types.User, errors.Error) { return out.User, nil } -func (cli *client) Create(username string) errors.Error { - out, err := cli.iam.CreateUser(cli.GetContext(), &iam.CreateUserInput{ - UserName: aws.String(username), +func (cli *client) Create(username string) error { + out, err := cli.iam.CreateUser(cli.GetContext(), &sdkiam.CreateUserInput{ + UserName: sdkaws.String(username), }) if err != nil { return cli.GetError(err) } else if out.User == nil { - return helper.ErrorResponse.Error(nil) + return awshlp.ErrorResponse.Error(nil) } return nil } -func (cli *client) Delete(username string) errors.Error { - _, err := cli.iam.DeleteUser(cli.GetContext(), &iam.DeleteUserInput{ - UserName: aws.String(username), +func (cli *client) Delete(username string) error { + _, err := cli.iam.DeleteUser(cli.GetContext(), &sdkiam.DeleteUserInput{ + UserName: sdkaws.String(username), }) return cli.GetError(err) diff --git a/certificates/config.go b/certificates/config.go index 2426a3f7..25cf0692 100644 --- a/certificates/config.go +++ b/certificates/config.go @@ -60,12 +60,12 @@ func (c *Config) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.StructNamespace(), e.ActualTag())) } } diff --git a/certificates/model.go b/certificates/model.go index cf08bf97..c6edfa3e 100644 --- a/certificates/model.go +++ b/certificates/model.go @@ -57,13 +57,13 @@ func (c *config) checkFile(pemFiles ...string) liberr.Error { } if _, e := os.Stat(f); e != nil { - return ErrorFileStat.ErrorParent(e) + return ErrorFileStat.Error(e) } /* #nosec */ b, e := ioutil.ReadFile(f) if e != nil { - return ErrorFileRead.ErrorParent(e) + return ErrorFileRead.Error(e) } b = bytes.Trim(b, "\n") @@ -162,7 +162,7 @@ func (c *config) AddCertificatePairString(key, crt string) liberr.Error { p, err := tls.X509KeyPair([]byte(crt), []byte(key)) if err != nil { - return ErrorCertKeyPairParse.ErrorParent(err) + return ErrorCertKeyPairParse.Error(err) } c.cert = append(c.cert, p) @@ -179,7 +179,7 @@ func (c *config) AddCertificatePairFile(keyFile, crtFile string) liberr.Error { } if p, e := tls.LoadX509KeyPair(crtFile, keyFile); e != nil { - return ErrorCertKeyPairLoad.ErrorParent(e) + return ErrorCertKeyPairLoad.Error(e) } else { c.cert = append(c.cert, p) return nil diff --git a/cluster/async.go b/cluster/async.go index 4d3890e3..41c79846 100644 --- a/cluster/async.go +++ b/cluster/async.go @@ -40,7 +40,7 @@ func (c *cRaft) AsyncPropose(session *dgbcli.Session, cmd []byte) (*dgbclt.Reque r, e := c.nodeHost.Propose(session, cmd, c.timeoutCmdASync) if e != nil { - return r, ErrorCommandASync.ErrorParent(c.getErrorCommand("Propose"), e) + return r, ErrorCommandASync.Error(c.getErrorCommand("Propose"), e) } return r, nil @@ -50,7 +50,7 @@ func (c *cRaft) AsyncProposeSession(session *dgbcli.Session) (*dgbclt.RequestSta r, e := c.nodeHost.ProposeSession(session, c.timeoutCmdASync) if e != nil { - return r, ErrorCommandASync.ErrorParent(c.getErrorCommand("ProposeSession"), e) + return r, ErrorCommandASync.Error(c.getErrorCommand("ProposeSession"), e) } return r, nil @@ -60,7 +60,7 @@ func (c *cRaft) AsyncReadIndex() (*dgbclt.RequestState, liberr.Error) { r, e := c.nodeHost.ReadIndex(c.config.ClusterID, c.timeoutCmdASync) if e != nil { - return r, ErrorCommandASync.ErrorParent(c.getErrorCluster(), c.getErrorCommand("ReadIndex"), e) + return r, ErrorCommandASync.Error(c.getErrorCluster(), c.getErrorCommand("ReadIndex"), e) } return r, nil @@ -78,7 +78,7 @@ func (c *cRaft) AsyncRequestCompaction(nodeID uint64) (*dgbclt.SysOpState, liber r, e := c.nodeHost.RequestCompaction(c.config.ClusterID, nodeID) if e != nil { - return r, ErrorCommandASync.ErrorParent(c.getErrorCluster(), er, c.getErrorCommand("RequestCompaction"), e) + return r, ErrorCommandASync.Error(c.getErrorCluster(), er, c.getErrorCommand("RequestCompaction"), e) } return r, nil diff --git a/cluster/cluster.go b/cluster/cluster.go index c99bc166..2d9df950 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -152,14 +152,14 @@ func (c *cRaft) ClusterStart(join bool) liberr.Error { } if f, ok := c.fctCreate.(dgbstm.CreateStateMachineFunc); ok { - err.AddParent(c.nodeHost.StartCluster(c.memberInit, join, f, c.config)) + err.Add(c.nodeHost.StartCluster(c.memberInit, join, f, c.config)) } else if f, ok := c.fctCreate.(dgbstm.CreateConcurrentStateMachineFunc); ok { - err.AddParent(c.nodeHost.StartConcurrentCluster(c.memberInit, join, f, c.config)) + err.Add(c.nodeHost.StartConcurrentCluster(c.memberInit, join, f, c.config)) } else if f, ok := c.fctCreate.(dgbstm.CreateOnDiskStateMachineFunc); ok { - err.AddParent(c.nodeHost.StartOnDiskCluster(c.memberInit, join, f, c.config)) + err.Add(c.nodeHost.StartOnDiskCluster(c.memberInit, join, f, c.config)) } else { //nolint #goerr113 - return ErrorParamsMismatching.ErrorParent(fmt.Errorf("create function is not one of type of CreateStateMachineFunc, CreateConcurrentStateMachineFunc, CreateOnDiskStateMachineFunc")) + return ErrorParamsMismatching.Error(fmt.Errorf("create function is not one of type of CreateStateMachineFunc, CreateConcurrentStateMachineFunc, CreateOnDiskStateMachineFunc")) } if err.HasParent() { @@ -173,7 +173,7 @@ func (c *cRaft) ClusterStop(force bool) liberr.Error { e := c.nodeHost.StopCluster(c.config.ClusterID) if e != nil && !force { - return ErrorNodeHostStop.ErrorParent(c.getErrorCluster(), e) + return ErrorNodeHostStop.Error(c.getErrorCluster(), e) } c.nodeHost.Stop() @@ -200,7 +200,7 @@ func (c *cRaft) NodeStop(target uint64) liberr.Error { e := c.nodeHost.StopNode(c.config.ClusterID, target) if e != nil { - return ErrorNodeHostStop.ErrorParent(c.getErrorCluster(), en, e) + return ErrorNodeHostStop.Error(c.getErrorCluster(), en, e) } return nil @@ -211,7 +211,7 @@ func (c *cRaft) NodeRestart(force bool) liberr.Error { if l, ok, err := c.GetLeaderID(); err == nil && ok && l == c.config.NodeID { join = true - var sErr = ErrorNodeHostRestart.ErrorParent(c.getErrorCluster(), c.getErrorNode()) + var sErr = ErrorNodeHostRestart.Error(c.getErrorCluster(), c.getErrorNode()) for id, nd := range c.memberInit { if id == c.config.NodeID { continue @@ -220,7 +220,7 @@ func (c *cRaft) NodeRestart(force bool) liberr.Error { continue } if err = c.RequestLeaderTransfer(id); err == nil { - sErr.AddParentError(err) + sErr.Add(err) break } } @@ -247,7 +247,7 @@ func (c *cRaft) GetLeaderID() (leader uint64, valid bool, err liberr.Error) { leader, valid, e = c.nodeHost.GetLeaderID(c.config.ClusterID) if e != nil { - err = ErrorLeader.ErrorParent(c.getErrorCluster(), e) + err = ErrorLeader.Error(c.getErrorCluster(), e) } return @@ -261,7 +261,7 @@ func (c *cRaft) GetNodeUser() (dgbclt.INodeUser, liberr.Error) { r, e := c.nodeHost.GetNodeUser(c.config.ClusterID) if e != nil { - return nil, ErrorNodeUser.ErrorParent(c.getErrorCluster()) + return nil, ErrorNodeUser.Error(c.getErrorCluster()) } return r, nil @@ -287,7 +287,7 @@ func (c *cRaft) RequestLeaderTransfer(targetNodeID uint64) liberr.Error { e := c.nodeHost.RequestLeaderTransfer(c.config.ClusterID, targetNodeID) if e != nil { - return ErrorLeaderTransfer.ErrorParent(c.getErrorCluster(), c.getErrorNodeTarget(targetNodeID), e) + return ErrorLeaderTransfer.Error(c.getErrorCluster(), c.getErrorNodeTarget(targetNodeID), e) } return nil diff --git a/cluster/config.go b/cluster/config.go index 3c4b653e..8f10d63c 100644 --- a/cluster/config.go +++ b/cluster/config.go @@ -68,12 +68,12 @@ func (c Config) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } diff --git a/cluster/configCluster.go b/cluster/configCluster.go index 2648aa1f..821a7d5b 100644 --- a/cluster/configCluster.go +++ b/cluster/configCluster.go @@ -248,12 +248,12 @@ func (c ConfigCluster) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } diff --git a/cluster/configEngine.go b/cluster/configEngine.go index ec0ed272..f49de94a 100644 --- a/cluster/configEngine.go +++ b/cluster/configEngine.go @@ -92,12 +92,12 @@ func (c ConfigEngine) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } diff --git a/cluster/configExpert.go b/cluster/configExpert.go index 8caabc41..d47b56d7 100644 --- a/cluster/configExpert.go +++ b/cluster/configExpert.go @@ -73,12 +73,12 @@ func (c ConfigExpert) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } diff --git a/cluster/configGossip.go b/cluster/configGossip.go index ca253015..39b65710 100644 --- a/cluster/configGossip.go +++ b/cluster/configGossip.go @@ -97,12 +97,12 @@ func (c ConfigGossip) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } diff --git a/cluster/configNode.go b/cluster/configNode.go index d2788168..a42cfefa 100644 --- a/cluster/configNode.go +++ b/cluster/configNode.go @@ -322,12 +322,12 @@ func (c ConfigNode) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } diff --git a/cluster/interface.go b/cluster/interface.go index 9605ae50..83a960a7 100644 --- a/cluster/interface.go +++ b/cluster/interface.go @@ -118,7 +118,7 @@ func NewCluster(cfg Config, fctCreate interface{}) (Cluster, liberr.Error) { } if n, e := dgbclt.NewNodeHost(cfg.GetDGBConfigNode()); e != nil { - return nil, ErrorNodeHostNew.ErrorParent(e) + return nil, ErrorNodeHostNew.Error(e) } else { c.nodeHost = n } diff --git a/cluster/local.go b/cluster/local.go index 64741d8e..e81d3bd1 100644 --- a/cluster/local.go +++ b/cluster/local.go @@ -39,7 +39,7 @@ func (c *cRaft) LocalReadNode(rs *dgbclt.RequestState, query interface{}) (inter i, e := c.nodeHost.ReadLocalNode(rs, query) if e != nil { - return i, ErrorCommandLocal.ErrorParent(c.getErrorCommand("ReadNode"), e) + return i, ErrorCommandLocal.Error(c.getErrorCommand("ReadNode"), e) } return i, nil @@ -49,7 +49,7 @@ func (c *cRaft) LocalNAReadNode(rs *dgbclt.RequestState, query []byte) ([]byte, r, e := c.nodeHost.NAReadLocalNode(rs, query) if e != nil { - return r, ErrorCommandLocal.ErrorParent(c.getErrorCommand("ReadNode"), e) + return r, ErrorCommandLocal.Error(c.getErrorCommand("ReadNode"), e) } return r, nil diff --git a/cluster/sync.go b/cluster/sync.go index b4ddcfd0..dcf7f16a 100644 --- a/cluster/sync.go +++ b/cluster/sync.go @@ -68,7 +68,7 @@ func (c *cRaft) SyncPropose(parent context.Context, session *dgbcli.Session, cmd r, e := c.nodeHost.SyncPropose(ctx, session, cmd) if e != nil { - return r, ErrorCommandSync.ErrorParent(c.getErrorCommand("Propose"), e) + return r, ErrorCommandSync.Error(c.getErrorCommand("Propose"), e) } return r, nil @@ -81,7 +81,7 @@ func (c *cRaft) SyncRead(parent context.Context, query interface{}) (interface{} r, e := c.nodeHost.SyncRead(ctx, c.config.ClusterID, query) if e != nil { - return r, ErrorCommandSync.ErrorParent(c.getErrorCluster(), c.getErrorCommand("Read"), e) + return r, ErrorCommandSync.Error(c.getErrorCluster(), c.getErrorCommand("Read"), e) } return r, nil @@ -94,7 +94,7 @@ func (c *cRaft) SyncGetClusterMembership(parent context.Context) (*dgbclt.Member r, e := c.nodeHost.SyncGetClusterMembership(ctx, c.config.ClusterID) if e != nil { - return r, ErrorCommandSync.ErrorParent(c.getErrorCluster(), c.getErrorCommand("GetClusterMembership"), e) + return r, ErrorCommandSync.Error(c.getErrorCluster(), c.getErrorCommand("GetClusterMembership"), e) } return r, nil @@ -107,7 +107,7 @@ func (c *cRaft) SyncGetSession(parent context.Context) (*dgbcli.Session, liberr. r, e := c.nodeHost.SyncGetSession(ctx, c.config.ClusterID) if e != nil { - return r, ErrorCommandSync.ErrorParent(c.getErrorCluster(), c.getErrorCommand("GetSession"), e) + return r, ErrorCommandSync.Error(c.getErrorCluster(), c.getErrorCommand("GetSession"), e) } return r, nil @@ -120,7 +120,7 @@ func (c *cRaft) SyncCloseSession(parent context.Context, cs *dgbcli.Session) lib e := c.nodeHost.SyncCloseSession(ctx, cs) if e != nil { - return ErrorCommandSync.ErrorParent(c.getErrorCommand("CloseSession"), e) + return ErrorCommandSync.Error(c.getErrorCommand("CloseSession"), e) } return nil @@ -133,7 +133,7 @@ func (c *cRaft) SyncRequestSnapshot(parent context.Context, opt dgbclt.SnapshotO r, e := c.nodeHost.SyncRequestSnapshot(ctx, c.config.ClusterID, opt) if e != nil { - return r, ErrorCommandSync.ErrorParent(c.getErrorCluster(), c.getErrorCommand("RequestSnapshot"), e) + return r, ErrorCommandSync.Error(c.getErrorCluster(), c.getErrorCommand("RequestSnapshot"), e) } return r, nil @@ -154,7 +154,7 @@ func (c *cRaft) SyncRequestDeleteNode(parent context.Context, nodeID uint64, con e := c.nodeHost.SyncRequestDeleteNode(ctx, c.config.ClusterID, nodeID, configChangeIndex) if e != nil { - return ErrorCommandSync.ErrorParent(c.getErrorCluster(), en, c.getErrorCommand("RequestDeleteNode"), e) + return ErrorCommandSync.Error(c.getErrorCluster(), en, c.getErrorCommand("RequestDeleteNode"), e) } return nil @@ -176,7 +176,7 @@ func (c *cRaft) SyncRequestAddNode(parent context.Context, nodeID uint64, target e := c.nodeHost.SyncRequestAddNode(ctx, c.config.ClusterID, nodeID, target, configChangeIndex) if e != nil { - return ErrorCommandSync.ErrorParent(c.getErrorCluster(), en, c.getErrorCommand("RequestAddNode"), e) + return ErrorCommandSync.Error(c.getErrorCluster(), en, c.getErrorCommand("RequestAddNode"), e) } return nil @@ -198,7 +198,7 @@ func (c *cRaft) SyncRequestAddObserver(parent context.Context, nodeID uint64, ta e := c.nodeHost.SyncRequestAddObserver(ctx, c.config.ClusterID, nodeID, target, configChangeIndex) if e != nil { - return ErrorCommandSync.ErrorParent(c.getErrorCluster(), en, c.getErrorCommand("RequestAddObserver"), e) + return ErrorCommandSync.Error(c.getErrorCluster(), en, c.getErrorCommand("RequestAddObserver"), e) } return nil @@ -220,7 +220,7 @@ func (c *cRaft) SyncRequestAddWitness(parent context.Context, nodeID uint64, tar e := c.nodeHost.SyncRequestAddWitness(ctx, c.config.ClusterID, nodeID, target, configChangeIndex) if e != nil { - return ErrorCommandSync.ErrorParent(c.getErrorCluster(), en, c.getErrorCommand("RequestAddWitness"), e) + return ErrorCommandSync.Error(c.getErrorCluster(), en, c.getErrorCommand("RequestAddWitness"), e) } return nil @@ -241,7 +241,7 @@ func (c *cRaft) SyncRemoveData(parent context.Context, nodeID uint64) liberr.Err e := c.nodeHost.SyncRemoveData(ctx, c.config.ClusterID, nodeID) if e != nil { - return ErrorCommandSync.ErrorParent(c.getErrorCluster(), en, c.getErrorCommand("RemoveData"), e) + return ErrorCommandSync.Error(c.getErrorCluster(), en, c.getErrorCommand("RemoveData"), e) } return nil diff --git a/config/components.go b/config/components.go index ad1986b5..0cc3dcdd 100644 --- a/config/components.go +++ b/config/components.go @@ -34,7 +34,6 @@ import ( cfgcst "github.com/nabbar/golib/config/const" cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" spfcbr "github.com/spf13/cobra" "golang.org/x/exp/slices" ) @@ -110,7 +109,7 @@ func (c *configModel) ComponentKeys() []string { return res } -func (c *configModel) ComponentStart() liberr.Error { +func (c *configModel) ComponentStart() error { var err = ErrorComponentStart.Error(nil) for _, key := range c.ComponentDependencies() { @@ -122,9 +121,9 @@ func (c *configModel) ComponentStart() liberr.Error { e := cpt.Start() c.componentUpdate(key, cpt) if e != nil { - err.AddParent(e) + err.Add(e) } else if !cpt.IsStarted() { - err.AddParent(fmt.Errorf("component '%s' has been call to start, but is not started", key)) + err.Add(fmt.Errorf("component '%s' has been call to start, but is not started", key)) } } } @@ -155,7 +154,7 @@ func (c *configModel) ComponentIsStarted() bool { return isOk } -func (c *configModel) ComponentReload() liberr.Error { +func (c *configModel) ComponentReload() error { var err = ErrorComponentReload.Error(nil) for _, key := range c.ComponentDependencies() { @@ -167,9 +166,9 @@ func (c *configModel) ComponentReload() liberr.Error { e := cpt.Reload() c.componentUpdate(key, cpt) if e != nil { - err.AddParent(e) + err.Add(e) } else if !cpt.IsStarted() { - err.AddParent(fmt.Errorf("component '%s' has been call to reload, but is not started", key)) + err.Add(fmt.Errorf("component '%s' has been call to reload, but is not started", key)) } } } @@ -336,7 +335,7 @@ func (c *configModel) RegisterFlag(Command *spfcbr.Command) error { if cpt := c.ComponentGet(k); cpt == nil { continue } else if e := cpt.RegisterFlag(Command); e != nil { - err.AddParent(e) + err.Add(e) } else { c.ComponentSet(k, cpt) } diff --git a/config/components/aws/client.go b/config/components/aws/client.go index 7f7ea28f..f6f68bed 100644 --- a/config/components/aws/client.go +++ b/config/components/aws/client.go @@ -32,7 +32,6 @@ import ( libaws "github.com/nabbar/golib/aws" libtls "github.com/nabbar/golib/certificates" cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" libhtc "github.com/nabbar/golib/httpcli" libreq "github.com/nabbar/golib/request" libver "github.com/nabbar/golib/version" @@ -165,7 +164,7 @@ func (o *componentAws) _getFctEvt(key uint8) cfgtps.FuncCptEvent { } } -func (o *componentAws) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error { +func (o *componentAws) _runFct(fct func(cpt cfgtps.Component) error) error { if fct != nil { return fct(o) } @@ -173,11 +172,9 @@ func (o *componentAws) _runFct(fct func(cpt cfgtps.Component) liberr.Error) libe return nil } -func (o *componentAws) _runCli() liberr.Error { +func (o *componentAws) _runCli() error { var ( - e error - - err liberr.Error + err error cli libaws.AWS cfg libaws.Config mon *libreq.OptionsHealth @@ -226,11 +223,11 @@ func (o *componentAws) _runCli() liberr.Error { o.m.Unlock() if req != nil { - if req, e = opt.Update(o.x.GetContext, req); e != nil { - return prt.ErrorParent(e) + if req, err = opt.Update(o.x.GetContext, req); err != nil { + return prt.Error(err) } - } else if req, e = opt.New(o.x.GetContext); e != nil { - return prt.ErrorParent(e) + } else if req, err = opt.New(o.x.GetContext); err != nil { + return prt.Error(err) } o.m.Lock() @@ -239,8 +236,8 @@ func (o *componentAws) _runCli() liberr.Error { } if mon != nil { - if e = o._registerMonitor(mon, cfg); e != nil { - return prt.ErrorParent(e) + if err = o._registerMonitor(mon, cfg); err != nil { + return prt.Error(err) } } @@ -251,7 +248,7 @@ func (o *componentAws) _runCli() liberr.Error { return nil } -func (o *componentAws) _run() liberr.Error { +func (o *componentAws) _run() error { fb, fa := o._getFct() if err := o._runFct(fb); err != nil { diff --git a/config/components/aws/component.go b/config/components/aws/component.go index a059ef0c..6fdc90bb 100644 --- a/config/components/aws/component.go +++ b/config/components/aws/component.go @@ -29,7 +29,6 @@ package aws import ( cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -95,11 +94,11 @@ func (o *componentAws) IsRunning() bool { return o.IsStarted() } -func (o *componentAws) Start() liberr.Error { +func (o *componentAws) Start() error { return o._run() } -func (o *componentAws) Reload() liberr.Error { +func (o *componentAws) Reload() error { return o._run() } @@ -132,7 +131,7 @@ func (o *componentAws) Dependencies() []string { } } -func (o *componentAws) SetDependencies(d []string) liberr.Error { +func (o *componentAws) SetDependencies(d []string) error { o.m.RLock() defer o.m.RUnlock() diff --git a/config/components/aws/config.go b/config/components/aws/config.go index 1e1ff09b..2527bfc6 100644 --- a/config/components/aws/config.go +++ b/config/components/aws/config.go @@ -30,7 +30,6 @@ import ( libaws "github.com/nabbar/golib/aws" cfgstd "github.com/nabbar/golib/aws/configAws" cfgcus "github.com/nabbar/golib/aws/configCustom" - liberr "github.com/nabbar/golib/errors" libhtc "github.com/nabbar/golib/httpcli" libreq "github.com/nabbar/golib/request" spfcbr "github.com/spf13/cobra" @@ -111,7 +110,7 @@ func (o *componentAws) RegisterFlag(Command *spfcbr.Command) error { return nil } -func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libhtc.Options, liberr.Error) { +func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libhtc.Options, error) { var ( key string cfg libaws.Config @@ -119,7 +118,7 @@ func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libh mon *libreq.OptionsHealth htc *libhtc.Options vpr *spfvpr.Viper - err liberr.Error + err error ) if vpr = o._getSPFViper(); vpr == nil { @@ -131,8 +130,8 @@ func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libh switch o.d { case ConfigCustomStatus: cnf := cfgcus.ModelStatus{} - if e := vpr.UnmarshalKey(key, &cnf); e != nil { - return nil, nil, nil, ErrorParamInvalid.ErrorParent(e) + if err = vpr.UnmarshalKey(key, &cnf); err != nil { + return nil, nil, nil, ErrorParamInvalid.Error(err) } else { flg.updCustom(&cnf.Config) } @@ -146,8 +145,8 @@ func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libh case ConfigCustom: cnf := cfgcus.Model{} - if e := vpr.UnmarshalKey(key, &cnf); e != nil { - return nil, nil, nil, ErrorParamInvalid.ErrorParent(e) + if err = vpr.UnmarshalKey(key, &cnf); err != nil { + return nil, nil, nil, ErrorParamInvalid.Error(err) } else { flg.updCustom(&cnf) } @@ -161,8 +160,8 @@ func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libh case ConfigStandardStatus: cnf := cfgstd.ModelStatus{} - if e := vpr.UnmarshalKey(key, &cnf); e != nil { - return nil, nil, nil, ErrorParamInvalid.ErrorParent(e) + if err = vpr.UnmarshalKey(key, &cnf); err != nil { + return nil, nil, nil, ErrorParamInvalid.Error(err) } else { flg.updStandard(&cnf.Config) } @@ -176,8 +175,8 @@ func (o *componentAws) _getConfig() (libaws.Config, *libreq.OptionsHealth, *libh case ConfigStandard: cnf := cfgstd.Model{} - if e := vpr.UnmarshalKey(key, &cnf); e != nil { - return nil, nil, nil, ErrorParamInvalid.ErrorParent(e) + if err = vpr.UnmarshalKey(key, &cnf); err != nil { + return nil, nil, nil, ErrorParamInvalid.Error(err) } else { flg.updStandard(&cnf) } diff --git a/config/components/aws/driver.go b/config/components/aws/driver.go index 24b51cab..16059fe3 100644 --- a/config/components/aws/driver.go +++ b/config/components/aws/driver.go @@ -32,7 +32,6 @@ import ( libaws "github.com/nabbar/golib/aws" cfgstd "github.com/nabbar/golib/aws/configAws" cfgcus "github.com/nabbar/golib/aws/configCustom" - liberr "github.com/nabbar/golib/errors" ) type ConfigDriver uint8 @@ -70,7 +69,7 @@ func (a ConfigDriver) String() string { } } -func (a ConfigDriver) Unmarshal(p []byte) (libaws.Config, liberr.Error) { +func (a ConfigDriver) Unmarshal(p []byte) (libaws.Config, error) { switch a { case ConfigCustom: return cfgcus.NewConfigJsonUnmashal(p) @@ -107,7 +106,7 @@ func (a ConfigDriver) Model() interface{} { } } -func (a ConfigDriver) NewFromModel(i interface{}) (libaws.Config, liberr.Error) { +func (a ConfigDriver) NewFromModel(i interface{}) (libaws.Config, error) { switch a { case ConfigCustomStatus: if o, ok := i.(cfgcus.ModelStatus); !ok { @@ -126,7 +125,7 @@ func (a ConfigDriver) NewFromModel(i interface{}) (libaws.Config, liberr.Error) return nil, ErrorConfigInvalid.Error(nil) } else { if edp, err := url.Parse(o.Endpoint); err != nil { - return nil, ErrorConfigInvalid.ErrorParent(err) + return nil, ErrorConfigInvalid.Error(err) } else { cfg := cfgcus.NewConfig(o.Bucket, o.AccessKey, o.SecretKey, edp, o.Region) diff --git a/config/components/aws/interface.go b/config/components/aws/interface.go index 5b1985bc..21b3b949 100644 --- a/config/components/aws/interface.go +++ b/config/components/aws/interface.go @@ -34,7 +34,6 @@ import ( libtls "github.com/nabbar/golib/certificates" libcfg "github.com/nabbar/golib/config" cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" ) type ComponentAwsClient interface { @@ -51,7 +50,7 @@ type ComponentAws interface { ComponentAwsClient ComponentAwsAPI - GetAws() (libaws.AWS, liberr.Error) + GetAws() (libaws.AWS, error) SetAws(a libaws.AWS) } diff --git a/config/components/aws/model.go b/config/components/aws/model.go index 3568264c..e5dd49aa 100644 --- a/config/components/aws/model.go +++ b/config/components/aws/model.go @@ -35,7 +35,6 @@ import ( libaws "github.com/nabbar/golib/aws" libtls "github.com/nabbar/golib/certificates" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" montps "github.com/nabbar/golib/monitor/types" ) @@ -64,7 +63,7 @@ func (o *componentAws) RegisterTLS(fct libtls.FctTLSDefault) { o.t = fct } -func (o *componentAws) GetAws() (libaws.AWS, liberr.Error) { +func (o *componentAws) GetAws() (libaws.AWS, error) { o.m.RLock() defer o.m.RUnlock() diff --git a/config/components/database/client.go b/config/components/database/client.go index 801849b6..92ed0427 100644 --- a/config/components/database/client.go +++ b/config/components/database/client.go @@ -32,7 +32,6 @@ import ( "github.com/nabbar/golib/database/gorm" cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" spfvbr "github.com/spf13/viper" @@ -148,7 +147,7 @@ func (o *componentDatabase) _getFctEvt(key uint8) cfgtps.FuncCptEvent { } } -func (o *componentDatabase) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error { +func (o *componentDatabase) _runFct(fct func(cpt cfgtps.Component) error) error { if fct != nil { return fct(o) } @@ -156,9 +155,9 @@ func (o *componentDatabase) _runFct(fct func(cpt cfgtps.Component) liberr.Error) return nil } -func (o *componentDatabase) _runCli() liberr.Error { +func (o *componentDatabase) _runCli() error { var ( - err liberr.Error + err error prt = ErrorComponentReload dbo gorm.Database cfg *gorm.Config @@ -183,13 +182,13 @@ func (o *componentDatabase) _runCli() liberr.Error { o.m.Unlock() if e := o._registerMonitor(cfg); e != nil { - return prt.ErrorParent(e) + return prt.Error(e) } return nil } -func (o *componentDatabase) _run() liberr.Error { +func (o *componentDatabase) _run() error { fb, fa := o._getFct() if err := o._runFct(fb); err != nil { diff --git a/config/components/database/component.go b/config/components/database/component.go index 09e4f461..714e6ebf 100644 --- a/config/components/database/component.go +++ b/config/components/database/component.go @@ -29,7 +29,6 @@ package database import ( cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -103,11 +102,11 @@ func (o *componentDatabase) IsRunning() bool { return true } -func (o *componentDatabase) Start() liberr.Error { +func (o *componentDatabase) Start() error { return o._run() } -func (o *componentDatabase) Reload() liberr.Error { +func (o *componentDatabase) Reload() error { return o._run() } @@ -145,7 +144,7 @@ func (o *componentDatabase) Dependencies() []string { } } -func (o *componentDatabase) SetDependencies(d []string) liberr.Error { +func (o *componentDatabase) SetDependencies(d []string) error { o.m.RLock() defer o.m.RUnlock() diff --git a/config/components/database/config.go b/config/components/database/config.go index 89271416..6634976a 100644 --- a/config/components/database/config.go +++ b/config/components/database/config.go @@ -31,7 +31,6 @@ import ( "github.com/nabbar/golib/database/gorm" - liberr "github.com/nabbar/golib/errors" spfcbr "github.com/spf13/cobra" spfvpr "github.com/spf13/viper" ) @@ -108,12 +107,12 @@ func (o *componentDatabase) RegisterFlag(Command *spfcbr.Command) error { return nil } -func (o *componentDatabase) _getConfig() (*gorm.Config, liberr.Error) { +func (o *componentDatabase) _getConfig() (*gorm.Config, error) { var ( key string cfg gorm.Config vpr *spfvpr.Viper - err liberr.Error + err error ) if vpr = o._getSPFViper(); vpr == nil { @@ -123,7 +122,7 @@ func (o *componentDatabase) _getConfig() (*gorm.Config, liberr.Error) { } if e := vpr.UnmarshalKey(key, &cfg); e != nil { - return nil, ErrorParamInvalid.ErrorParent(e) + return nil, ErrorParamInvalid.Error(e) } cfg.RegisterLogger(o.getLogger, o.li, o.ls) diff --git a/config/components/head/client.go b/config/components/head/client.go index 22f2ac8e..d45ad161 100644 --- a/config/components/head/client.go +++ b/config/components/head/client.go @@ -28,7 +28,6 @@ package head import ( cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" spfvbr "github.com/spf13/viper" @@ -137,7 +136,7 @@ func (o *componentHead) _getFctEvt(key uint8) cfgtps.FuncCptEvent { } } -func (o *componentHead) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error { +func (o *componentHead) _runFct(fct func(cpt cfgtps.Component) error) error { if fct != nil { return fct(o) } @@ -145,7 +144,7 @@ func (o *componentHead) _runFct(fct func(cpt cfgtps.Component) liberr.Error) lib return nil } -func (o *componentHead) _runCli() liberr.Error { +func (o *componentHead) _runCli() error { if cfg, err := o._getConfig(); err != nil { return ErrorParamInvalid.Error(err) } else { @@ -157,7 +156,7 @@ func (o *componentHead) _runCli() liberr.Error { } } -func (o *componentHead) _run() liberr.Error { +func (o *componentHead) _run() error { fb, fa := o._getFct() if err := o._runFct(fb); err != nil { diff --git a/config/components/head/component.go b/config/components/head/component.go index 074189df..cbc72c2e 100644 --- a/config/components/head/component.go +++ b/config/components/head/component.go @@ -29,7 +29,6 @@ package head import ( cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -95,11 +94,11 @@ func (o *componentHead) IsRunning() bool { return o.IsStarted() } -func (o *componentHead) Start() liberr.Error { +func (o *componentHead) Start() error { return o._run() } -func (o *componentHead) Reload() liberr.Error { +func (o *componentHead) Reload() error { return o._run() } @@ -132,7 +131,7 @@ func (o *componentHead) Dependencies() []string { } } -func (o *componentHead) SetDependencies(d []string) liberr.Error { +func (o *componentHead) SetDependencies(d []string) error { o.m.RLock() defer o.m.RUnlock() diff --git a/config/components/head/config.go b/config/components/head/config.go index 6f774ce1..c5346c8b 100644 --- a/config/components/head/config.go +++ b/config/components/head/config.go @@ -27,7 +27,6 @@ package head import ( - liberr "github.com/nabbar/golib/errors" librtr "github.com/nabbar/golib/router" spfcbr "github.com/spf13/cobra" spfvpr "github.com/spf13/viper" @@ -37,12 +36,12 @@ func (o *componentHead) RegisterFlag(Command *spfcbr.Command) error { return nil } -func (o *componentHead) _getConfig() (*librtr.HeadersConfig, liberr.Error) { +func (o *componentHead) _getConfig() (*librtr.HeadersConfig, error) { var ( key string cfg librtr.HeadersConfig vpr *spfvpr.Viper - err liberr.Error + err error ) if vpr = o._getSPFViper(); vpr == nil { @@ -52,7 +51,7 @@ func (o *componentHead) _getConfig() (*librtr.HeadersConfig, liberr.Error) { } if e := vpr.UnmarshalKey(key, &cfg); e != nil { - return nil, ErrorParamInvalid.ErrorParent(e) + return nil, ErrorParamInvalid.Error(e) } if err = cfg.Validate(); err != nil { diff --git a/config/components/http/client.go b/config/components/http/client.go index 085ee899..51bf3329 100644 --- a/config/components/http/client.go +++ b/config/components/http/client.go @@ -33,7 +33,6 @@ import ( libtls "github.com/nabbar/golib/certificates" cpttls "github.com/nabbar/golib/config/components/tls" cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" htpool "github.com/nabbar/golib/httpserver/pool" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -178,7 +177,7 @@ func (o *componentHttp) _getFctEvt(key uint8) cfgtps.FuncCptEvent { } } -func (o *componentHttp) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error { +func (o *componentHttp) _runFct(fct func(cpt cfgtps.Component) error) error { if fct != nil { return fct(o) } @@ -186,10 +185,10 @@ func (o *componentHttp) _runFct(fct func(cpt cfgtps.Component) liberr.Error) lib return nil } -func (o *componentHttp) _runCli() liberr.Error { +func (o *componentHttp) _runCli() error { var ( e error - err liberr.Error + err error prt = ErrorComponentReload pol htpool.Pool cfg *htpool.Config @@ -207,12 +206,12 @@ func (o *componentHttp) _runCli() liberr.Error { defer o.m.RUnlock() if pol, err = cfg.Pool(o.x.GetContext, o._GetHandler, o.getLogger); err != nil { - return prt.ErrorParent(err) + return prt.Error(err) } if o.s != nil && o.s.Len() > 0 { if e = o.s.Merge(pol, o.getLogger); e != nil { - return prt.ErrorParent(e) + return prt.Error(e) } } else { o.m.RUnlock() @@ -223,7 +222,7 @@ func (o *componentHttp) _runCli() liberr.Error { } if e = o.s.Restart(o.x.GetContext()); e != nil { - return prt.ErrorParent(e) + return prt.Error(e) } // Implement wait notify on main call @@ -233,7 +232,7 @@ func (o *componentHttp) _runCli() liberr.Error { return o._registerMonitor(prt) } -func (o *componentHttp) _run() liberr.Error { +func (o *componentHttp) _run() error { fb, fa := o._getFct() if err := o._runFct(fb); err != nil { diff --git a/config/components/http/component.go b/config/components/http/component.go index 16725f96..51710680 100644 --- a/config/components/http/component.go +++ b/config/components/http/component.go @@ -30,7 +30,6 @@ import ( cpttls "github.com/nabbar/golib/config/components/tls" cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -103,11 +102,11 @@ func (o *componentHttp) IsRunning() bool { return o.s.IsRunning() } -func (o *componentHttp) Start() liberr.Error { +func (o *componentHttp) Start() error { return o._run() } -func (o *componentHttp) Reload() liberr.Error { +func (o *componentHttp) Reload() error { return o._run() } @@ -145,7 +144,7 @@ func (o *componentHttp) Dependencies() []string { } } -func (o *componentHttp) SetDependencies(d []string) liberr.Error { +func (o *componentHttp) SetDependencies(d []string) error { o.m.RLock() defer o.m.RUnlock() diff --git a/config/components/http/config.go b/config/components/http/config.go index 2474cd42..3ac4d96c 100644 --- a/config/components/http/config.go +++ b/config/components/http/config.go @@ -29,7 +29,6 @@ package http import ( "fmt" - liberr "github.com/nabbar/golib/errors" htpool "github.com/nabbar/golib/httpserver/pool" spfcbr "github.com/spf13/cobra" spfvpr "github.com/spf13/viper" @@ -39,12 +38,12 @@ func (o *componentHttp) RegisterFlag(Command *spfcbr.Command) error { return nil } -func (o *componentHttp) _getConfig() (*htpool.Config, liberr.Error) { +func (o *componentHttp) _getConfig() (*htpool.Config, error) { var ( key string cfg htpool.Config vpr *spfvpr.Viper - err liberr.Error + err error ) if vpr = o._getSPFViper(); vpr == nil { @@ -54,7 +53,7 @@ func (o *componentHttp) _getConfig() (*htpool.Config, liberr.Error) { } if e := vpr.UnmarshalKey(key, &cfg); e != nil { - return nil, ErrorParamInvalid.ErrorParent(e) + return nil, ErrorParamInvalid.Error(e) } cfg.SetDefaultTLS(o._GetTLS) @@ -64,9 +63,9 @@ func (o *componentHttp) _getConfig() (*htpool.Config, liberr.Error) { if err = cfg.Validate(); err != nil { return nil, ErrorConfigInvalid.Error(err) } else if o.h == nil { - return nil, ErrorComponentNotInitialized.ErrorParent(fmt.Errorf("missing handler")) + return nil, ErrorComponentNotInitialized.Error(fmt.Errorf("missing handler")) } else if len(o.h()) < 1 { - return nil, ErrorComponentNotInitialized.ErrorParent(fmt.Errorf("missing handler")) + return nil, ErrorComponentNotInitialized.Error(fmt.Errorf("missing handler")) } return &cfg, nil diff --git a/config/components/http/monitor.go b/config/components/http/monitor.go index 1b076316..f1f71266 100644 --- a/config/components/http/monitor.go +++ b/config/components/http/monitor.go @@ -52,7 +52,7 @@ func (o *componentHttp) _getMonitorPool() montps.Pool { } } -func (o *componentHttp) _registerMonitor(err liberr.CodeError) liberr.Error { +func (o *componentHttp) _registerMonitor(err liberr.CodeError) error { var ( e error key = o._getKey() @@ -70,7 +70,7 @@ func (o *componentHttp) _registerMonitor(err liberr.CodeError) liberr.Error { } if mon, e = o._newMonitor(vrs); e != nil { - return err.ErrorParent(e) + return err.Error(e) } else if mon == nil { return nil } @@ -84,9 +84,9 @@ func (o *componentHttp) _registerMonitor(err liberr.CodeError) liberr.Error { } if e = m.Restart(ctx()); e != nil { - return err.ErrorParent(e) + return err.Error(e) } else if e = o._setMonitor(m); e != nil { - return err.ErrorParent(e) + return err.Error(e) } } diff --git a/config/components/ldap/client.go b/config/components/ldap/client.go index 4c3cf81f..3ddf0d44 100644 --- a/config/components/ldap/client.go +++ b/config/components/ldap/client.go @@ -28,7 +28,6 @@ package ldap import ( cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" lbldap "github.com/nabbar/golib/ldap" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -138,7 +137,7 @@ func (o *componentLDAP) _getFctEvt(key uint8) cfgtps.FuncCptEvent { } } -func (o *componentLDAP) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error { +func (o *componentLDAP) _runFct(fct func(cpt cfgtps.Component) error) error { if fct != nil { return fct(o) } @@ -146,10 +145,10 @@ func (o *componentLDAP) _runFct(fct func(cpt cfgtps.Component) liberr.Error) lib return nil } -func (o *componentLDAP) _runCli() liberr.Error { +func (o *componentLDAP) _runCli() error { var ( e error - err liberr.Error + err error cli *lbldap.HelperLDAP cfg *lbldap.Config ) @@ -160,7 +159,7 @@ func (o *componentLDAP) _runCli() liberr.Error { if cfg, err = o._getConfig(); err != nil { return ErrorParamInvalid.Error(err) } else if cli, e = lbldap.NewLDAP(o.x.GetContext(), cfg, o.a); e != nil { - return ErrorConfigInvalid.ErrorParent(e) + return ErrorConfigInvalid.Error(e) } else { cli.SetLogger(o.getLogger) } @@ -179,7 +178,7 @@ func (o *componentLDAP) _runCli() liberr.Error { return nil } -func (o *componentLDAP) _run() liberr.Error { +func (o *componentLDAP) _run() error { fb, fa := o._getFct() if err := o._runFct(fb); err != nil { diff --git a/config/components/ldap/component.go b/config/components/ldap/component.go index 9a028ba6..680a5436 100644 --- a/config/components/ldap/component.go +++ b/config/components/ldap/component.go @@ -29,7 +29,6 @@ package ldap import ( cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -95,11 +94,11 @@ func (o *componentLDAP) IsRunning() bool { return o.IsStarted() } -func (o *componentLDAP) Start() liberr.Error { +func (o *componentLDAP) Start() error { return o._run() } -func (o *componentLDAP) Reload() liberr.Error { +func (o *componentLDAP) Reload() error { return o._run() } @@ -134,7 +133,7 @@ func (o *componentLDAP) Dependencies() []string { } } -func (o *componentLDAP) SetDependencies(d []string) liberr.Error { +func (o *componentLDAP) SetDependencies(d []string) error { o.m.RLock() defer o.m.RUnlock() diff --git a/config/components/ldap/config.go b/config/components/ldap/config.go index a72dcb8e..3649ad83 100644 --- a/config/components/ldap/config.go +++ b/config/components/ldap/config.go @@ -27,7 +27,6 @@ package ldap import ( - liberr "github.com/nabbar/golib/errors" lbldap "github.com/nabbar/golib/ldap" spfcbr "github.com/spf13/cobra" spfvpr "github.com/spf13/viper" @@ -37,12 +36,12 @@ func (o *componentLDAP) RegisterFlag(Command *spfcbr.Command) error { return nil } -func (o *componentLDAP) _getConfig() (*lbldap.Config, liberr.Error) { +func (o *componentLDAP) _getConfig() (*lbldap.Config, error) { var ( key string cfg lbldap.Config vpr *spfvpr.Viper - err liberr.Error + err error ) if vpr = o._getSPFViper(); vpr == nil { @@ -52,7 +51,7 @@ func (o *componentLDAP) _getConfig() (*lbldap.Config, liberr.Error) { } if e := vpr.UnmarshalKey(key, &cfg); e != nil { - return nil, ErrorParamInvalid.ErrorParent(e) + return nil, ErrorParamInvalid.Error(e) } if err = cfg.Validate(); err != nil { diff --git a/config/components/log/client.go b/config/components/log/client.go index 97f21b88..d73118b8 100644 --- a/config/components/log/client.go +++ b/config/components/log/client.go @@ -28,7 +28,6 @@ package log import ( cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" logcfg "github.com/nabbar/golib/logger/config" libver "github.com/nabbar/golib/version" @@ -139,7 +138,7 @@ func (o *componentLog) _getFctEvt(key uint8) cfgtps.FuncCptEvent { } } -func (o *componentLog) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error { +func (o *componentLog) _runFct(fct func(cpt cfgtps.Component) error) error { if fct != nil { return fct(o) } @@ -147,10 +146,10 @@ func (o *componentLog) _runFct(fct func(cpt cfgtps.Component) liberr.Error) libe return nil } -func (o *componentLog) _runCli() liberr.Error { +func (o *componentLog) _runCli() error { var ( e error - err liberr.Error + err error prt = ErrorReloadLog cfg *logcfg.Options ) @@ -174,13 +173,13 @@ func (o *componentLog) _runCli() liberr.Error { defer o.m.RUnlock() if e = o.l.SetOptions(cfg); e != nil { - return prt.ErrorParent(e) + return prt.Error(e) } return nil } -func (o *componentLog) _run() liberr.Error { +func (o *componentLog) _run() error { fb, fa := o._getFct() if err := o._runFct(fb); err != nil { diff --git a/config/components/log/component.go b/config/components/log/component.go index 55f805e2..c9dec39f 100644 --- a/config/components/log/component.go +++ b/config/components/log/component.go @@ -29,7 +29,6 @@ package log import ( cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -95,11 +94,11 @@ func (o *componentLog) IsRunning() bool { return o.IsStarted() } -func (o *componentLog) Start() liberr.Error { +func (o *componentLog) Start() error { return o._run() } -func (o *componentLog) Reload() liberr.Error { +func (o *componentLog) Reload() error { return o._run() } @@ -133,7 +132,7 @@ func (o *componentLog) Dependencies() []string { } } -func (o *componentLog) SetDependencies(d []string) liberr.Error { +func (o *componentLog) SetDependencies(d []string) error { o.m.RLock() defer o.m.RUnlock() diff --git a/config/components/log/config.go b/config/components/log/config.go index f2493e37..31f2e129 100644 --- a/config/components/log/config.go +++ b/config/components/log/config.go @@ -27,7 +27,6 @@ package log import ( - liberr "github.com/nabbar/golib/errors" logcfg "github.com/nabbar/golib/logger/config" spfcbr "github.com/spf13/cobra" spfvpr "github.com/spf13/viper" @@ -70,12 +69,12 @@ func (o *componentLog) RegisterFlag(Command *spfcbr.Command) error { return nil } -func (o *componentLog) _getConfig() (*logcfg.Options, liberr.Error) { +func (o *componentLog) _getConfig() (*logcfg.Options, error) { var ( key string cfg logcfg.Options vpr *spfvpr.Viper - err liberr.Error + err error ) if vpr = o._getSPFViper(); vpr == nil { @@ -85,7 +84,7 @@ func (o *componentLog) _getConfig() (*logcfg.Options, liberr.Error) { } if e := vpr.UnmarshalKey(key, &cfg); e != nil { - return nil, ErrorParamInvalid.ErrorParent(e) + return nil, ErrorParamInvalid.Error(e) } if cfg.Stdout == nil { diff --git a/config/components/log/interface.go b/config/components/log/interface.go index d1d0d37e..97f76f43 100644 --- a/config/components/log/interface.go +++ b/config/components/log/interface.go @@ -32,7 +32,6 @@ import ( libcfg "github.com/nabbar/golib/config" cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" logcfg "github.com/nabbar/golib/logger/config" logfld "github.com/nabbar/golib/logger/fields" @@ -54,7 +53,7 @@ type ComponentLog interface { SetField(fields logfld.Fields) GetField() logfld.Fields - SetOptions(opt *logcfg.Options) liberr.Error + SetOptions(opt *logcfg.Options) error GetOptions() *logcfg.Options } diff --git a/config/components/log/model.go b/config/components/log/model.go index d0f620bd..9f6d9a2c 100644 --- a/config/components/log/model.go +++ b/config/components/log/model.go @@ -30,7 +30,6 @@ import ( "sync" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" logcfg "github.com/nabbar/golib/logger/config" logfld "github.com/nabbar/golib/logger/fields" @@ -109,7 +108,7 @@ func (o *componentLog) GetOptions() *logcfg.Options { return o.l.GetOptions() } -func (o *componentLog) SetOptions(opt *logcfg.Options) liberr.Error { +func (o *componentLog) SetOptions(opt *logcfg.Options) error { o.m.Lock() defer o.m.Unlock() @@ -118,7 +117,7 @@ func (o *componentLog) SetOptions(opt *logcfg.Options) liberr.Error { } if e := o.l.SetOptions(opt); e != nil { - return ErrorConfigInvalid.ErrorParent(e) + return ErrorConfigInvalid.Error(e) } return nil diff --git a/config/components/mail/client.go b/config/components/mail/client.go index 5f015731..bb9dfc72 100644 --- a/config/components/mail/client.go +++ b/config/components/mail/client.go @@ -30,7 +30,6 @@ import ( "context" cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" libmail "github.com/nabbar/golib/mail" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -147,7 +146,7 @@ func (o *componentMail) _getFctEvt(key uint8) cfgtps.FuncCptEvent { } } -func (o *componentMail) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error { +func (o *componentMail) _runFct(fct func(cpt cfgtps.Component) error) error { if fct != nil { return fct(o) } @@ -155,9 +154,9 @@ func (o *componentMail) _runFct(fct func(cpt cfgtps.Component) liberr.Error) lib return nil } -func (o *componentMail) _runCli() liberr.Error { +func (o *componentMail) _runCli() error { var ( - err liberr.Error + err error prt = ErrorComponentReload obj libmail.Mail cfg *libmail.Config @@ -182,7 +181,7 @@ func (o *componentMail) _runCli() liberr.Error { return nil } -func (o *componentMail) _run() liberr.Error { +func (o *componentMail) _run() error { fb, fa := o._getFct() if err := o._runFct(fb); err != nil { diff --git a/config/components/mail/component.go b/config/components/mail/component.go index c8122e99..ff10fbd5 100644 --- a/config/components/mail/component.go +++ b/config/components/mail/component.go @@ -29,7 +29,6 @@ package mail import ( cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -95,11 +94,11 @@ func (o *componentMail) IsRunning() bool { return o.IsStarted() } -func (o *componentMail) Start() liberr.Error { +func (o *componentMail) Start() error { return o._run() } -func (o *componentMail) Reload() liberr.Error { +func (o *componentMail) Reload() error { return o._run() } @@ -132,7 +131,7 @@ func (o *componentMail) Dependencies() []string { } } -func (o *componentMail) SetDependencies(d []string) liberr.Error { +func (o *componentMail) SetDependencies(d []string) error { o.m.RLock() defer o.m.RUnlock() diff --git a/config/components/mail/config.go b/config/components/mail/config.go index 9cbe6707..acc458a0 100644 --- a/config/components/mail/config.go +++ b/config/components/mail/config.go @@ -27,7 +27,6 @@ package mail import ( - liberr "github.com/nabbar/golib/errors" libmail "github.com/nabbar/golib/mail" spfcbr "github.com/spf13/cobra" spfvpr "github.com/spf13/viper" @@ -78,12 +77,12 @@ func (o *componentMail) RegisterFlag(Command *spfcbr.Command) error { return nil } -func (o *componentMail) _getConfig() (*libmail.Config, liberr.Error) { +func (o *componentMail) _getConfig() (*libmail.Config, error) { var ( key string cfg libmail.Config vpr *spfvpr.Viper - err liberr.Error + err error ) if vpr = o._getSPFViper(); vpr == nil { @@ -93,7 +92,7 @@ func (o *componentMail) _getConfig() (*libmail.Config, liberr.Error) { } if e := vpr.UnmarshalKey(key, &cfg); e != nil { - return nil, ErrorParamInvalid.ErrorParent(e) + return nil, ErrorParamInvalid.Error(e) } if len(cfg.Headers) < 1 { diff --git a/config/components/mail/interface.go b/config/components/mail/interface.go index 6387229d..b1ac045e 100644 --- a/config/components/mail/interface.go +++ b/config/components/mail/interface.go @@ -32,14 +32,13 @@ import ( libcfg "github.com/nabbar/golib/config" cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" libmail "github.com/nabbar/golib/mail" ) type ComponentMail interface { cfgtps.Component - GetMail() (libmail.Mail, liberr.Error) + GetMail() (libmail.Mail, error) } func New(ctx libctx.FuncContext) ComponentMail { diff --git a/config/components/mail/model.go b/config/components/mail/model.go index 681d10e9..864e5951 100644 --- a/config/components/mail/model.go +++ b/config/components/mail/model.go @@ -30,7 +30,6 @@ import ( "sync" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" libmail "github.com/nabbar/golib/mail" ) @@ -40,7 +39,7 @@ type componentMail struct { e libmail.Mail } -func (o *componentMail) GetMail() (libmail.Mail, liberr.Error) { +func (o *componentMail) GetMail() (libmail.Mail, error) { if !o.IsStarted() { return nil, ErrorComponentNotInitialized.Error(nil) } diff --git a/config/components/request/client.go b/config/components/request/client.go index 86a55c32..48405312 100644 --- a/config/components/request/client.go +++ b/config/components/request/client.go @@ -32,7 +32,6 @@ import ( libtls "github.com/nabbar/golib/certificates" cpttls "github.com/nabbar/golib/config/components/tls" cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" libreq "github.com/nabbar/golib/request" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -166,7 +165,7 @@ func (o *componentRequest) _getFctEvt(key uint8) cfgtps.FuncCptEvent { } } -func (o *componentRequest) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error { +func (o *componentRequest) _runFct(fct func(cpt cfgtps.Component) error) error { if fct != nil { return fct(o) } @@ -174,10 +173,10 @@ func (o *componentRequest) _runFct(fct func(cpt cfgtps.Component) liberr.Error) return nil } -func (o *componentRequest) _runCli() liberr.Error { +func (o *componentRequest) _runCli() error { var ( e error - err liberr.Error + err error prt = ErrorComponentReload req libreq.Request cfg *libreq.Options @@ -198,11 +197,11 @@ func (o *componentRequest) _runCli() liberr.Error { if req != nil { if req, e = cfg.Update(o.x.GetContext, req); err != nil { - return prt.ErrorParent(e) + return prt.Error(e) } } else { if req, e = cfg.New(o.x.GetContext); err != nil { - return prt.ErrorParent(e) + return prt.Error(e) } } @@ -211,13 +210,13 @@ func (o *componentRequest) _runCli() liberr.Error { o.m.Unlock() if e = o._registerMonitor(cfg); e != nil { - return prt.ErrorParent(e) + return prt.Error(e) } return nil } -func (o *componentRequest) _run() liberr.Error { +func (o *componentRequest) _run() error { fb, fa := o._getFct() if err := o._runFct(fb); err != nil { diff --git a/config/components/request/component.go b/config/components/request/component.go index a50940fb..c28d177b 100644 --- a/config/components/request/component.go +++ b/config/components/request/component.go @@ -30,7 +30,6 @@ import ( cpttls "github.com/nabbar/golib/config/components/tls" cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -96,11 +95,11 @@ func (o *componentRequest) IsRunning() bool { return o.IsStarted() } -func (o *componentRequest) Start() liberr.Error { +func (o *componentRequest) Start() error { return o._run() } -func (o *componentRequest) Reload() liberr.Error { +func (o *componentRequest) Reload() error { return o._run() } @@ -137,7 +136,7 @@ func (o *componentRequest) Dependencies() []string { } } -func (o *componentRequest) SetDependencies(d []string) liberr.Error { +func (o *componentRequest) SetDependencies(d []string) error { o.m.RLock() defer o.m.RUnlock() diff --git a/config/components/request/config.go b/config/components/request/config.go index 8d7a26d2..82acbe5c 100644 --- a/config/components/request/config.go +++ b/config/components/request/config.go @@ -27,7 +27,6 @@ package request import ( - liberr "github.com/nabbar/golib/errors" libreq "github.com/nabbar/golib/request" spfcbr "github.com/spf13/cobra" spfvpr "github.com/spf13/viper" @@ -37,12 +36,12 @@ func (o *componentRequest) RegisterFlag(Command *spfcbr.Command) error { return nil } -func (o *componentRequest) _getConfig() (*libreq.Options, liberr.Error) { +func (o *componentRequest) _getConfig() (*libreq.Options, error) { var ( key string cfg libreq.Options vpr *spfvpr.Viper - err liberr.Error + err error ) if vpr = o._getSPFViper(); vpr == nil { @@ -52,7 +51,7 @@ func (o *componentRequest) _getConfig() (*libreq.Options, liberr.Error) { } if e := vpr.UnmarshalKey(key, &cfg); e != nil { - return nil, ErrorParamInvalid.ErrorParent(e) + return nil, ErrorParamInvalid.Error(e) } if err = cfg.Validate(); err != nil { diff --git a/config/components/smtp/client.go b/config/components/smtp/client.go index 7d57ea1c..aed87df5 100644 --- a/config/components/smtp/client.go +++ b/config/components/smtp/client.go @@ -33,7 +33,6 @@ import ( libtls "github.com/nabbar/golib/certificates" cpttls "github.com/nabbar/golib/config/components/tls" cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" moncfg "github.com/nabbar/golib/monitor/types" lbsmtp "github.com/nabbar/golib/smtp" smtpcf "github.com/nabbar/golib/smtp/config" @@ -177,7 +176,7 @@ func (o *componentSmtp) _getFctEvt(key uint8) cfgtps.FuncCptEvent { } } -func (o *componentSmtp) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error { +func (o *componentSmtp) _runFct(fct func(cpt cfgtps.Component) error) error { if fct != nil { return fct(o) } @@ -185,10 +184,10 @@ func (o *componentSmtp) _runFct(fct func(cpt cfgtps.Component) liberr.Error) lib return nil } -func (o *componentSmtp) _runCli() liberr.Error { +func (o *componentSmtp) _runCli() error { var ( e error - err liberr.Error + err error prt = ErrorComponentReload obj lbsmtp.SMTP cfg smtpcf.Config @@ -212,13 +211,13 @@ func (o *componentSmtp) _runCli() liberr.Error { o.m.Unlock() if e = o._registerMonitor(mon); e != nil { - return prt.ErrorParent(e) + return prt.Error(e) } return nil } -func (o *componentSmtp) _run() liberr.Error { +func (o *componentSmtp) _run() error { fb, fa := o._getFct() if err := o._runFct(fb); err != nil { diff --git a/config/components/smtp/component.go b/config/components/smtp/component.go index 1abbfa80..50326dd1 100644 --- a/config/components/smtp/component.go +++ b/config/components/smtp/component.go @@ -30,7 +30,6 @@ import ( cpttls "github.com/nabbar/golib/config/components/tls" cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -103,11 +102,11 @@ func (o *componentSmtp) IsRunning() bool { return o.s.Check(o.x.GetContext()) == nil } -func (o *componentSmtp) Start() liberr.Error { +func (o *componentSmtp) Start() error { return o._run() } -func (o *componentSmtp) Reload() liberr.Error { +func (o *componentSmtp) Reload() error { return o._run() } @@ -148,7 +147,7 @@ func (o *componentSmtp) Dependencies() []string { } } -func (o *componentSmtp) SetDependencies(d []string) liberr.Error { +func (o *componentSmtp) SetDependencies(d []string) error { o.m.RLock() defer o.m.RUnlock() diff --git a/config/components/smtp/config.go b/config/components/smtp/config.go index d67b6ffd..5ee9a3f8 100644 --- a/config/components/smtp/config.go +++ b/config/components/smtp/config.go @@ -27,7 +27,6 @@ package smtp import ( - liberr "github.com/nabbar/golib/errors" libmon "github.com/nabbar/golib/monitor/types" smtpcf "github.com/nabbar/golib/smtp/config" spfcbr "github.com/spf13/cobra" @@ -55,12 +54,12 @@ func (o *componentSmtp) RegisterFlag(Command *spfcbr.Command) error { return nil } -func (o *componentSmtp) _getConfig() (smtpcf.Config, *libmon.Config, liberr.Error) { +func (o *componentSmtp) _getConfig() (smtpcf.Config, *libmon.Config, error) { var ( key string cfg smtpcf.ConfigModel vpr *spfvpr.Viper - err liberr.Error + err error ) if vpr = o._getSPFViper(); vpr == nil { @@ -70,7 +69,7 @@ func (o *componentSmtp) _getConfig() (smtpcf.Config, *libmon.Config, liberr.Erro } if e := vpr.UnmarshalKey(key, &cfg); e != nil { - return nil, nil, ErrorParamInvalid.ErrorParent(e) + return nil, nil, ErrorParamInvalid.Error(e) } if val := vpr.GetString(key + "dsn"); val != "" { diff --git a/config/components/smtp/interface.go b/config/components/smtp/interface.go index c31792a4..9ce003ed 100644 --- a/config/components/smtp/interface.go +++ b/config/components/smtp/interface.go @@ -33,7 +33,6 @@ import ( cpttls "github.com/nabbar/golib/config/components/tls" cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" lbsmtp "github.com/nabbar/golib/smtp" ) @@ -41,7 +40,7 @@ type ComponentSMTP interface { cfgtps.Component SetTLSKey(tlsKey string) - GetSMTP() (lbsmtp.SMTP, liberr.Error) + GetSMTP() (lbsmtp.SMTP, error) } func New(ctx libctx.FuncContext, tlsKey string) ComponentSMTP { diff --git a/config/components/smtp/model.go b/config/components/smtp/model.go index 52bc0028..fb405595 100644 --- a/config/components/smtp/model.go +++ b/config/components/smtp/model.go @@ -30,7 +30,6 @@ import ( "sync" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" montps "github.com/nabbar/golib/monitor/types" libsmtp "github.com/nabbar/golib/smtp" ) @@ -50,7 +49,7 @@ func (o *componentSmtp) SetTLSKey(tlsKey string) { o.t = tlsKey } -func (o *componentSmtp) GetSMTP() (libsmtp.SMTP, liberr.Error) { +func (o *componentSmtp) GetSMTP() (libsmtp.SMTP, error) { if !o.IsStarted() { return nil, ErrorComponentNotInitialized.Error(nil) } diff --git a/config/components/tls/client.go b/config/components/tls/client.go index 09bd5ed6..a4636399 100644 --- a/config/components/tls/client.go +++ b/config/components/tls/client.go @@ -29,7 +29,6 @@ package tls import ( libtls "github.com/nabbar/golib/certificates" cfgtps "github.com/nabbar/golib/config/types" - liberr "github.com/nabbar/golib/errors" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" spfvbr "github.com/spf13/viper" @@ -138,7 +137,7 @@ func (o *componentTls) _getFctEvt(key uint8) cfgtps.FuncCptEvent { } } -func (o *componentTls) _runFct(fct func(cpt cfgtps.Component) liberr.Error) liberr.Error { +func (o *componentTls) _runFct(fct func(cpt cfgtps.Component) error) error { if fct != nil { return fct(o) } @@ -146,9 +145,9 @@ func (o *componentTls) _runFct(fct func(cpt cfgtps.Component) liberr.Error) libe return nil } -func (o *componentTls) _runCli() liberr.Error { +func (o *componentTls) _runCli() error { var ( - err liberr.Error + err error prt = ErrorComponentReload tls libtls.TLSConfig cfg *libtls.Config @@ -173,7 +172,7 @@ func (o *componentTls) _runCli() liberr.Error { return nil } -func (o *componentTls) _run() liberr.Error { +func (o *componentTls) _run() error { fb, fa := o._getFct() if err := o._runFct(fb); err != nil { diff --git a/config/components/tls/component.go b/config/components/tls/component.go index 6d7722ad..4cfbfa5d 100644 --- a/config/components/tls/component.go +++ b/config/components/tls/component.go @@ -29,7 +29,6 @@ package tls import ( cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" @@ -95,11 +94,11 @@ func (o *componentTls) IsRunning() bool { return o.IsStarted() } -func (o *componentTls) Start() liberr.Error { +func (o *componentTls) Start() error { return o._run() } -func (o *componentTls) Reload() liberr.Error { +func (o *componentTls) Reload() error { return o._run() } @@ -132,7 +131,7 @@ func (o *componentTls) Dependencies() []string { } } -func (o *componentTls) SetDependencies(d []string) liberr.Error { +func (o *componentTls) SetDependencies(d []string) error { o.m.RLock() defer o.m.RUnlock() diff --git a/config/components/tls/config.go b/config/components/tls/config.go index 5e85c7b8..f622becf 100644 --- a/config/components/tls/config.go +++ b/config/components/tls/config.go @@ -28,7 +28,6 @@ package tls import ( libtls "github.com/nabbar/golib/certificates" - liberr "github.com/nabbar/golib/errors" spfcbr "github.com/spf13/cobra" spfvpr "github.com/spf13/viper" ) @@ -37,12 +36,12 @@ func (o *componentTls) RegisterFlag(Command *spfcbr.Command) error { return nil } -func (o *componentTls) _getConfig() (*libtls.Config, liberr.Error) { +func (o *componentTls) _getConfig() (*libtls.Config, error) { var ( key string cfg libtls.Config vpr *spfvpr.Viper - err liberr.Error + err error ) if vpr = o._getSPFViper(); vpr == nil { @@ -52,7 +51,7 @@ func (o *componentTls) _getConfig() (*libtls.Config, liberr.Error) { } if e := vpr.UnmarshalKey(key, &cfg); e != nil { - return nil, ErrorParamInvalid.ErrorParent(e) + return nil, ErrorParamInvalid.Error(e) } if err = cfg.Validate(); err != nil { diff --git a/config/events.go b/config/events.go index c01c1e42..411b7efe 100644 --- a/config/events.go +++ b/config/events.go @@ -28,11 +28,9 @@ package config import ( "os" - - liberr "github.com/nabbar/golib/errors" ) -func (c *configModel) Start() liberr.Error { +func (c *configModel) Start() error { if err := c.runFuncStartBefore(); err != nil { return err } @@ -48,7 +46,7 @@ func (c *configModel) Start() liberr.Error { return nil } -func (c *configModel) Reload() liberr.Error { +func (c *configModel) Reload() error { if err := c.runFuncReloadBefore(); err != nil { return err } diff --git a/config/interface.go b/config/interface.go index 572606a2..e90e5253 100644 --- a/config/interface.go +++ b/config/interface.go @@ -35,14 +35,13 @@ import ( cfgtps "github.com/nabbar/golib/config/types" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" shlcmd "github.com/nabbar/golib/shell/command" libver "github.com/nabbar/golib/version" libvpr "github.com/nabbar/golib/viper" ) -type FuncEvent func() liberr.Error +type FuncEvent func() error type Config interface { /* @@ -67,10 +66,10 @@ type Config interface { // Start will trigger the start function of all registered component. // If any component return an error, this func will stop the start // process and return the error. - Start() liberr.Error + Start() error // Reload triggers the Reload function of each registered Component. - Reload() liberr.Error + Reload() error // Stop will trigger the stop function of all registered component. // All component must stop cleanly. diff --git a/config/manage.go b/config/manage.go index ae79e1c3..4431df98 100644 --- a/config/manage.go +++ b/config/manage.go @@ -27,7 +27,6 @@ package config import ( - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" montps "github.com/nabbar/golib/monitor/types" libver "github.com/nabbar/golib/version" @@ -79,7 +78,7 @@ func (c *configModel) RegisterFuncStartBefore(fct FuncEvent) { c.fct.Store(fctStartBefore, fct) } -func (c *configModel) runFuncStartBefore() liberr.Error { +func (c *configModel) runFuncStartBefore() error { if i, l := c.fct.Load(fctStartBefore); !l { return nil } else if v, k := i.(FuncEvent); !k { @@ -95,7 +94,7 @@ func (c *configModel) RegisterFuncStartAfter(fct FuncEvent) { c.fct.Store(fctStartAfter, fct) } -func (c *configModel) runFuncStartAfter() liberr.Error { +func (c *configModel) runFuncStartAfter() error { if i, l := c.fct.Load(fctStartAfter); !l { return nil } else if v, k := i.(FuncEvent); !k { @@ -111,7 +110,7 @@ func (c *configModel) RegisterFuncReloadBefore(fct FuncEvent) { c.fct.Store(fctReloadBefore, fct) } -func (c *configModel) runFuncReloadBefore() liberr.Error { +func (c *configModel) runFuncReloadBefore() error { if i, l := c.fct.Load(fctReloadBefore); !l { return nil } else if v, k := i.(FuncEvent); !k { @@ -127,7 +126,7 @@ func (c *configModel) RegisterFuncReloadAfter(fct FuncEvent) { c.fct.Store(fctReloadAfter, fct) } -func (c *configModel) runFuncReloadAfter() liberr.Error { +func (c *configModel) runFuncReloadAfter() error { if i, l := c.fct.Load(fctReloadAfter); !l { return nil } else if v, k := i.(FuncEvent); !k { @@ -143,7 +142,7 @@ func (c *configModel) RegisterFuncStopBefore(fct FuncEvent) { c.fct.Store(fctStopBefore, fct) } -func (c *configModel) runFuncStopBefore() liberr.Error { +func (c *configModel) runFuncStopBefore() error { if i, l := c.fct.Load(fctStopBefore); !l { return nil } else if v, k := i.(FuncEvent); !k { @@ -159,7 +158,7 @@ func (c *configModel) RegisterFuncStopAfter(fct FuncEvent) { c.fct.Store(fctStopAfter, fct) } -func (c *configModel) runFuncStopAfter() liberr.Error { +func (c *configModel) runFuncStopAfter() error { if i, l := c.fct.Load(fctStopAfter); !l { return nil } else if v, k := i.(FuncEvent); !k { diff --git a/config/model.go b/config/model.go index 1d7f41a8..689a0080 100644 --- a/config/model.go +++ b/config/model.go @@ -30,7 +30,6 @@ import ( "sync" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" ) const ( @@ -56,13 +55,13 @@ type configModel struct { fcnl []func() } -func (c *configModel) _ComponentGetConfig(key string, model interface{}) liberr.Error { +func (c *configModel) _ComponentGetConfig(key string, model interface{}) error { if vpr := c.getViper(); vpr == nil { return ErrorConfigMissingViper.Error(nil) } else if vip := vpr.Viper(); vip == nil { return ErrorConfigMissingViper.Error(nil) } else if err := vpr.Viper().UnmarshalKey(key, model); err != nil { - return ErrorComponentConfigError.ErrorParent(err) + return ErrorComponentConfigError.Error(err) } return nil diff --git a/config/types/component.go b/config/types/component.go index 687a2272..fb20d139 100644 --- a/config/types/component.go +++ b/config/types/component.go @@ -28,7 +28,6 @@ package types import ( libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" liblog "github.com/nabbar/golib/logger" montps "github.com/nabbar/golib/monitor/types" libver "github.com/nabbar/golib/version" @@ -37,7 +36,7 @@ import ( ) type FuncCptGet func(key string) Component -type FuncCptEvent func(cpt Component) liberr.Error +type FuncCptEvent func(cpt Component) error type ComponentEvent interface { // RegisterFuncStart is called to register the function to be called before and after the start function. @@ -59,12 +58,12 @@ type ComponentEvent interface { // Start is called by the Config interface when the global configuration as been started // This function can be usefull to start server in go routine with a configuration stored // itself. - Start() liberr.Error + Start() error // Reload is called by the Config interface when the global configuration as been updated // It receives a func as param to grab a config model by sending a model structure. // It must configure itself, and stop / start his server if possible or return an error. - Reload() liberr.Error + Reload() error // Stop is called by the Config interface when global context is done. // The context done can arrive by stopping the application or by received a signal KILL/TERM. @@ -103,7 +102,7 @@ type Component interface { // SetDependencies allow to customize the dependencies for the current component. // The custom dependencies will replace the default dependencies. // Take care to be sure to include the default dependencies into the custom given as params. - SetDependencies(d []string) liberr.Error + SetDependencies(d []string) error ComponentViper ComponentEvent diff --git a/config/types/componentList.go b/config/types/componentList.go index 6769e7d4..84a84537 100644 --- a/config/types/componentList.go +++ b/config/types/componentList.go @@ -29,7 +29,6 @@ package types import ( "io" - liberr "github.com/nabbar/golib/errors" spfcbr "github.com/spf13/cobra" ) @@ -68,7 +67,7 @@ type ComponentList interface { // ComponentStart trigger the Start function of each Component. // This function will keep the dependencies of each Component. // This function will stop the Start sequence on any error triggered. - ComponentStart() liberr.Error + ComponentStart() error // ComponentIsStarted will trigger the IsStarted function of all registered component. // If any component return false, this func return false. @@ -77,7 +76,7 @@ type ComponentList interface { // ComponentReload trigger the Reload function of each Component. // This function will keep the dependencies of each Component. // This function will stop the Reload sequence on any error triggered. - ComponentReload() liberr.Error + ComponentReload() error // ComponentStop trigger the Stop function of each Component. // This function will not keep the dependencies of each Component. diff --git a/console/color.go b/console/color.go index 074f4b6d..cc17ce99 100644 --- a/console/color.go +++ b/console/color.go @@ -97,7 +97,7 @@ func (c colorType) BuffPrintf(buff io.Writer, format string, args ...interface{} i, e := colorList[c].Fprintf(buff, format, args...) if e != nil { - return i, ErrorColorIOFprintf.ErrorParent(e) + return i, ErrorColorIOFprintf.Error(e) } return i, nil @@ -107,7 +107,7 @@ func (c colorType) BuffPrintf(buff io.Writer, format string, args ...interface{} i, e := buff.Write([]byte(fmt.Sprintf(format, args...))) if e != nil { - return i, ErrorColorBufWrite.ErrorParent(e) + return i, ErrorColorBufWrite.Error(e) } return i, nil diff --git a/crypt/crypt.go b/crypt/crypt.go index 97e27ed4..33146703 100644 --- a/crypt/crypt.go +++ b/crypt/crypt.go @@ -49,13 +49,13 @@ func SetKeyHex(key, nonce string) errors.Error { cryptKey, err = hex.DecodeString(key) if err != nil { - return ErrorHexaKey.ErrorParent(err) + return ErrorHexaKey.Error(err) } cryptNonce, err = hex.DecodeString(nonce) if err != nil { - return ErrorHexaNonce.ErrorParent(err) + return ErrorHexaNonce.Error(err) } return nil @@ -69,12 +69,12 @@ func SetKeyByte(key [32]byte, nonce [12]byte) { func GenKeyByte() ([]byte, []byte, errors.Error) { // Never use more than 2^32 random key with a given key because of the risk of a repeat. if _, err := io.ReadFull(rand.Reader, cryptKey); err != nil { - return make([]byte, 32), make([]byte, 12), ErrorByteKeygen.ErrorParent(err) + return make([]byte, 32), make([]byte, 12), ErrorByteKeygen.Error(err) } // Never use more than 2^32 random nonces with a given key because of the risk of a repeat. if _, err := io.ReadFull(rand.Reader, cryptNonce); err != nil { - return make([]byte, 32), make([]byte, 12), ErrorByteNonceGen.ErrorParent(err) + return make([]byte, 32), make([]byte, 12), ErrorByteNonceGen.Error(err) } return cryptKey, cryptNonce, nil @@ -84,12 +84,12 @@ func Encrypt(clearValue []byte) (string, errors.Error) { // When decoded the key should be 16 bytes (AES-128) or 32 (AES-256). block, err := aes.NewCipher(cryptKey) if err != nil { - return "", ErrorAESBlock.ErrorParent(err) + return "", ErrorAESBlock.Error(err) } aesgcm, err := cipher.NewGCM(block) if err != nil { - return "", ErrorAESGCM.ErrorParent(err) + return "", ErrorAESGCM.Error(err) } return hex.EncodeToString(aesgcm.Seal(nil, cryptNonce, clearValue, nil)), nil @@ -99,21 +99,21 @@ func Decrypt(hexaVal string) ([]byte, errors.Error) { // When decoded the key should be 16 bytes (AES-128) or 32 (AES-256). ciphertext, err := hex.DecodeString(hexaVal) if err != nil { - return nil, ErrorHexaDecode.ErrorParent(err) + return nil, ErrorHexaDecode.Error(err) } block, err := aes.NewCipher(cryptKey) if err != nil { - return nil, ErrorAESBlock.ErrorParent(err) + return nil, ErrorAESBlock.Error(err) } aesgcm, err := cipher.NewGCM(block) if err != nil { - return nil, ErrorAESGCM.ErrorParent(err) + return nil, ErrorAESGCM.Error(err) } if res, err := aesgcm.Open(nil, cryptNonce, ciphertext, nil); err != nil { - return res, ErrorAESDecrypt.ErrorParent(err) + return res, ErrorAESDecrypt.Error(err) } else { return res, nil } diff --git a/database/gorm/config.go b/database/gorm/config.go index 9a68152b..fd70a29a 100644 --- a/database/gorm/config.go +++ b/database/gorm/config.go @@ -113,12 +113,12 @@ func (c *Config) Validate() liberr.Error { if err := libval.New().Struct(c); err != nil { if er, ok := err.(*libval.InvalidValidationError); ok { - e.AddParent(er) + e.Add(er) } for _, er := range err.(libval.ValidationErrors) { //nolint #goerr113 - e.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) + e.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) } } @@ -179,7 +179,7 @@ func (c *Config) New(cfg *gormdb.Config) (*gormdb.DB, liberr.Error) { o, e := gormdb.Open(c.Driver.Dialector(c.DSN), cfg) if e != nil { - return nil, ErrorDatabaseOpen.ErrorParent(e) + return nil, ErrorDatabaseOpen.Error(e) } if c.ctx != nil { @@ -190,7 +190,7 @@ func (c *Config) New(cfg *gormdb.Config) (*gormdb.DB, liberr.Error) { var db *sql.DB if db, e = o.DB(); e != nil { - return nil, ErrorDatabaseOpenPool.ErrorParent(e) + return nil, ErrorDatabaseOpenPool.Error(e) } if c.PoolMaxIdleConns > 0 { diff --git a/database/gorm/model.go b/database/gorm/model.go index 7a492522..04e9e24f 100644 --- a/database/gorm/model.go +++ b/database/gorm/model.go @@ -142,9 +142,9 @@ func (d *database) CheckConn() liberr.Error { } if v, e := o.DB(); e != nil { - return ErrorDatabaseCannotSQLDB.ErrorParent(e) + return ErrorDatabaseCannotSQLDB.Error(e) } else if e = v.Ping(); e != nil { - return ErrorDatabasePing.ErrorParent(e) + return ErrorDatabasePing.Error(e) } return nil diff --git a/errors/code.go b/errors/code.go index d3bccf6e..07fe8d1e 100644 --- a/errors/code.go +++ b/errors/code.go @@ -72,22 +72,12 @@ func (c CodeError) GetMessage() string { return UnknownMessage } -func (c CodeError) Error(p Error) Error { - return NewError(c.GetUint16(), c.GetMessage(), p) +func (c CodeError) Error(p ...error) Error { + return New(c.GetUint16(), c.GetMessage(), p...) } -func (c CodeError) ErrorParent(p ...error) Error { - e := c.Error(nil) - e.AddParent(p...) - return e -} - -func (c CodeError) IfError(e Error) Error { - return NewErrorIfError(c.GetUint16(), c.GetMessage(), e) -} - -func (c CodeError) Iferror(e error) Error { - return NewErrorIferror(c.GetUint16(), c.GetMessage(), e) +func (c CodeError) IfError(e error) Error { + return IfError(c.GetUint16(), c.GetMessage(), e) } func GetCodePackages(rootPackage string) map[CodeError]string { diff --git a/errors/errors.go b/errors/errors.go index 9cd68dac..a896aebb 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -27,29 +27,17 @@ package errors import ( - errs "errors" + "errors" "fmt" "runtime" - "strconv" "strings" ) var ( - defaultGlue = ", " defaultPattern = "[Error #%s] %s" defaultPatternTrace = "[Error #%s] %s (%s)" ) -// SetTracePathFilter define the glue string to be used to join main error with parents'errors. -func SetDefaultGlue(glue string) { - defaultGlue = glue -} - -// GetDefaultGlue return the current glue used to joins errors with parents. -func GetDefaultGlue() string { - return defaultGlue -} - // GetDefaultPatternTrace define the pattern to be used for string of error with code. // The pattern is fmt pattern with 2 inputs in order : code, message. func SetDefaultPattern(pattern string) { @@ -79,24 +67,24 @@ func SetTracePathFilter(path string) { filterPkg = path } -type errors struct { +type ers struct { c uint16 e string p []Error t runtime.Frame } -type FuncMap func(e Error) bool +type FuncMap func(e error) bool type Error interface { - //IsCodeError check if the given error code is matching with the current Error - IsCodeError(code CodeError) bool - //HasCodeError check if current error or parent has the given error code - HasCodeError(code CodeError) bool - //GetCodeError return the CodeError value of the current error - GetCodeError() CodeError - //GetCodeErrorParent return a slice of CodeError value of all parent Error and the code of the current Error - GetCodeErrorParent() []CodeError + //IsCode check if the given error code is matching with the current Error + IsCode(code CodeError) bool + //HasCode check if current error or parent has the given error code + HasCode(code CodeError) bool + //GetCode return the CodeError value of the current error + GetCode() CodeError + //GetParentCode return a slice of CodeError value of all parent Error and the code of the current Error + GetParentCode() []CodeError //IsError check if the given error params is a valid error and not a nil pointer IsError(e error) bool @@ -105,37 +93,29 @@ type Error interface { //HasParent check if the current Error has any valid parent HasParent() bool //GetParent return a slice of Error interface for each parent error with or without the first error. - GetParent(withMainError bool) []Error + GetParent(withMainError bool) []error //Map run a function on each func and parent. If the function return false, the loop stop. Map(fct FuncMap) bool + //ContainsString return true if any message into the main error or the parent message error contains the given part string + ContainsString(s string) bool - //AddParent will add all no empty given error into parent of the current Error pointer - AddParent(parent ...error) + //Add will add all no empty given error into parent of the current Error pointer + Add(parent ...error) //SetParent will replace all parent with the given error list SetParent(parent ...error) - //AddParentError will add all no empty given Error into parent of the current Error pointer - AddParentError(parent ...Error) - //SetParentError will replace all parent with the given Error list - SetParentError(parent ...Error) //Code is used to return the code of current Error, as string - Code() string - //CodeFull is used to return a joint string of code of current Error and code of all parent Error - CodeFull(glue string) string + Code() uint16 //CodeSlice is used to return a slice string of all code of current Error (main and parent) - CodeSlice() []string + CodeSlice() []uint16 //CodeError is used to return a composed string of current Error code with message, for current Error and no parent CodeError(pattern string) string - //CodeErrorFull is used to return a composed string of couple error code with message, for current Error and all parent - CodeErrorFull(pattern, glue string) string //CodeErrorSlice is used to return a composed string slice of couple error code with message, for current Error and all parent CodeErrorSlice(pattern string) []string //CodeErrorTrace is used to return a composed string of current Error code with message and trace information, for current Error and no parent CodeErrorTrace(pattern string) string - //CodeErrorTraceFull is used to return a composed string of couple error code with message and trace information, for current Error and all parent - CodeErrorTraceFull(pattern, glue string) string //CodeErrorTraceSlice is used to return a composed string slice of couple error code with message and trace information, for current Error and all parent CodeErrorTraceSlice(pattern string) []string @@ -145,23 +125,14 @@ type Error interface { //StringError is used to return the error message, for current Error and no parent StringError() string - //StringErrorFull is used to return the error message, for current Error and all parent - StringErrorFull(glue string) string //StringErrorSlice is used to return the error message, for current Error and all parent, as a slice of string StringErrorSlice() []string //GetError is used to return a new error interface based of the current error (and no parent) GetError() error - //GetErrorFull is used to return a new error interface based of the current error with all parent - GetErrorFull(glue string) error //GetErrorSlice is used to return a slice of new error interface, based of the current error and all parent GetErrorSlice() []error - //GetIError is used to return a Error interface pointer based of current Error - GetIError() Error - //GetIErrorSlice is used to return a slice of Error interface pointer, based of current Error and all parents - GetIErrorSlice() []Error - //GetTrace will return a comped string for the trace of the current Error GetTrace() string //GetTrace will return a slice of comped string fpr the trace of the current Error and all parent @@ -183,31 +154,109 @@ type Errors interface { ErrorsList() []error } -func MakeErrorIfError(err ...Error) Error { +func Is(e error) bool { + var err Error + return errors.As(e, &err) +} + +func Get(e error) Error { + var err Error + + if errors.As(e, &err) { + return err + } + + return nil +} + +func Has(e error, code CodeError) bool { + if err := Get(e); err == nil { + return false + } else { + return err.HasCode(code) + } +} + +func ContainsString(e error, s string) bool { + if e == nil { + return false + } else if err := Get(e); err == nil { + return strings.Contains(e.Error(), s) + } else { + return err.ContainsString(s) + } +} + +func IsCode(e error, code CodeError) bool { + if err := Get(e); err == nil { + return false + } else { + return err.IsCode(code) + } +} + +func Make(e error) Error { + var err Error + + if e == nil { + return nil + } else if errors.As(e, &err) { + return err + } else { + return &ers{ + c: 0, + e: e.Error(), + p: nil, + t: getNilFrame(), + } + } +} + +func MakeIfError(err ...error) Error { var e Error = nil for _, p := range err { if p == nil { continue - } - if e == nil { - e = p + } else if e == nil { + e = Make(p) } else { - e.AddParentError(p) + e.Add(p) } } return e } -func NewError(code uint16, message string, parent Error) Error { +func AddOrNew(errMain, errSub error, parent ...error) Error { + var e Error + + if errMain != nil { + if e = Get(errMain); e == nil { + e = New(0, errMain.Error()) + } + e.Add(errSub) + e.Add(parent...) + return e + } else if errSub != nil { + return New(0, errSub.Error(), parent...) + } + + return nil +} + +func New(code uint16, message string, parent ...error) Error { var p = make([]Error, 0) - if parent != nil { - p = parent.GetIErrorSlice() + if len(parent) > 0 { + for _, e := range parent { + if er := Make(e); er != nil { + p = append(p, er) + } + } } - return &errors{ + return &ers{ c: code, e: message, p: p, @@ -215,14 +264,18 @@ func NewError(code uint16, message string, parent Error) Error { } } -func NewErrorTrace(code int, msg string, file string, line int, parent Error) Error { +func NewErrorTrace(code int, msg string, file string, line int, parent ...error) Error { var p = make([]Error, 0) - if parent != nil { - p = parent.GetIErrorSlice() + if len(parent) > 0 { + for _, e := range parent { + if er := Make(e); er != nil { + p = append(p, er) + } + } } - return &errors{ + return &ers{ c: uint16(code), e: msg, p: p, @@ -237,7 +290,7 @@ func NewErrorRecovered(msg string, recovered string, parent ...error) Error { var p = make([]Error, 0) if recovered != "" { - p = append(p, &errors{ + p = append(p, &ers{ c: 0, e: recovered, p: nil, @@ -245,16 +298,10 @@ func NewErrorRecovered(msg string, recovered string, parent ...error) Error { } if len(parent) > 0 { - for _, err := range parent { - if err == nil { - continue + for _, e := range parent { + if er := Make(e); er != nil { + p = append(p, er) } - - p = append(p, &errors{ - c: 0, - e: err.Error(), - p: nil, - }) } } @@ -265,7 +312,7 @@ func NewErrorRecovered(msg string, recovered string, parent ...error) Error { msg += "\n " + fmt.Sprintf("Fct: %s - File: %s - Line: %d", t.Function, t.File, t.Line) } - return &errors{ + return &ers{ c: 0, e: msg, p: p, @@ -273,66 +320,62 @@ func NewErrorRecovered(msg string, recovered string, parent ...error) Error { } } -func NewErrorIferror(code uint16, message string, parent error) Error { - if parent == nil { - return nil - } - +func IfError(code uint16, message string, parent ...error) Error { p := make([]Error, 0) - p = append(p, &errors{ - c: 0, - e: parent.Error(), - p: nil, - }) - return &errors{ - c: code, - e: message, - p: p, - t: getFrame(), + if len(parent) > 0 { + for _, e := range parent { + if er := Make(e); er != nil { + p = append(p, er) + } + } } -} -func NewErrorIfError(code uint16, message string, parent Error) Error { - if parent == nil { + if len(p) < 1 { return nil } - return &errors{ + return &ers{ c: code, e: message, - p: parent.GetIErrorSlice(), + p: p, t: getFrame(), } } -func (e *errors) AddParent(parent ...error) { +func (e *ers) Add(parent ...error) { for _, v := range parent { - if v != nil { - e.p = append(e.p, &errors{ + if v == nil { + continue + } + + if err, ok := v.(Error); !ok { + e.p = append(e.p, &ers{ c: 0, e: v.Error(), p: nil, }) + } else { + e.p = append(e.p, err) } } } -func (e *errors) IsCodeError(code CodeError) bool { +func (e *ers) IsCode(code CodeError) bool { return e.c == code.GetUint16() } -func (e *errors) IsError(err error) bool { +func (e *ers) IsError(err error) bool { return e.e == err.Error() } -func (e *errors) HasCodeError(code CodeError) bool { - if e.IsCodeError(code) { +func (e *ers) HasCode(code CodeError) bool { + if e.IsCode(code) { return true } for _, p := range e.p { - if p.IsCodeError(code) { + if p.IsCode(code) { return true } } @@ -340,22 +383,22 @@ func (e *errors) HasCodeError(code CodeError) bool { return false } -func (e *errors) GetCodeError() CodeError { +func (e *ers) GetCode() CodeError { return CodeError(e.c) } -func (e *errors) GetCodeErrorParent() []CodeError { +func (e *ers) GetParentCode() []CodeError { var res = make([]CodeError, 0) - res = append(res, e.GetCodeError()) + res = append(res, e.GetCode()) for _, p := range e.p { - res = append(res, p.GetCodeErrorParent()...) + res = append(res, p.GetParentCode()...) } return unicCodeSlice(res) } -func (e *errors) HasError(err error) bool { +func (e *ers) HasError(err error) bool { if e.IsError(err) { return true } @@ -369,15 +412,15 @@ func (e *errors) HasError(err error) bool { return false } -func (e *errors) HasParent() bool { +func (e *ers) HasParent() bool { return len(e.p) > 0 } -func (e *errors) GetParent(withMainError bool) []Error { - var res = make([]Error, 0) +func (e *ers) GetParent(withMainError bool) []error { + var res = make([]error, 0) if withMainError { - res = append(res, &errors{ + res = append(res, &ers{ c: e.c, e: e.e, p: nil, @@ -394,12 +437,12 @@ func (e *errors) GetParent(withMainError bool) []Error { return res } -func (e *errors) SetParent(parent ...error) { +func (e *ers) SetParent(parent ...error) { e.p = make([]Error, 0) - e.AddParent(parent...) + e.Add(parent...) } -func (e *errors) Map(fct FuncMap) bool { +func (e *ers) Map(fct FuncMap) bool { if !fct(e) { return false } else if len(e.p) > 0 { @@ -413,57 +456,45 @@ func (e *errors) Map(fct FuncMap) bool { return true } -func (e *errors) AddParentError(parent ...Error) { - for _, p := range parent { - if p != nil { - e.p = append(e.p, p) +func (e *ers) ContainsString(s string) bool { + if strings.Contains(e.e, s) { + return true + } else { + for _, i := range e.p { + if i.ContainsString(s) { + return true + } } } -} - -func (e *errors) SetParentError(parent ...Error) { - e.p = parent -} -func (e *errors) Code() string { - return strconv.Itoa(int(e.c)) + return false } -func (e *errors) CodeFull(glue string) string { - if glue == "" { - glue = defaultGlue - } - - return strings.Join(e.CodeSlice(), glue) +func (e *ers) Code() uint16 { + return e.c } -func (e *errors) CodeSlice() []string { - var r = []string{e.Code()} +func (e *ers) CodeSlice() []uint16 { + var r = []uint16{e.Code()} for _, v := range e.p { - r = append(r, v.Code()) + if v.Code() > 0 { + r = append(r, v.Code()) + } } return r } -func (e *errors) Error() string { +func (e *ers) Error() string { return modeError.error(e) } -func (e *errors) StringError() string { +func (e *ers) StringError() string { return e.e } -func (e *errors) StringErrorFull(glue string) string { - if glue == "" { - glue = defaultGlue - } - - return strings.Join(e.StringErrorSlice(), glue) -} - -func (e *errors) StringErrorSlice() []string { +func (e *ers) StringErrorSlice() []string { var r = []string{e.StringError()} for _, v := range e.p { @@ -473,17 +504,12 @@ func (e *errors) StringErrorSlice() []string { return r } -func (e *errors) GetError() error { +func (e *ers) GetError() error { //nolint goerr113 - return errs.New(e.e) + return fmt.Errorf(e.e) } -func (e *errors) GetErrorFull(glue string) error { - //nolint goerr113 - return errs.New(e.StringErrorFull(glue)) -} - -func (e *errors) GetErrorSlice() []error { +func (e *ers) GetErrorSlice() []error { var r = []error{e.GetError()} for _, v := range e.p { @@ -495,21 +521,7 @@ func (e *errors) GetErrorSlice() []error { return r } -func (e *errors) GetIError() Error { - return e -} - -func (e *errors) GetIErrorSlice() []Error { - var r = []Error{e} - - for _, v := range e.p { - r = append(r, v.GetIError()) - } - - return r -} - -func (e *errors) GetTrace() string { +func (e *ers) GetTrace() string { if e.t.File != "" { return fmt.Sprintf("%s#%d", filterPath(e.t.File), e.t.Line) } else if e.t.Function != "" { @@ -519,7 +531,7 @@ func (e *errors) GetTrace() string { return "" } -func (e *errors) GetTraceSlice() []string { +func (e *ers) GetTraceSlice() []string { var r = []string{e.GetTrace()} for _, v := range e.p { @@ -531,22 +543,14 @@ func (e *errors) GetTraceSlice() []string { return r } -func (e *errors) CodeError(pattern string) string { +func (e *ers) CodeError(pattern string) string { if pattern == "" { pattern = defaultPattern } return fmt.Sprintf(pattern, e.Code(), e.StringError()) } -func (e *errors) CodeErrorFull(pattern, glue string) string { - if glue == "" { - glue = defaultGlue - } - - return strings.Join(e.CodeErrorSlice(pattern), glue) -} - -func (e *errors) CodeErrorSlice(pattern string) []string { +func (e *ers) CodeErrorSlice(pattern string) []string { var r = []string{e.CodeError(pattern)} for _, v := range e.p { @@ -556,7 +560,7 @@ func (e *errors) CodeErrorSlice(pattern string) []string { return r } -func (e *errors) CodeErrorTrace(pattern string) string { +func (e *ers) CodeErrorTrace(pattern string) string { if pattern == "" { pattern = defaultPatternTrace } @@ -564,15 +568,7 @@ func (e *errors) CodeErrorTrace(pattern string) string { return fmt.Sprintf(pattern, e.Code(), e.StringError(), e.GetTrace()) } -func (e *errors) CodeErrorTraceFull(pattern, glue string) string { - if glue == "" { - glue = defaultGlue - } - - return strings.Join(e.CodeErrorTraceSlice(pattern), glue) -} - -func (e *errors) CodeErrorTraceSlice(pattern string) []string { +func (e *ers) CodeErrorTraceSlice(pattern string) []string { var r = []string{e.CodeErrorTrace(pattern)} for _, v := range e.p { @@ -582,12 +578,12 @@ func (e *errors) CodeErrorTraceSlice(pattern string) []string { return r } -func (e *errors) Return(r Return) { +func (e *ers) Return(r Return) { e.ReturnError(r.SetError) e.ReturnParent(r.AddParent) } -func (e *errors) ReturnError(f ReturnError) { +func (e *ers) ReturnError(f ReturnError) { if e.t.File != "" { f(int(e.c), e.e, e.t.File, e.t.Line) } else { @@ -595,7 +591,7 @@ func (e *errors) ReturnError(f ReturnError) { } } -func (e *errors) ReturnParent(f ReturnError) { +func (e *ers) ReturnParent(f ReturnError) { for _, p := range e.p { p.ReturnError(f) p.ReturnParent(f) diff --git a/errors/mode.go b/errors/mode.go index f791fdbc..1a4b3b20 100644 --- a/errors/mode.go +++ b/errors/mode.go @@ -26,6 +26,11 @@ package errors +import ( + "fmt" + "strings" +) + var modeError = Default func SetModeReturnError(mode ErrorMode) { @@ -76,27 +81,27 @@ func (m ErrorMode) String() string { return Default.String() } -func (m ErrorMode) error(e *errors) string { +func (m ErrorMode) error(e *ers) string { //nolint exhaustive switch m { case Default: return e.StringError() case ErrorReturnCode: - return e.Code() + return fmt.Sprintf("%v", e.Code()) case ErrorReturnCodeFull: - return e.CodeFull("") + return fmt.Sprintf("%v", e.CodeSlice()) case ErrorReturnCodeError: return e.CodeError("") case ErrorReturnCodeErrorFull: - return e.CodeErrorFull("", "") + return strings.Join(e.CodeErrorSlice(""), ", ") case ErrorReturnCodeErrorTrace: return e.CodeErrorTrace("") case ErrorReturnCodeErrorTraceFull: - return e.CodeErrorTraceFull("", "") + return strings.Join(e.CodeErrorTraceSlice(""), ", ") case ErrorReturnStringError: return e.StringError() case ErrorReturnStringErrorFull: - return e.StringErrorFull("") + return strings.Join(e.StringErrorSlice(), ", ") } return Default.error(e) diff --git a/file/progress/model.go b/file/progress/model.go index ac2aa41f..06b7964e 100644 --- a/file/progress/model.go +++ b/file/progress/model.go @@ -72,7 +72,7 @@ func (o *progress) Stat() (os.FileInfo, error) { } if i, e := o.fos.Stat(); e != nil { - return i, ErrorIOFileStat.ErrorParent(e) + return i, ErrorIOFileStat.Error(e) } else { return i, nil } diff --git a/ftpclient/config.go b/ftpclient/config.go index 4ca5c27f..a91d2d59 100644 --- a/ftpclient/config.go +++ b/ftpclient/config.go @@ -86,12 +86,12 @@ func (c *Config) Validate() liberr.Error { if err := libval.New().Struct(c); err != nil { if er, ok := err.(*libval.InvalidValidationError); ok { - e.AddParent(er) + e.Add(er) } for _, er := range err.(libval.ValidationErrors) { //nolint #goerr113 - e.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) + e.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) } } @@ -151,11 +151,11 @@ func (c *Config) New() (*libftp.ServerConn, liberr.Error) { } if cli, err := libftp.Dial(c.Hostname, opt...); err != nil { - return nil, ErrorFTPConnection.ErrorParent(err) + return nil, ErrorFTPConnection.Error(err) } else if c.Login == "" && c.Password == "" { return cli, nil } else if err = cli.Login(c.Login, c.Password); err != nil { - return cli, ErrorFTPLogin.ErrorParent(err) + return cli, ErrorFTPLogin.Error(err) } else { return cli, nil } diff --git a/ftpclient/model.go b/ftpclient/model.go index 0d485c5f..10ad39ed 100644 --- a/ftpclient/model.go +++ b/ftpclient/model.go @@ -121,7 +121,7 @@ func (f *ftpClient) Connect() liberr.Error { } if e = cli.NoOp(); e != nil { - return ErrorFTPConnectionCheck.ErrorParent(e) + return ErrorFTPConnectionCheck.Error(e) } f.setClient(cli) @@ -142,7 +142,7 @@ func (f *ftpClient) Check() liberr.Error { } if e := cli.NoOp(); e != nil { - return ErrorFTPConnectionCheck.ErrorParent(e) + return ErrorFTPConnectionCheck.Error(e) } return nil } @@ -159,7 +159,7 @@ func (f *ftpClient) NameList(path string) ([]string, liberr.Error) { } if r, e := f.getClient().NameList(path); e != nil { - return nil, ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "NameList", "NLST")) + return nil, ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "NameList", "NLST")) } else { return r, nil } @@ -171,7 +171,7 @@ func (f *ftpClient) List(path string) ([]*libftp.Entry, liberr.Error) { } if r, e := f.getClient().List(path); e != nil { - return nil, ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "List", "MLSD/LIST")) + return nil, ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "List", "MLSD/LIST")) } else { return r, nil } @@ -183,7 +183,7 @@ func (f *ftpClient) ChangeDir(path string) liberr.Error { } if e := f.getClient().ChangeDir(path); e != nil { - return ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "ChangeDir", "CWD")) + return ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "ChangeDir", "CWD")) } else { return nil } @@ -195,7 +195,7 @@ func (f *ftpClient) CurrentDir() (string, liberr.Error) { } if r, e := f.getClient().CurrentDir(); e != nil { - return "", ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "CurrentDir", "PWD")) + return "", ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "CurrentDir", "PWD")) } else { return r, nil } @@ -207,7 +207,7 @@ func (f *ftpClient) FileSize(path string) (int64, liberr.Error) { } if r, e := f.getClient().FileSize(path); e != nil { - return 0, ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "FileSize", "SIZE")) + return 0, ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "FileSize", "SIZE")) } else { return r, nil } @@ -219,7 +219,7 @@ func (f *ftpClient) GetTime(path string) (time.Time, liberr.Error) { } if r, e := f.getClient().GetTime(path); e != nil { - return time.Time{}, ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "GetTime", "MDTM")) + return time.Time{}, ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "GetTime", "MDTM")) } else { return r, nil } @@ -231,7 +231,7 @@ func (f *ftpClient) SetTime(path string, t time.Time) liberr.Error { } if e := f.getClient().SetTime(path, t); e != nil { - return ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "SetTime", "MFMT/MDTM")) + return ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "SetTime", "MFMT/MDTM")) } else { return nil } @@ -243,7 +243,7 @@ func (f *ftpClient) Retr(path string) (*libftp.Response, liberr.Error) { } if r, e := f.getClient().Retr(path); e != nil { - return nil, ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "Retr", "RETR")) + return nil, ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "Retr", "RETR")) } else { return r, nil } @@ -255,7 +255,7 @@ func (f *ftpClient) RetrFrom(path string, offset uint64) (*libftp.Response, erro } if r, e := f.getClient().RetrFrom(path, offset); e != nil { - return nil, ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "RetrFrom", "RETR")) + return nil, ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "RetrFrom", "RETR")) } else { return r, nil } @@ -267,7 +267,7 @@ func (f *ftpClient) Stor(path string, r io.Reader) liberr.Error { } if e := f.getClient().Stor(path, r); e != nil { - return ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "Stor", "STOR")) + return ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "Stor", "STOR")) } else { return nil } @@ -279,7 +279,7 @@ func (f *ftpClient) StorFrom(path string, r io.Reader, offset uint64) liberr.Err } if e := f.getClient().StorFrom(path, r, offset); e != nil { - return ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "StorFrom", "STOR")) + return ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "StorFrom", "STOR")) } else { return nil } @@ -291,7 +291,7 @@ func (f *ftpClient) Append(path string, r io.Reader) liberr.Error { } if e := f.getClient().Append(path, r); e != nil { - return ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "Append", "APPE")) + return ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "Append", "APPE")) } else { return nil } @@ -303,7 +303,7 @@ func (f *ftpClient) Rename(from, to string) liberr.Error { } if e := f.getClient().Rename(from, to); e != nil { - return ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "Rename", "RNFR/RNTO")) + return ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "Rename", "RNFR/RNTO")) } else { return nil } @@ -315,7 +315,7 @@ func (f *ftpClient) Delete(path string) liberr.Error { } if e := f.getClient().Delete(path); e != nil { - return ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "Delete", "DELE")) + return ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "Delete", "DELE")) } else { return nil } @@ -327,7 +327,7 @@ func (f *ftpClient) RemoveDirRecur(path string) liberr.Error { } if e := f.getClient().RemoveDirRecur(path); e != nil { - return ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "RemoveDirRecur", "DELE/RMD")) + return ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "RemoveDirRecur", "DELE/RMD")) } else { return nil } @@ -339,7 +339,7 @@ func (f *ftpClient) MakeDir(path string) liberr.Error { } if e := f.getClient().MakeDir(path); e != nil { - return ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "MakeDir", "MKD")) + return ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "MakeDir", "MKD")) } else { return nil } @@ -351,7 +351,7 @@ func (f *ftpClient) RemoveDir(path string) liberr.Error { } if e := f.getClient().RemoveDir(path); e != nil { - return ErrorFTPCommand.ErrorParent(e, fmt.Errorf("command : %s = %s", "MakeDir", "RMD")) + return ErrorFTPCommand.Error(e, fmt.Errorf("command : %s = %s", "MakeDir", "RMD")) } else { return nil } diff --git a/httpcli/cli.go b/httpcli/cli.go index f755a69a..28b7aee9 100644 --- a/httpcli/cli.go +++ b/httpcli/cli.go @@ -104,7 +104,7 @@ func SetTransportDial(tr *http.Transport, forceIp bool, netw libptc.NetworkProto func GetClient(tr *http.Transport, http2Tr bool, GlobalTimeout time.Duration) (*http.Client, liberr.Error) { if http2Tr { if e := http2.ConfigureTransport(tr); e != nil { - return nil, ErrorClientTransportHttp2.ErrorParent(e) + return nil, ErrorClientTransportHttp2.Error(e) } } diff --git a/httpcli/options.go b/httpcli/options.go index ba0c61dc..d0095726 100644 --- a/httpcli/options.go +++ b/httpcli/options.go @@ -102,12 +102,12 @@ func (o Options) Validate() liberr.Error { if err := libval.New().Struct(o); err != nil { if er, ok := err.(*libval.InvalidValidationError); ok { - e.AddParent(er) + e.Add(er) } for _, er := range err.(libval.ValidationErrors) { //nolint #goerr113 - e.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) + e.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) } } diff --git a/httpserver/config.go b/httpserver/config.go index c799d08b..f2001212 100644 --- a/httpserver/config.go +++ b/httpserver/config.go @@ -253,7 +253,7 @@ func (c *Config) CheckTLS() (libtls.TLSConfig, liberr.Error) { if ssl, err := c.GetTLS(); err != nil { return nil, err } else if ssl == nil || ssl.LenCertificatePair() < 1 { - return nil, ErrorServerValidate.ErrorParent(fmt.Errorf("not certificates defined")) + return nil, ErrorServerValidate.Error(fmt.Errorf("not certificates defined")) } else { return ssl, nil } @@ -342,12 +342,12 @@ func (c *Config) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } @@ -400,7 +400,7 @@ func (o *srv) SetConfig(cfg Config, defLog liblog.FuncLog) error { if o.HandlerHas(cfg.HandlerKey) { o.HandlerStoreFct(cfg.HandlerKey) } else { - return ErrorServerValidate.ErrorParent(fmt.Errorf("handler is missing or not existing")) + return ErrorServerValidate.Error(fmt.Errorf("handler is missing or not existing")) } o.c.Store(cfgName, cfg.Name) diff --git a/httpserver/pool/config.go b/httpserver/pool/config.go index 89eb9827..980a28fd 100644 --- a/httpserver/pool/config.go +++ b/httpserver/pool/config.go @@ -67,7 +67,7 @@ func (p Config) Pool(ctx libctx.FuncContext, hdl srvtps.FuncHandler, defLog libl p.Walk(func(cfg libhtp.Config) bool { if err := r.StoreNew(cfg, defLog); err != nil { - e.AddParent(err) + e.Add(err) } return true }) @@ -98,7 +98,7 @@ func (p Config) Validate() liberr.Error { var err liberr.Error if err = cfg.Validate(); err != nil { - e.AddParentError(err) + e.Add(err) } return true diff --git a/httpserver/pool/model.go b/httpserver/pool/model.go index ded82f1b..6ebdceb9 100644 --- a/httpserver/pool/model.go +++ b/httpserver/pool/model.go @@ -127,7 +127,7 @@ func (o *pool) Monitor(vrs libver.Version) ([]montps.Monitor, liberr.Error) { o.Walk(func(bindAddress string, srv libhtp.Server) bool { if p, e := srv.Monitor(vrs); e != nil { - err.AddParent(e) + err.Add(e) } else { res = append(res, p) } diff --git a/httpserver/pool/server.go b/httpserver/pool/server.go index 1eed1586..f3426bca 100644 --- a/httpserver/pool/server.go +++ b/httpserver/pool/server.go @@ -37,7 +37,7 @@ func (o *pool) Start(ctx context.Context) error { o.Walk(func(bindAddress string, srv libhtp.Server) bool { if e := srv.Start(ctx); e != nil { - err.AddParent(e) + err.Add(e) } else { o.Store(srv) } @@ -57,7 +57,7 @@ func (o *pool) Stop(ctx context.Context) error { o.Walk(func(bindAddress string, srv libhtp.Server) bool { if e := srv.Stop(ctx); e != nil { - err.AddParent(e) + err.Add(e) } else { o.Store(srv) } @@ -77,7 +77,7 @@ func (o *pool) Restart(ctx context.Context) error { o.Walk(func(bindAddress string, srv libhtp.Server) bool { if e := srv.Restart(ctx); e != nil { - err.AddParent(e) + err.Add(e) } else { o.Store(srv) } diff --git a/httpserver/run.go b/httpserver/run.go index cdd15284..5837aedc 100644 --- a/httpserver/run.go +++ b/httpserver/run.go @@ -158,7 +158,7 @@ func (o *srv) runFuncStart(ctx context.Context) (err error) { ent.Log() return err } else if ser = o.getServer(); ser == nil { - err = ErrorServerStart.ErrorParent(fmt.Errorf("cannot create new server, cannot retrieve server")) + err = ErrorServerStart.Error(fmt.Errorf("cannot create new server, cannot retrieve server")) ent := o.logger().Entry(loglvl.ErrorLevel, "starting http server") ent.ErrorAdd(true, err) ent.Log() @@ -208,7 +208,7 @@ func (o *srv) runFuncStop(ctx context.Context) (err error) { }() if ser = o.getServer(); ser == nil { - err = ErrorServerStart.ErrorParent(fmt.Errorf("cannot retrieve server")) + err = ErrorServerStart.Error(fmt.Errorf("cannot retrieve server")) ent := o.logger().Entry(loglvl.ErrorLevel, "starting http server") ent.ErrorAdd(true, err) ent.Log() diff --git a/httpserver/server.go b/httpserver/server.go index 10761898..b52dc734 100644 --- a/httpserver/server.go +++ b/httpserver/server.go @@ -82,7 +82,7 @@ func (o *srv) setServer(ctx context.Context) error { ) if o.IsTLS() && ssl == nil { - err := ErrorServerValidate.ErrorParent(fmt.Errorf("TLS Config is not well defined")) + err := ErrorServerValidate.Error(fmt.Errorf("TLS Config is not well defined")) ent := o.logger().Entry(loglvl.ErrorLevel, "starting http server") ent.ErrorAdd(true, err) ent.Log() diff --git a/httpserver/serverOpt.go b/httpserver/serverOpt.go index 13a6b2e2..930fddee 100644 --- a/httpserver/serverOpt.go +++ b/httpserver/serverOpt.go @@ -103,7 +103,7 @@ func (o *optServer) initServer(s *http.Server) liberr.Error { } if e := http2.ConfigureServer(s, s2); e != nil { - return ErrorHTTP2Configure.ErrorParent(e) + return ErrorHTTP2Configure.Error(e) } return nil diff --git a/ioutils/fileDescriptor_ok.go b/ioutils/fileDescriptor_ok.go index 8977ca4c..a4f2265b 100644 --- a/ioutils/fileDescriptor_ok.go +++ b/ioutils/fileDescriptor_ok.go @@ -41,7 +41,7 @@ func systemFileDescriptor(newValue int) (current int, max int, err Error) { ) if e = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); e != nil { - err = ErrorSyscallRLimitGet.ErrorParent(e) + err = ErrorSyscallRLimitGet.Error(e) return } @@ -66,7 +66,7 @@ func systemFileDescriptor(newValue int) (current int, max int, err Error) { if chg { if e = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); e != nil { - err = ErrorSyscallRLimitSet.ErrorParent(e) + err = ErrorSyscallRLimitSet.Error(e) return } diff --git a/ioutils/tempFile.go b/ioutils/tempFile.go index 068875d5..18115e1f 100644 --- a/ioutils/tempFile.go +++ b/ioutils/tempFile.go @@ -34,7 +34,7 @@ import ( func NewTempFile() (*os.File, Error) { f, e := os.CreateTemp(os.TempDir(), "") - return f, ErrorIOFileTempNew.Iferror(e) + return f, ErrorIOFileTempNew.IfError(e) } func GetTempFilePath(f *os.File) string { @@ -53,10 +53,10 @@ func DelTempFile(f *os.File) Error { n := GetTempFilePath(f) a := f.Close() - e1 := ErrorIOFileTempClose.Iferror(a) + e1 := ErrorIOFileTempClose.IfError(a) b := os.Remove(n) - e2 := ErrorIOFileTempRemove.Iferror(b) + e2 := ErrorIOFileTempRemove.IfError(b) - return MakeErrorIfError(e2, e1) + return MakeIfError(e2, e1) } diff --git a/ldap/ldap.go b/ldap/ldap.go index b86da051..15831790 100644 --- a/ldap/ldap.go +++ b/ldap/ldap.go @@ -162,28 +162,28 @@ func (lc *HelperLDAP) dialTLS() (*ldap.Conn, liberr.Error) { _ = c.Close() } - return nil, ErrorLDAPServerTLS.ErrorParent(err) + return nil, ErrorLDAPServerTLS.Error(err) } c = tls.Client(c, lc.tlsConfig) if c == nil { - return nil, ErrorLDAPServerTLS.ErrorParent(ErrorLDAPServerConnection.Error(nil)) + return nil, ErrorLDAPServerTLS.Error(ErrorLDAPServerConnection.Error(nil)) } l := ldap.NewConn(c, true) if l == nil { - return nil, ErrorLDAPServerTLS.ErrorParent(ErrorLDAPServerConnection.Error(nil)) + return nil, ErrorLDAPServerTLS.Error(ErrorLDAPServerConnection.Error(nil)) } l.Start() if l.IsClosing() { - return nil, ErrorLDAPServerTLS.ErrorParent(ErrorLDAPServerDialClosing.Error(nil)) + return nil, ErrorLDAPServerTLS.Error(ErrorLDAPServerDialClosing.Error(nil)) } if _, tlsOk := l.TLSConnectionState(); !tlsOk { - return nil, ErrorLDAPServerTLS.ErrorParent(nil) + return nil, ErrorLDAPServerTLS.Error(nil) } return l, nil @@ -199,18 +199,18 @@ func (lc *HelperLDAP) dial() (*ldap.Conn, liberr.Error) { _ = c.Close() } - return nil, ErrorLDAPServerDial.ErrorParent(err) + return nil, ErrorLDAPServerDial.Error(err) } l := ldap.NewConn(c, false) if l == nil { - return nil, ErrorLDAPServerDial.ErrorParent(ErrorLDAPServerConnection.Error(nil)) + return nil, ErrorLDAPServerDial.Error(ErrorLDAPServerConnection.Error(nil)) } l.Start() if l.IsClosing() { - return nil, ErrorLDAPServerDial.ErrorParent(ErrorLDAPServerDialClosing.Error(nil)) + return nil, ErrorLDAPServerDial.Error(ErrorLDAPServerDialClosing.Error(nil)) } return l, nil @@ -220,11 +220,11 @@ func (lc *HelperLDAP) starttls(l *ldap.Conn) liberr.Error { err := l.StartTLS(lc.tlsConfig) if err != nil { - return ErrorLDAPServerStartTLS.ErrorParent(err) + return ErrorLDAPServerStartTLS.Error(err) } if _, tlsOk := l.TLSConnectionState(); !tlsOk { - return ErrorLDAPServerStartTLS.ErrorParent(nil) + return ErrorLDAPServerStartTLS.Error(nil) } return nil @@ -283,7 +283,7 @@ func (lc *HelperLDAP) connect() liberr.Error { } if err := lc.ctx.Err(); err != nil { - return ErrorLDAPContext.ErrorParent(err) + return ErrorLDAPContext.Error(err) } if lc.conn == nil { @@ -390,7 +390,7 @@ func (lc *HelperLDAP) AuthUser(username, password string) liberr.Error { err := lc.conn.Bind(username, password) - return ErrorLDAPBind.Iferror(err) + return ErrorLDAPBind.IfError(err) } // Connect used to connect and bind to server. @@ -430,7 +430,7 @@ func (lc *HelperLDAP) runSearch(filter string, attributes []string) (*ldap.Searc ) if src, err = lc.conn.Search(searchRequest); err != nil { - return nil, ErrorLDAPSearch.ErrorParent(err) + return nil, ErrorLDAPSearch.Error(err) } lc.getLogEntry(loglvl.DebugLevel, "ldap search success").FieldAdd("ldap.filter", filter).FieldAdd("ldap.attributes", attributes).Log() diff --git a/ldap/model.go b/ldap/model.go index b5ee1dab..d8e13bbb 100644 --- a/ldap/model.go +++ b/ldap/model.go @@ -119,12 +119,12 @@ func (cnf Config) Validate() errors.Error { if err := validator.New().Struct(cnf); err != nil { if er, ok := err.(*validator.InvalidValidationError); ok { - e.AddParent(er) + e.Add(er) } for _, er := range err.(validator.ValidationErrors) { //nolint #goerr113 - e.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) + e.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) } } diff --git a/logger/config/model.go b/logger/config/model.go index 9b214a88..2e7f72cf 100644 --- a/logger/config/model.go +++ b/logger/config/model.go @@ -75,12 +75,12 @@ func (o *Options) Validate() liberr.Error { if err := libval.New().Struct(o); err != nil { if er, ok := err.(*libval.InvalidValidationError); ok { - e.AddParent(er) + e.Add(er) } for _, er := range err.(libval.ValidationErrors) { //nolint #goerr113 - e.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) + e.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) } } diff --git a/logger/entry/errors.go b/logger/entry/errors.go index 2f95dd0f..4b95f161 100644 --- a/logger/entry/errors.go +++ b/logger/entry/errors.go @@ -27,9 +27,7 @@ package entry -import ( - liberr "github.com/nabbar/golib/errors" -) +import liberr "github.com/nabbar/golib/errors" func (e *entry) ErrorClean() Entry { e.Error = make([]error, 0) @@ -53,15 +51,11 @@ func (e *entry) ErrorAdd(cleanNil bool, err ...error) Entry { if cleanNil && er == nil { continue } - e.Error = append(e.Error, er) - } - - return e -} - -func (e *entry) ErrorAddLib(cleanNil bool, err ...liberr.Error) Entry { - for _, er := range err { - e.ErrorAdd(cleanNil, er.GetErrorSlice()...) + if liberr.Is(er) { + e.Error = append(e.Error, liberr.Get(er).GetErrorSlice()...) + } else { + e.Error = append(e.Error, er) + } } return e diff --git a/logger/entry/interface.go b/logger/entry/interface.go index d67314d6..b293530c 100644 --- a/logger/entry/interface.go +++ b/logger/entry/interface.go @@ -31,7 +31,6 @@ import ( "time" ginsdk "github.com/gin-gonic/gin" - liberr "github.com/nabbar/golib/errors" logfld "github.com/nabbar/golib/logger/fields" loglvl "github.com/nabbar/golib/logger/level" "github.com/sirupsen/logrus" @@ -56,7 +55,6 @@ type Entry interface { ErrorClean() Entry ErrorSet(err []error) Entry ErrorAdd(cleanNil bool, err ...error) Entry - ErrorAddLib(cleanNil bool, err ...liberr.Error) Entry } func New(lvl loglvl.Level) Entry { diff --git a/mail/config.go b/mail/config.go index 09f85fbe..558884c2 100644 --- a/mail/config.go +++ b/mail/config.go @@ -96,12 +96,12 @@ func (c Config) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } @@ -170,7 +170,7 @@ func (c Config) NewMailer() (Mail, liberr.Error) { if len(c.Attach) > 0 { for _, f := range c.Attach { if h, e := libfpg.Open(f.Path); e != nil { - return nil, ErrorFileOpenCreate.ErrorParent(e) + return nil, ErrorFileOpenCreate.Error(e) } else { m.AddAttachment(f.Name, f.Mime, h, false) } @@ -180,7 +180,7 @@ func (c Config) NewMailer() (Mail, liberr.Error) { if len(c.Inline) > 0 { for _, f := range c.Inline { if h, e := libfpg.Open(f.Path); e != nil { - return nil, ErrorFileOpenCreate.ErrorParent(e) + return nil, ErrorFileOpenCreate.Error(e) } else { m.AddAttachment(f.Name, f.Mime, h, true) } diff --git a/mail/interface.go b/mail/interface.go index dfb0984a..89321cc3 100644 --- a/mail/interface.go +++ b/mail/interface.go @@ -29,8 +29,6 @@ import ( "io" "net/textproto" "time" - - liberr "github.com/nabbar/golib/errors" ) type Mail interface { @@ -50,7 +48,7 @@ type Mail interface { SetDateTime(datetime time.Time) GetDateTime() time.Time - SetDateString(layout, datetime string) liberr.Error + SetDateString(layout, datetime string) error GetDateString() string AddHeader(key string, values ...string) @@ -68,7 +66,7 @@ type Mail interface { Email() Email - Sender() (Sender, liberr.Error) + Sender() (Sender, error) } func New() Mail { diff --git a/mail/mail.go b/mail/mail.go index 2e68fc00..59e4389a 100644 --- a/mail/mail.go +++ b/mail/mail.go @@ -31,8 +31,6 @@ import ( "net/textproto" "path/filepath" "time" - - liberr "github.com/nabbar/golib/errors" ) const ( @@ -101,9 +99,9 @@ func (m *mail) GetDateTime() time.Time { return m.date } -func (m *mail) SetDateString(layout, datetime string) liberr.Error { +func (m *mail) SetDateString(layout, datetime string) error { if t, e := time.Parse(layout, datetime); e != nil { - return ErrorMailDateParsing.ErrorParent(e) + return ErrorMailDateParsing.Error(e) } else { m.date = t } diff --git a/mail/sender.go b/mail/sender.go index d8290809..379aefc3 100644 --- a/mail/sender.go +++ b/mail/sender.go @@ -31,7 +31,6 @@ import ( "fmt" "io" - liberr "github.com/nabbar/golib/errors" libfpg "github.com/nabbar/golib/file/progress" libsmtp "github.com/nabbar/golib/smtp" simple "github.com/xhit/go-simple-mail" @@ -43,8 +42,8 @@ const ( type Sender interface { Close() error - Send(ctx context.Context, cli libsmtp.SMTP) liberr.Error - SendClose(ctx context.Context, cli libsmtp.SMTP) liberr.Error + Send(ctx context.Context, cli libsmtp.SMTP) error + SendClose(ctx context.Context, cli libsmtp.SMTP) error } type sender struct { @@ -54,7 +53,7 @@ type sender struct { } // nolint #gocognit -func (m *mail) Sender() (snd Sender, err liberr.Error) { +func (m *mail) Sender() (snd Sender, err error) { e := simple.NewMSG() f := make([]libfpg.Progress, 0) @@ -66,7 +65,7 @@ func (m *mail) Sender() (snd Sender, err liberr.Error) { } if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } switch m.GetEncoding() { @@ -79,78 +78,78 @@ func (m *mail) Sender() (snd Sender, err liberr.Error) { } if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } e.Charset = m.GetCharset() e.SetSubject(m.GetSubject()) if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } e.SetDate(m.date.Format("2006-01-02 15:04:05 MST")) if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } if r := m.Email().GetFrom(); len(r) > 0 { e.SetFrom(r) } if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } if r := m.Email().GetReplyTo(); len(r) > 0 { e.SetReplyTo(r) } if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } if r := m.Email().GetReturnPath(); len(r) > 0 { e.SetReturnPath(r) } if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } if r := m.Email().GetSender(); len(r) > 0 { e.SetSender(r) } if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } if r := m.address.GetRecipients(RecipientTo); len(r) > 0 { e.AddTo(r...) if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } } if r := m.address.GetRecipients(RecipientCC); len(r) > 0 { e.AddCc(r...) if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } } if r := m.address.GetRecipients(RecipientBCC); len(r) > 0 { e.AddBcc(r...) if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } } if len(m.attach) > 0 { for _, i := range m.attach { if t, er := libfpg.Temp(""); er != nil { - return nil, ErrorFileOpenCreate.ErrorParent(er) + return nil, ErrorFileOpenCreate.Error(er) } else if _, er := t.ReadFrom(i.data); er != nil { - return nil, ErrorMailIORead.ErrorParent(er) + return nil, ErrorMailIORead.Error(er) } else if e.AddAttachment(t.Path(), i.name); e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } else { f = append(f, t) } @@ -160,11 +159,11 @@ func (m *mail) Sender() (snd Sender, err liberr.Error) { if len(m.inline) > 0 { for _, i := range m.inline { if t, er := libfpg.Temp(""); er != nil { - return nil, ErrorFileOpenCreate.ErrorParent(er) + return nil, ErrorFileOpenCreate.Error(er) } else if _, er := t.ReadFrom(i.data); er != nil { - return nil, ErrorMailIORead.ErrorParent(er) + return nil, ErrorMailIORead.Error(er) } else if e.AddInline(t.Path(), i.name); e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } else { f = append(f, t) } @@ -183,14 +182,14 @@ func (m *mail) Sender() (snd Sender, err liberr.Error) { } if _, er := buf.ReadFrom(b.body); er != nil { - return nil, ErrorMailIORead.ErrorParent(er) + return nil, ErrorMailIORead.Error(er) } else if i > 0 { e.AddAlternative(enc, buf.String()) } else { e.SetBody(enc, buf.String()) } if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } } } @@ -210,13 +209,13 @@ func (m *mail) Sender() (snd Sender, err liberr.Error) { s.rcpt = append(s.rcpt, m.Email().GetRecipients(RecipientBCC)...) if tmp, er := libfpg.Temp(""); er != nil { - return nil, ErrorFileOpenCreate.ErrorParent(er) + return nil, ErrorFileOpenCreate.Error(er) } else if _, er = tmp.WriteString(e.GetMessage()); er != nil { - return nil, ErrorMailIOWrite.ErrorParent(er) + return nil, ErrorMailIOWrite.Error(er) } else if e.Error != nil { - return nil, ErrorMailSenderInit.ErrorParent(e.Error) + return nil, ErrorMailSenderInit.Error(e.Error) } else if _, er = tmp.Seek(0, io.SeekStart); er != nil { - return nil, ErrorMailIOWrite.ErrorParent(er) + return nil, ErrorMailIOWrite.Error(er) } else { s.data = tmp snd = s @@ -225,7 +224,7 @@ func (m *mail) Sender() (snd Sender, err liberr.Error) { return } -func (s *sender) SendClose(ctx context.Context, cli libsmtp.SMTP) liberr.Error { +func (s *sender) SendClose(ctx context.Context, cli libsmtp.SMTP) error { defer func() { _ = s.Close() }() @@ -237,17 +236,17 @@ func (s *sender) SendClose(ctx context.Context, cli libsmtp.SMTP) liberr.Error { return nil } -func (s *sender) Send(ctx context.Context, cli libsmtp.SMTP) liberr.Error { +func (s *sender) Send(ctx context.Context, cli libsmtp.SMTP) error { if e := cli.Check(ctx); e != nil { - return ErrorMailSmtpClient.ErrorParent(e) + return ErrorMailSmtpClient.Error(e) } if len(s.from) < _MinSizeAddr { //nolint #goerr113 - return ErrorParamEmpty.ErrorParent(fmt.Errorf("parameters 'from' is not valid")) + return ErrorParamEmpty.Error(fmt.Errorf("parameters 'from' is not valid")) } else if len(s.rcpt) < 1 || len(s.rcpt[0]) < _MinSizeAddr { //nolint #goerr113 - return ErrorParamEmpty.ErrorParent(fmt.Errorf("parameters 'receipient' is not valid")) + return ErrorParamEmpty.Error(fmt.Errorf("parameters 'receipient' is not valid")) } e := cli.Send(ctx, s.from, s.rcpt, s.data) @@ -256,7 +255,7 @@ func (s *sender) Send(ctx context.Context, cli libsmtp.SMTP) liberr.Error { } if _, err := s.data.Seek(0, io.SeekStart); err != nil { - return ErrorMailIOWrite.ErrorParent(err) + return ErrorMailIOWrite.Error(err) } return nil diff --git a/mailPooler/config.go b/mailPooler/config.go index 0e94f951..1996c8a6 100644 --- a/mailPooler/config.go +++ b/mailPooler/config.go @@ -27,11 +27,9 @@ package mailPooler import ( "time" - - liberr "github.com/nabbar/golib/errors" ) -type FuncCaller func() liberr.Error +type FuncCaller func() error type Config struct { Max int `json:"max" yaml:"max" toml:"max" mapstructure:"max"` diff --git a/mailPooler/counter.go b/mailPooler/counter.go index 7f7dbd24..d58528bb 100644 --- a/mailPooler/counter.go +++ b/mailPooler/counter.go @@ -29,13 +29,11 @@ import ( "context" "sync" "time" - - liberr "github.com/nabbar/golib/errors" ) type Counter interface { - Pool(ctx context.Context) liberr.Error - Reset() liberr.Error + Pool(ctx context.Context) error + Reset() error Clone() Counter } @@ -61,7 +59,7 @@ func newCounter(max int, dur time.Duration, fct FuncCaller) Counter { } } -func (c *counter) Pool(ctx context.Context) liberr.Error { +func (c *counter) Pool(ctx context.Context) error { c.m.Lock() defer c.m.Unlock() @@ -70,7 +68,7 @@ func (c *counter) Pool(ctx context.Context) liberr.Error { } if e := ctx.Err(); e != nil { - return ErrorMailPoolerContext.ErrorParent(e) + return ErrorMailPoolerContext.Error(e) } if c.tim.IsZero() { @@ -90,7 +88,7 @@ func (c *counter) Pool(ctx context.Context) liberr.Error { c.tim = time.Now() if e := ctx.Err(); e != nil { - return ErrorMailPoolerContext.ErrorParent(e) + return ErrorMailPoolerContext.Error(e) } else if err := c.fct(); err != nil { return err } @@ -99,7 +97,7 @@ func (c *counter) Pool(ctx context.Context) liberr.Error { return nil } -func (c *counter) Reset() liberr.Error { +func (c *counter) Reset() error { c.m.Lock() defer c.m.Unlock() diff --git a/mailPooler/interface.go b/mailPooler/interface.go index ee386147..8d9ba12a 100644 --- a/mailPooler/interface.go +++ b/mailPooler/interface.go @@ -26,12 +26,11 @@ package mailPooler import ( - liberr "github.com/nabbar/golib/errors" libsmtp "github.com/nabbar/golib/smtp" ) type Pooler interface { - Reset() liberr.Error + Reset() error NewPooler() Pooler libsmtp.SMTP diff --git a/mailPooler/model.go b/mailPooler/model.go index 1f1b0f7f..2bbb3eff 100644 --- a/mailPooler/model.go +++ b/mailPooler/model.go @@ -32,7 +32,6 @@ import ( "io" "net/smtp" - liberr "github.com/nabbar/golib/errors" libsmtp "github.com/nabbar/golib/smtp" smtpcf "github.com/nabbar/golib/smtp/config" ) @@ -42,9 +41,9 @@ type pooler struct { c Counter } -func (p *pooler) Reset() liberr.Error { +func (p *pooler) Reset() error { if p.s == nil { - return ErrorParamEmpty.ErrorParent(errors.New("smtp client is not define")) + return ErrorParamEmpty.Error(errors.New("smtp client is not define")) } if err := p.c.Reset(); err != nil { @@ -68,9 +67,9 @@ func (p *pooler) NewPooler() Pooler { } } -func (p *pooler) Send(ctx context.Context, from string, to []string, data io.WriterTo) liberr.Error { +func (p *pooler) Send(ctx context.Context, from string, to []string, data io.WriterTo) error { if p.s == nil { - return ErrorParamEmpty.ErrorParent(errors.New("smtp client is not define")) + return ErrorParamEmpty.Error(errors.New("smtp client is not define")) } if err := p.c.Pool(ctx); err != nil { @@ -80,9 +79,9 @@ func (p *pooler) Send(ctx context.Context, from string, to []string, data io.Wri return p.s.Send(ctx, from, to, data) } -func (p *pooler) Client(ctx context.Context) (*smtp.Client, liberr.Error) { +func (p *pooler) Client(ctx context.Context) (*smtp.Client, error) { if p.s == nil { - return nil, ErrorParamEmpty.ErrorParent(errors.New("smtp client is not define")) + return nil, ErrorParamEmpty.Error(errors.New("smtp client is not define")) } return p.s.Client(ctx) @@ -94,9 +93,9 @@ func (p *pooler) Close() { } } -func (p *pooler) Check(ctx context.Context) liberr.Error { +func (p *pooler) Check(ctx context.Context) error { if p.s == nil { - return ErrorParamEmpty.ErrorParent(errors.New("smtp client is not define")) + return ErrorParamEmpty.Error(errors.New("smtp client is not define")) } return p.s.Check(ctx) diff --git a/mailer/config.go b/mailer/config.go index 27674cf0..565fe3e5 100644 --- a/mailer/config.go +++ b/mailer/config.go @@ -51,12 +51,12 @@ func (c Config) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } diff --git a/mailer/render.go b/mailer/render.go index 8fd2d4f5..82382ed0 100644 --- a/mailer/render.go +++ b/mailer/render.go @@ -100,7 +100,7 @@ func (e email) generated(f func(h hermes.Hermes, m hermes.Email) (string, error) if p, e := f(h, hermes.Email{ Body: *e.b, }); e != nil { - return nil, ErrorMailerText.ErrorParent(e) + return nil, ErrorMailerText.Error(e) } else { buf.WriteString(p) } diff --git a/monitor/internalConfig.go b/monitor/internalConfig.go index 86dbee7f..d2865d91 100644 --- a/monitor/internalConfig.go +++ b/monitor/internalConfig.go @@ -169,7 +169,7 @@ func (o *mon) SetConfig(ctx libctx.FuncContext, cfg montps.Config) liberr.Error } if e := n.SetOptions(&cfg.Logger); e != nil { - return ErrorLoggerError.ErrorParent(e) + return ErrorLoggerError.Error(e) } f := n.GetFields() diff --git a/monitor/model.go b/monitor/model.go index edb01244..12c652e0 100644 --- a/monitor/model.go +++ b/monitor/model.go @@ -85,7 +85,7 @@ func (o *mon) Clone(ctx context.Context) (montps.Monitor, liberr.Error) { if err, ok := e.(liberr.Error); ok { return nil, err } else { - return nil, ErrorTimeout.ErrorParent(e) + return nil, ErrorTimeout.Error(e) } } } diff --git a/monitor/types/config.go b/monitor/types/config.go index 0efeb1e3..e277082a 100644 --- a/monitor/types/config.go +++ b/monitor/types/config.go @@ -101,12 +101,12 @@ func (o Config) Validate() liberr.Error { if err := libval.New().Struct(o); err != nil { if er, ok := err.(*libval.InvalidValidationError); ok { - e.AddParent(er) + e.Add(er) } for _, er := range err.(libval.ValidationErrors) { //nolint #goerr113 - e.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) + e.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) } } diff --git a/nats/client.go b/nats/client.go index 8d519b50..bb4845c1 100644 --- a/nats/client.go +++ b/nats/client.go @@ -152,12 +152,12 @@ func (c Client) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } @@ -282,7 +282,7 @@ func (c Client) NewClient(defTls libtls.TLSConfig) (*natcli.Conn, liberr.Error) } if n, e := opts.Connect(); e != nil { - return nil, ErrorClientConnect.ErrorParent(e) + return nil, ErrorClientConnect.Error(e) } else { return n, nil } diff --git a/nats/config.go b/nats/config.go index e3d15d78..a77caafe 100644 --- a/nats/config.go +++ b/nats/config.go @@ -68,12 +68,12 @@ func (c Config) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } @@ -101,12 +101,12 @@ func (c Config) LogConfigJson() liberr.Error { } if e := libiot.PathCheckCreate(true, c.Logs.LogFile, permFile, permDirs); e != nil { - return ErrorConfigInvalidFilePath.ErrorParent(e) + return ErrorConfigInvalidFilePath.Error(e) } f, e := os.OpenFile(c.Logs.LogFile, os.O_APPEND|os.O_WRONLY, permFile) if e != nil { - return ErrorConfigInvalidFilePath.ErrorParent(e) + return ErrorConfigInvalidFilePath.Error(e) } defer func() { @@ -116,13 +116,13 @@ func (c Config) LogConfigJson() liberr.Error { }() if p, e := json.MarshalIndent(c, "", " "); e != nil { - return ErrorConfigJsonMarshall.ErrorParent(e) + return ErrorConfigJsonMarshall.Error(e) } else if _, e := f.WriteString("----\nConfig Node: "); e != nil { - return ErrorConfigWriteInFile.ErrorParent(e) + return ErrorConfigWriteInFile.Error(e) } else if _, e := f.Write(p); e != nil { - return ErrorConfigWriteInFile.ErrorParent(e) + return ErrorConfigWriteInFile.Error(e) } else if _, e := f.WriteString("\n---- \n"); e != nil { - return ErrorConfigWriteInFile.ErrorParent(e) + return ErrorConfigWriteInFile.Error(e) } return nil @@ -250,7 +250,7 @@ func (c ConfigAuth) makeOpt(cfg *natsrv.Options) liberr.Error { for _, t := range c.TrustedOperators { if j, e := natsrv.ReadOperatorJWT(t); e != nil { - return ErrorConfigInvalidJWTOperator.ErrorParent(e) + return ErrorConfigInvalidJWTOperator.Error(e) } else if j != nil { cfg.TrustedOperators = append(cfg.TrustedOperators, j) } @@ -320,12 +320,12 @@ func (c ConfigNkey) makeOpt(auth ConfigAuth, cfg *natsrv.Options) (*natsrv.NkeyU case natjwt.ConnectionTypeMqtt: t[natjwt.ConnectionTypeMqtt] = struct{}{} default: - return nil, ErrorConfigInvalidAllowedConnectionType.ErrorParent(fmt.Errorf("connection type: %s", at)) + return nil, ErrorConfigInvalidAllowedConnectionType.Error(fmt.Errorf("connection type: %s", at)) } } if a = auth.findConfigAccount(c.Account); a == nil { - return nil, ErrorConfigInvalidAccount.ErrorParent(fmt.Errorf("account: %s", c.Account)) + return nil, ErrorConfigInvalidAccount.Error(fmt.Errorf("account: %s", c.Account)) } return &natsrv.NkeyUser{ @@ -377,12 +377,12 @@ func (c ConfigUser) makeOpt(auth ConfigAuth, cfg *natsrv.Options) (*natsrv.User, case natjwt.ConnectionTypeMqtt: t[natjwt.ConnectionTypeMqtt] = struct{}{} default: - return nil, ErrorConfigInvalidAllowedConnectionType.ErrorParent(fmt.Errorf("connection type: %s", at)) + return nil, ErrorConfigInvalidAllowedConnectionType.Error(fmt.Errorf("connection type: %s", at)) } } if a = auth.findConfigAccount(c.Account); a == nil { - return nil, ErrorConfigInvalidAccount.ErrorParent(fmt.Errorf("account: %s", c.Account)) + return nil, ErrorConfigInvalidAccount.Error(fmt.Errorf("account: %s", c.Account)) } return &natsrv.User{ @@ -500,7 +500,7 @@ func (c ConfigLogger) makeOpt(log liblog.Logger, cfg *natsrv.Options) liberr.Err if c.LogFile != "" { if e := libiot.PathCheckCreate(true, c.LogFile, permFile, permDir); e != nil { - return ErrorConfigInvalidFilePath.ErrorParent(e) + return ErrorConfigInvalidFilePath.Error(e) } cfg.LogFile = c.LogFile } @@ -707,7 +707,7 @@ func (c ConfigSrv) makeOpt(cfg *natsrv.Options, defTls libtls.TLSConfig) liberr. if c.StoreDir != "" { if e := libiot.PathCheckCreate(false, c.StoreDir, 0644, perm); e != nil { - return ErrorConfigInvalidFilePath.ErrorParent(e) + return ErrorConfigInvalidFilePath.Error(e) } cfg.StoreDir = c.StoreDir diff --git a/nats/server.go b/nats/server.go index 0988ec7c..8d2fa587 100644 --- a/nats/server.go +++ b/nats/server.go @@ -104,7 +104,7 @@ func (s *server) Listen(ctx context.Context) liberr.Error { ) if o, e = natsrv.NewServer(s.GetOptions()); e != nil { - err := ErrorServerStart.ErrorParent(e) + err := ErrorServerStart.Error(e) s._SetError(err) return err } diff --git a/network/network.go b/network/network.go index c1ee1d75..ae6cdfa0 100644 --- a/network/network.go +++ b/network/network.go @@ -60,7 +60,7 @@ func GetAllInterfaces(ctx context.Context, onlyPhysical, hasAddr bool, atLeastMT var res = make([]string, 0) if l, e := netlib.InterfacesWithContext(ctx); e != nil { - return nil, ErrorNetInterface.ErrorParent(e) + return nil, ErrorNetInterface.Error(e) } else { for _, f := range l { if onlyPhysical && f.HardwareAddr == "" { @@ -103,7 +103,7 @@ func NewInterface(ctx context.Context, name, physical string) (Interface, errors ) if l, e := netlib.InterfacesWithContext(ctx); e != nil { - return nil, ErrorNetInterface.ErrorParent(e) + return nil, ErrorNetInterface.Error(e) } else { for _, f := range l { if (name != "" && f.Name == name) || (physical != "" && physical == f.HardwareAddr) { @@ -118,7 +118,7 @@ func NewInterface(ctx context.Context, name, physical string) (Interface, errors } if l, e := netlib.IOCountersWithContext(ctx, true); e != nil { - return nil, ErrorNetCounter.ErrorParent(e) + return nil, ErrorNetCounter.Error(e) } else { for _, f := range l { if f.Name == ifs.Name { diff --git a/nutsdb/client.go b/nutsdb/client.go index 676b34cc..00b558cc 100644 --- a/nutsdb/client.go +++ b/nutsdb/client.go @@ -96,93 +96,93 @@ func (c *clientNutDB) strToType(dest reflect.Type, val string) (interface{}, lib switch dest.Kind() { case reflect.Bool: if v, e := strconv.ParseBool(val); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return v, nil } case reflect.Int: if v, e := strconv.ParseInt(val, 10, 64); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return int(v), nil } case reflect.Int8: if v, e := strconv.ParseInt(val, 10, 8); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return int8(v), nil } case reflect.Int16: if v, e := strconv.ParseInt(val, 10, 16); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return int16(v), nil } case reflect.Int32: if v, e := strconv.ParseInt(val, 10, 32); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return int32(v), nil } case reflect.Int64: if v, e := strconv.ParseInt(val, 10, 64); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return v, nil } case reflect.Uint: if v, e := strconv.ParseUint(val, 10, 64); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return uint(v), nil } case reflect.Uint8: if v, e := strconv.ParseUint(val, 10, 8); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return uint8(v), nil } case reflect.Uint16: if v, e := strconv.ParseUint(val, 10, 16); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return uint16(v), nil } case reflect.Uint32: if v, e := strconv.ParseUint(val, 10, 32); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return uint32(v), nil } case reflect.Uint64: if v, e := strconv.ParseUint(val, 10, 64); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return v, nil } case reflect.Uintptr: - return nil, ErrorParamInvalid.ErrorParent(fmt.Errorf("cannot convert int UintPtr")) + return nil, ErrorParamInvalid.Error(fmt.Errorf("cannot convert int UintPtr")) case reflect.Float32: if v, e := strconv.ParseFloat(val, 32); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return float32(v), nil } case reflect.Float64: if v, e := strconv.ParseFloat(val, 64); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return v, nil } case reflect.Complex64: if v, e := strconv.ParseComplex(val, 64); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return complex64(v), nil } case reflect.Complex128: if v, e := strconv.ParseComplex(val, 128); e != nil { - return nil, ErrorParamMismatching.ErrorParent(e) + return nil, ErrorParamMismatching.Error(e) } else { return v, nil } diff --git a/nutsdb/config.go b/nutsdb/config.go index 101fe790..258ca320 100644 --- a/nutsdb/config.go +++ b/nutsdb/config.go @@ -87,12 +87,12 @@ func (c Config) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } diff --git a/nutsdb/configDb.go b/nutsdb/configDb.go index 43ede908..80c6c655 100644 --- a/nutsdb/configDb.go +++ b/nutsdb/configDb.go @@ -102,12 +102,12 @@ func (o NutsDBOptions) Validate() liberr.Error { if er := libval.New().Struct(o); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } diff --git a/nutsdb/configFs.go b/nutsdb/configFs.go index 846cf428..18916d3b 100644 --- a/nutsdb/configFs.go +++ b/nutsdb/configFs.go @@ -85,12 +85,12 @@ func (f NutsDBFolder) Validate() liberr.Error { if er := libval.New().Struct(f); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } @@ -120,7 +120,7 @@ func (f NutsDBFolder) getDirectory(base, dir string) (string, liberr.Error) { } if abs, err = filepath.Abs(dir); err != nil { - return "", ErrorFolderCheck.ErrorParent(err) + return "", ErrorFolderCheck.Error(err) } if f.Permission == 0 { @@ -128,10 +128,10 @@ func (f NutsDBFolder) getDirectory(base, dir string) (string, liberr.Error) { } if _, err = os.Stat(abs); err != nil && !errors.Is(err, os.ErrNotExist) { - return "", ErrorFolderCheck.ErrorParent(err) + return "", ErrorFolderCheck.Error(err) } else if err != nil { if err = os.MkdirAll(abs, f.Permission); err != nil { - return "", ErrorFolderCreate.ErrorParent(err) + return "", ErrorFolderCreate.Error(err) } } diff --git a/nutsdb/entryKv.go b/nutsdb/entryKv.go index 78655a72..e5a81e0b 100644 --- a/nutsdb/entryKv.go +++ b/nutsdb/entryKv.go @@ -70,7 +70,7 @@ func NewCommandByDecode(l liblog.FuncLog, p []byte) (*CommandRequest, liberr.Err d := NewCommand() if e := cbor.Unmarshal(p, d); e != nil { - return nil, ErrorCommandUnmarshal.ErrorParent(e) + return nil, ErrorCommandUnmarshal.Error(e) } d.SetLogger(l) @@ -149,7 +149,7 @@ func (c *CommandRequest) SetParamsInc(num int, val interface{}) int { func (c *CommandRequest) EncodeRequest() ([]byte, liberr.Error) { if p, e := cbor.Marshal(c); e != nil { - return nil, ErrorCommandMarshal.ErrorParent(e) + return nil, ErrorCommandMarshal.Error(e) } else { return p, nil } @@ -159,7 +159,7 @@ func (c *CommandRequest) DecodeResult(p []byte) (*CommandResponse, liberr.Error) res := CommandResponse{} if e := cbor.Unmarshal(p, &res); e != nil { - return nil, ErrorCommandResultUnmarshal.ErrorParent(e) + return nil, ErrorCommandResultUnmarshal.Error(e) } else { return &res, nil } @@ -181,7 +181,7 @@ func (c *CommandRequest) RunLocal(tx *nutsdb.Tx) (*CommandResponse, liberr.Error if len(c.Params) != nbPrm { //nolint #goerr113 - return nil, ErrorClientCommandParamsBadNumber.ErrorParent(fmt.Errorf("%s need %d parameters", c.Cmd.Name(), nbPrm)) + return nil, ErrorClientCommandParamsBadNumber.Error(fmt.Errorf("%s need %d parameters", c.Cmd.Name(), nbPrm)) } params := make([]reflect.Value, nbPrm) @@ -196,7 +196,7 @@ func (c *CommandRequest) RunLocal(tx *nutsdb.Tx) (*CommandResponse, liberr.Error if !v.Type().ConvertibleTo(method.Type().In(i)) { //nolint #goerr113 - return nil, ErrorClientCommandParamsMismatching.ErrorParent(fmt.Errorf("cmd: %s", mtName), fmt.Errorf("param num: %d", i), fmt.Errorf("param type: %s, avaitting type: %s", v.Type().Kind(), method.Type().In(i).Kind())) + return nil, ErrorClientCommandParamsMismatching.Error(fmt.Errorf("cmd: %s", mtName), fmt.Errorf("param num: %d", i), fmt.Errorf("param type: %s, avaitting type: %s", v.Type().Kind(), method.Type().In(i).Kind())) } //nolint #exhaustive @@ -272,7 +272,7 @@ func (c *CommandRequest) Run(tx *nutsdb.Tx) ([]byte, liberr.Error) { if r, err := c.RunLocal(tx); err != nil { return nil, err } else if p, e := cbor.Marshal(r); e != nil { - return nil, ErrorCommandResultMarshal.ErrorParent(e) + return nil, ErrorCommandResultMarshal.Error(e) } else { return p, nil } diff --git a/nutsdb/node.go b/nutsdb/node.go index ad580f72..150453ce 100644 --- a/nutsdb/node.go +++ b/nutsdb/node.go @@ -116,7 +116,7 @@ func (n *nutsNode) newTx(writable bool) (*nutsdb.Tx, liberr.Error) { if db := n.getDb(); db == nil { return nil, ErrorDatabaseClosed.Error(nil) } else if tx, e := db.Begin(writable); e != nil { - return nil, ErrorTransactionInit.ErrorParent(e) + return nil, ErrorTransactionInit.Error(e) } else { return tx, nil } @@ -189,9 +189,9 @@ func (n *nutsNode) applyRaftLogIndexLastApplied(idx uint64) error { }() if e = tx.Put(_RaftBucket, []byte(_RaftKeyAppliedIndex), n.i64tob(idx), 0); e != nil { - return ErrorTransactionPutKey.ErrorParent(e) + return ErrorTransactionPutKey.Error(e) } else if e = tx.Commit(); e != nil { - return ErrorTransactionCommit.ErrorParent(e) + return ErrorTransactionCommit.Error(e) } else { return nil } @@ -280,7 +280,7 @@ func (n *nutsNode) Update(logEntry []dgbstm.Entry) ([]dgbstm.Entry, error) { if e = tx.Commit(); e != nil { _ = tx.Rollback() - return logEntry, ErrorTransactionCommit.ErrorParent(e) + return logEntry, ErrorTransactionCommit.Error(e) } return logEntry, n.applyRaftLogIndexLastApplied(logEntry[len(logEntry)-1].Index) @@ -329,7 +329,7 @@ func (n *nutsNode) PrepareSnapshot() (interface{}, error) { return nil, ErrorDatabaseClosed.Error(nil) } else if err := sh.Prepare(opt, db); err != nil { sh.Finish() - return nil, ErrorDatabaseBackup.ErrorParent(err) + return nil, ErrorDatabaseBackup.Error(err) } else { return sh, nil } diff --git a/nutsdb/options.go b/nutsdb/options.go index 7741de43..a3634945 100644 --- a/nutsdb/options.go +++ b/nutsdb/options.go @@ -113,7 +113,7 @@ func (o options) NewBackup(db *nutsdb.DB) (string, liberr.Error) { fld := o.getBackupDirName() if e := os.MkdirAll(filepath.Join(o.dirs.backup, fld), o.perm); e != nil { - return "", ErrorFolderCreate.ErrorParent(e) + return "", ErrorFolderCreate.Error(e) } else if err := o.newBackupDir(fld, db); err != nil { return "", err } else { @@ -133,7 +133,7 @@ func (o options) NewBackupTemp(db *nutsdb.DB) (string, liberr.Error) { func (o options) NewTempFolder() (string, liberr.Error) { if p, e := os.MkdirTemp(o.dirs.temp, o.getTempPrefix()); e != nil { - return "", ErrorFolderCreate.ErrorParent(e) + return "", ErrorFolderCreate.Error(e) } else { _ = os.Chmod(p, o.perm) return p, nil @@ -164,9 +164,9 @@ func (o options) Permission() os.FileMode { func (o options) RestoreBackup(dir string) liberr.Error { if err := os.RemoveAll(o.dirs.data); err != nil { - return ErrorFolderDelete.ErrorParent(err) + return ErrorFolderDelete.Error(err) } else if err = xujufs.CopyDir(dir, o.dirs.data); err != nil { - return ErrorFolderCopy.ErrorParent(err) + return ErrorFolderCopy.Error(err) } else { _ = os.Chmod(o.dirs.data, o.perm) } @@ -178,7 +178,7 @@ func (o options) RestoreBackup(dir string) liberr.Error { func (o options) newBackupDir(dir string, db *nutsdb.DB) liberr.Error { if err := db.Backup(dir); err != nil { - return ErrorDatabaseBackup.ErrorParent(err) + return ErrorDatabaseBackup.Error(err) } return nil diff --git a/nutsdb/snap.go b/nutsdb/snap.go index b96df5a1..f0262cf8 100644 --- a/nutsdb/snap.go +++ b/nutsdb/snap.go @@ -98,7 +98,7 @@ func (s *snap) Save(opt Options, writer io.Writer) liberr.Error { }() if tmp, e = libfpg.Unique(opt.GetTempDir(), opt.NewTempFilePattern("tar")); e != nil { - return ErrorFileTemp.ErrorParent(e) + return ErrorFileTemp.Error(e) } if _, err = archive.CreateArchive(archive.TypeTarGzip, tmp, s.path, s.path); err != nil { @@ -106,11 +106,11 @@ func (s *snap) Save(opt Options, writer io.Writer) liberr.Error { } if _, e = tmp.Seek(0, io.SeekStart); e != nil { - return ErrorDatabaseSnapshot.ErrorParent(e) + return ErrorDatabaseSnapshot.Error(e) } if _, e = tmp.WriteTo(writer); e != nil { - return ErrorDatabaseSnapshot.ErrorParent(e) + return ErrorDatabaseSnapshot.Error(e) } return nil @@ -133,11 +133,11 @@ func (s *snap) Load(opt Options, reader io.Reader) liberr.Error { }() if tmp, e = libfpg.Unique(opt.GetTempDir(), opt.NewTempFilePattern("tar.gz")); e != nil { - return ErrorFileTemp.ErrorParent(e) + return ErrorFileTemp.Error(e) } if _, e = tmp.ReadFrom(reader); e != nil { - return ErrorDatabaseSnapshot.ErrorParent(e) + return ErrorDatabaseSnapshot.Error(e) } if o, err = opt.NewTempFolder(); err != nil { diff --git a/oauth/client.go b/oauth/client.go index 23c1724b..9179e931 100644 --- a/oauth/client.go +++ b/oauth/client.go @@ -70,7 +70,7 @@ func ConfigExchangeCode(oa *oauth2.Config, ctx context.Context, httpcli *http.Cl } if tok, err := oa.Exchange(ctx, code); err != nil { - return nil, ErrorOAuthExchange.ErrorParent(err) + return nil, ErrorOAuthExchange.Error(err) } else { return oa.Client(ctx, tok), nil } diff --git a/request/interface.go b/request/interface.go index a7f3972b..2ec4a06f 100644 --- a/request/interface.go +++ b/request/interface.go @@ -40,7 +40,6 @@ import ( libtls "github.com/nabbar/golib/certificates" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" libver "github.com/nabbar/golib/version" ) @@ -113,9 +112,9 @@ type Request interface { Error() Error IsError() bool - Do() (*http.Response, liberr.Error) - DoParse(model interface{}, validStatus ...int) liberr.Error - DoParseRetry(retry int, model interface{}, validStatus ...int) liberr.Error + Do() (*http.Response, error) + DoParse(model interface{}, validStatus ...int) error + DoParseRetry(retry int, model interface{}, validStatus ...int) error Monitor(ctx context.Context, vrs libver.Version) (montps.Monitor, error) HealthCheck(ctx context.Context) error diff --git a/request/monitor.go b/request/monitor.go index a2750e60..bf246536 100644 --- a/request/monitor.go +++ b/request/monitor.go @@ -39,7 +39,6 @@ import ( loglvl "github.com/nabbar/golib/logger/level" - liberr "github.com/nabbar/golib/errors" libmon "github.com/nabbar/golib/monitor" moninf "github.com/nabbar/golib/monitor/info" montps "github.com/nabbar/golib/monitor/types" @@ -87,7 +86,7 @@ func (r *request) HealthCheck(ctx context.Context) error { var ( e error - err liberr.Error + err error buf *bytes.Buffer req *http.Request rsp *http.Response @@ -102,40 +101,40 @@ func (r *request) HealthCheck(ctx context.Context) error { if err != nil { if ent != nil { - ent.ErrorAddLib(true, err).Check(loglvl.NilLevel) + ent.ErrorAdd(true, err).Check(loglvl.NilLevel) } return err } rsp, e = r.client().Do(req) if e != nil { - err = ErrorSendRequest.ErrorParent(e) + err = ErrorSendRequest.Error(e) if ent != nil { - ent.ErrorAddLib(true, err).Check(loglvl.NilLevel) + ent.ErrorAdd(true, err).Check(loglvl.NilLevel) } return err } if buf, err = r._CheckResponse(rsp); err != nil { if ent != nil { - ent.ErrorAddLib(true, err).Check(loglvl.NilLevel) + ent.ErrorAdd(true, err).Check(loglvl.NilLevel) } return err } if len(opts.Health.Result.ValidHTTPCode) > 0 { if !r._IsValidCode(opts.Health.Result.ValidHTTPCode, rsp.StatusCode) { - err = ErrorResponseStatus.ErrorParent(fmt.Errorf("status: %s", rsp.Status)) + err = ErrorResponseStatus.Error(fmt.Errorf("status: %s", rsp.Status)) if ent != nil { - ent.ErrorAddLib(true, err).Check(loglvl.NilLevel) + ent.ErrorAdd(true, err).Check(loglvl.NilLevel) } return err } } else if len(opts.Health.Result.InvalidHTTPCode) > 0 { if r._IsValidCode(opts.Health.Result.InvalidHTTPCode, rsp.StatusCode) { - err = ErrorResponseStatus.ErrorParent(fmt.Errorf("status: %s", rsp.Status)) + err = ErrorResponseStatus.Error(fmt.Errorf("status: %s", rsp.Status)) if ent != nil { - ent.ErrorAddLib(true, err).Check(loglvl.NilLevel) + ent.ErrorAdd(true, err).Check(loglvl.NilLevel) } return err } @@ -145,7 +144,7 @@ func (r *request) HealthCheck(ctx context.Context) error { if !r._IsValidContents(opts.Health.Result.Contain, buf) { err = ErrorResponseContainsNotFound.Error(nil) if ent != nil { - ent.ErrorAddLib(true, err).Check(loglvl.NilLevel) + ent.ErrorAdd(true, err).Check(loglvl.NilLevel) } return err } @@ -153,7 +152,7 @@ func (r *request) HealthCheck(ctx context.Context) error { if r._IsValidContents(opts.Health.Result.NotContain, buf) { err = ErrorResponseNotContainsFound.Error(nil) if ent != nil { - ent.ErrorAddLib(true, err).Check(loglvl.NilLevel) + ent.ErrorAdd(true, err).Check(loglvl.NilLevel) } return err } diff --git a/request/options.go b/request/options.go index e4efd7fa..26ed6274 100644 --- a/request/options.go +++ b/request/options.go @@ -38,7 +38,6 @@ import ( libval "github.com/go-playground/validator/v10" libtls "github.com/nabbar/golib/certificates" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" libhtc "github.com/nabbar/golib/httpcli" ) @@ -83,17 +82,17 @@ type Options struct { log liblog.FuncLog } -func (o *Options) Validate() liberr.Error { +func (o *Options) Validate() error { var e = ErrorValidatorError.Error(nil) if err := libval.New().Struct(o); err != nil { if er, ok := err.(*libval.InvalidValidationError); ok { - e.AddParent(er) + e.Add(er) } for _, er := range err.(libval.ValidationErrors) { //nolint #goerr113 - e.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) + e.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) } } @@ -104,17 +103,17 @@ func (o *Options) Validate() liberr.Error { return e } -func (o *OptionsHealth) Validate() liberr.Error { +func (o *OptionsHealth) Validate() error { var e = ErrorValidatorError.Error(nil) if err := libval.New().Struct(o); err != nil { if er, ok := err.(*libval.InvalidValidationError); ok { - e.AddParent(er) + e.Add(er) } for _, er := range err.(libval.ValidationErrors) { //nolint #goerr113 - e.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) + e.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) } } diff --git a/request/request.go b/request/request.go index 4ffc2fe2..a5a08546 100644 --- a/request/request.go +++ b/request/request.go @@ -38,7 +38,7 @@ import ( liberr "github.com/nabbar/golib/errors" ) -func (r *request) _MakeRequest(ctx context.Context, u *url.URL, mtd string, body io.Reader, head url.Values, params url.Values) (*http.Request, liberr.Error) { +func (r *request) _MakeRequest(ctx context.Context, u *url.URL, mtd string, body io.Reader, head url.Values, params url.Values) (*http.Request, error) { var ( req *http.Request err error @@ -47,7 +47,7 @@ func (r *request) _MakeRequest(ctx context.Context, u *url.URL, mtd string, body req, err = http.NewRequestWithContext(ctx, mtd, u.String(), body) if err != nil { - return nil, ErrorCreateRequest.ErrorParent(err) + return nil, ErrorCreateRequest.Error(err) } if len(head) > 0 { @@ -67,7 +67,7 @@ func (r *request) _MakeRequest(ctx context.Context, u *url.URL, mtd string, body return req, nil } -func (r *request) _CheckResponse(rsp *http.Response, validStatus ...int) (*bytes.Buffer, liberr.Error) { +func (r *request) _CheckResponse(rsp *http.Response, validStatus ...int) (*bytes.Buffer, error) { var ( e error b = bytes.NewBuffer(make([]byte, 0)) @@ -85,7 +85,7 @@ func (r *request) _CheckResponse(rsp *http.Response, validStatus ...int) (*bytes if rsp.Body != nil { if _, e = io.Copy(b, rsp.Body); e != nil { - return b, ErrorResponseLoadBody.ErrorParent(e) + return b, ErrorResponseLoadBody.Error(e) } } @@ -126,7 +126,7 @@ func (r *request) _IsValidContents(contains []string, buf *bytes.Buffer) bool { return false } -func (r *request) Do() (*http.Response, liberr.Error) { +func (r *request) Do() (*http.Response, error) { r.s.Lock() defer r.s.Unlock() @@ -138,7 +138,7 @@ func (r *request) Do() (*http.Response, liberr.Error) { e error req *http.Request rsp *http.Response - err liberr.Error + err error ) r.e = &requestError{ @@ -160,18 +160,18 @@ func (r *request) Do() (*http.Response, liberr.Error) { if e != nil { r.e.e = e - return nil, ErrorSendRequest.ErrorParent(e) + return nil, ErrorSendRequest.Error(e) } return rsp, nil } -func (r *request) DoParse(model interface{}, validStatus ...int) liberr.Error { +func (r *request) DoParse(model interface{}, validStatus ...int) error { var ( e error b = bytes.NewBuffer(make([]byte, 0)) - err liberr.Error + err error rsp *http.Response ) @@ -196,7 +196,7 @@ func (r *request) DoParse(model interface{}, validStatus ...int) liberr.Error { b, err = r._CheckResponse(rsp, validStatus...) r.e.b = b - if err != nil && err.HasCodeError(ErrorResponseStatus) { + if er := liberr.Get(err); er != nil && er.HasCode(ErrorResponseStatus) { r.e.se = true } else if err != nil { r.e.e = err @@ -207,15 +207,15 @@ func (r *request) DoParse(model interface{}, validStatus ...int) liberr.Error { if e = json.Unmarshal(b.Bytes(), model); e != nil { r.e.be = true r.e.e = e - return ErrorResponseUnmarshall.ErrorParent(e) + return ErrorResponseUnmarshall.Error(e) } } return nil } -func (r *request) DoParseRetry(retry int, model interface{}, validStatus ...int) liberr.Error { - var e liberr.Error +func (r *request) DoParseRetry(retry int, model interface{}, validStatus ...int) error { + var e error for i := 0; i < retry; i++ { if e = r.DoParse(model, validStatus...); e != nil { diff --git a/router/auth.go b/router/auth.go index 911a44d8..95859d63 100644 --- a/router/auth.go +++ b/router/auth.go @@ -26,6 +26,7 @@ package router import ( + "fmt" "net/http" "strings" @@ -114,7 +115,7 @@ func (a *authorization) Handler(c *ginsdk.Context) { auth := c.Request.Header.Get(HEAD_AUTH_SEND) if auth == "" { - AuthRequire(c, ErrorHeaderAuthMissing.Error(nil).GetErrorFull("")) + AuthRequire(c, fmt.Errorf("%v", ErrorHeaderAuthMissing.Error(nil).GetErrorSlice())) return } @@ -128,7 +129,7 @@ func (a *authorization) Handler(c *ginsdk.Context) { } if authValue == "" { - AuthRequire(c, ErrorHeaderAuthEmpty.Error(nil).GetErrorFull("")) + AuthRequire(c, fmt.Errorf("%v", ErrorHeaderAuthEmpty.Error(nil).GetErrorSlice())) return } else { code, err := a.check(authValue) @@ -140,12 +141,12 @@ func (a *authorization) Handler(c *ginsdk.Context) { r(c) } case AUTH_CODE_REQUIRE: - AuthRequire(c, ErrorHeaderAuthRequire.Error(err).GetErrorFull("")) + AuthRequire(c, fmt.Errorf("%v", ErrorHeaderAuthRequire.Error(err).GetErrorSlice())) case AUTH_CODE_FORBIDDEN: - AuthForbidden(c, ErrorHeaderAuthForbidden.Error(err).GetErrorFull("")) + AuthForbidden(c, fmt.Errorf("%v", ErrorHeaderAuthForbidden.Error(err).GetErrorSlice())) default: c.Errors = append(c.Errors, &ginsdk.Error{ - Err: ErrorHeaderAuth.Error(err).GetErrorFull(""), + Err: fmt.Errorf("%v", ErrorHeaderAuth.Error(err).GetErrorSlice()), Type: ginsdk.ErrorTypePrivate, }) c.AbortWithStatus(http.StatusInternalServerError) diff --git a/semaphore/semaphore.go b/semaphore/semaphore.go index 83807030..56c0c451 100644 --- a/semaphore/semaphore.go +++ b/semaphore/semaphore.go @@ -65,7 +65,7 @@ func (s *sem) setCompleted(flag bool) { func (s *sem) NewWorker() liberr.Error { e := s.s.Acquire(s.context(), 1) - return ErrorWorkerNew.Iferror(e) + return ErrorWorkerNew.IfError(e) } func (s *sem) NewWorkerTry() bool { @@ -75,7 +75,7 @@ func (s *sem) NewWorkerTry() bool { func (s *sem) WaitAll() liberr.Error { e := s.s.Acquire(s.context(), s.i) s.setCompleted(true) - return ErrorWorkerWaitAll.Iferror(e) + return ErrorWorkerWaitAll.IfError(e) } func (s *sem) DeferWorker() { diff --git a/smtp/client.go b/smtp/client.go index 016d6082..28d9fb98 100644 --- a/smtp/client.go +++ b/smtp/client.go @@ -32,11 +32,10 @@ import ( "io" "net/smtp" - liberr "github.com/nabbar/golib/errors" smtpnt "github.com/nabbar/golib/smtp/network" ) -func (s *smtpClient) _client(ctx context.Context) (*smtp.Client, liberr.Error) { +func (s *smtpClient) _client(ctx context.Context) (*smtp.Client, error) { if s.cli != nil && s.con != nil { return s.cli, nil } @@ -82,7 +81,7 @@ func (s *smtpClient) _client(ctx context.Context) (*smtp.Client, liberr.Error) { } // Client Get SMTP Client interface. -func (s *smtpClient) Client(ctx context.Context) (*smtp.Client, liberr.Error) { +func (s *smtpClient) Client(ctx context.Context) (*smtp.Client, error) { s.mut.Lock() defer s.mut.Unlock() @@ -90,7 +89,7 @@ func (s *smtpClient) Client(ctx context.Context) (*smtp.Client, liberr.Error) { } // Check Try to initiate SMTP dial and negotiation and try to close connection. -func (s *smtpClient) Check(ctx context.Context) liberr.Error { +func (s *smtpClient) Check(ctx context.Context) error { s.mut.Lock() defer func() { s._close() @@ -100,7 +99,7 @@ func (s *smtpClient) Check(ctx context.Context) liberr.Error { if c, err := s._client(ctx); err != nil { return err } else if e := c.Noop(); e != nil { - return ErrorSMTPClientNoop.ErrorParent(e) + return ErrorSMTPClientNoop.Error(e) } return nil @@ -108,15 +107,13 @@ func (s *smtpClient) Check(ctx context.Context) liberr.Error { // Send is used to initiate the smtp connection with the client and send a mail before closing the connection. // This function is based on smtp.SendMail function. -func (s *smtpClient) Send(ctx context.Context, from string, to []string, data io.WriterTo) liberr.Error { +func (s *smtpClient) Send(ctx context.Context, from string, to []string, data io.WriterTo) error { //from smtp.SendMail() var ( e error c *smtp.Client w io.WriteCloser - - err liberr.Error ) s.mut.Lock() @@ -132,40 +129,40 @@ func (s *smtpClient) Send(ctx context.Context, from string, to []string, data io s.mut.Unlock() }() - if err = s._ValidateLine(from); err != nil { - return err + if e = s._ValidateLine(from); e != nil { + return e } for _, recp := range to { - if err = s._ValidateLine(recp); err != nil { - return err + if e = s._ValidateLine(recp); e != nil { + return e } } - if c, err = s._client(ctx); err != nil { - return ErrorSMTPClientInit.Error(err) + if c, e = s._client(ctx); e != nil { + return ErrorSMTPClientInit.Error(e) } if e = c.Noop(); e != nil { - return ErrorSMTPClientNoop.ErrorParent(e) + return ErrorSMTPClientNoop.Error(e) } if e = c.Mail(from); e != nil { - return ErrorSMTPClientMail.ErrorParent(e) + return ErrorSMTPClientMail.Error(e) } for _, addr := range to { if e = c.Rcpt(addr); e != nil { - return ErrorSMTPClientRcpt.ErrorParent(e) + return ErrorSMTPClientRcpt.Error(e) } } if w, e = c.Data(); e != nil { - return ErrorSMTPClientData.ErrorParent(e) + return ErrorSMTPClientData.Error(e) } if _, e = data.WriteTo(w); e != nil { - return ErrorSMTPClientWrite.ErrorParent(e) + return ErrorSMTPClientWrite.Error(e) } return nil diff --git a/smtp/config/config.go b/smtp/config/config.go index 992be551..eb0a58e4 100644 --- a/smtp/config/config.go +++ b/smtp/config/config.go @@ -45,21 +45,21 @@ func (c ConfigModel) Validate() liberr.Error { if er := libval.New().Struct(c); er != nil { if e, ok := er.(*libval.InvalidValidationError); ok { - err.AddParent(e) + err.Add(e) } for _, e := range er.(libval.ValidationErrors) { //nolint goerr113 - err.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) + err.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", e.Namespace(), e.ActualTag())) } } if c.DSN != "" { if _, er := New(c); er != nil { - err.AddParent(er) + err.Add(er) } } else { - err.AddParent(ErrorConfigInvalidDSN.Error(nil)) + err.Add(ErrorConfigInvalidDSN.Error(nil)) } if !err.HasParent() { diff --git a/smtp/config/interface.go b/smtp/config/interface.go index d14bbc97..31522eed 100644 --- a/smtp/config/interface.go +++ b/smtp/config/interface.go @@ -159,7 +159,7 @@ func New(cfg ConfigModel) (Config, liberr.Error) { if dsn[j] == '?' { if val, err := url.ParseQuery(dsn[j+1:]); err != nil { - return nil, ErrorConfigInvalidParams.ErrorParent(err) + return nil, ErrorConfigInvalidParams.Error(err) } else { if val.Get("ServerName") != "" { diff --git a/smtp/dial.go b/smtp/dial.go index 563a5347..47facce8 100644 --- a/smtp/dial.go +++ b/smtp/dial.go @@ -65,7 +65,7 @@ func (s *smtpClient) dial(ctx context.Context, addr string) (con net.Conn, err l d := net.Dialer{} if con, e = d.DialContext(ctx, s.cfg.GetNet().String(), addr); e != nil { - return con, ErrorSMTPDial.ErrorParent(e) + return con, ErrorSMTPDial.Error(e) } return @@ -97,14 +97,14 @@ func (s *smtpClient) client(ctx context.Context, addr string, tlsConfig *tls.Con if con, err = s.dialTLS(ctx, addr, tlsConfig); err != nil { return } else if cli, e = smtp.NewClient(con, addr); e != nil { - err = ErrorSMTPClientInit.ErrorParent(e) + err = ErrorSMTPClientInit.Error(e) return } } else { if con, err = s.dial(ctx, addr); err != nil { return } else if cli, e = smtp.NewClient(con, addr); e != nil { - err = ErrorSMTPClientInit.ErrorParent(e) + err = ErrorSMTPClientInit.Error(e) return } @@ -112,7 +112,7 @@ func (s *smtpClient) client(ctx context.Context, addr string, tlsConfig *tls.Con if s.cfg.GetTlsMode() == smtptl.TLSStartTLS || try { if e = cli.StartTLS(tlsConfig); e != nil && !try { - err = ErrorSMTPClientStartTLS.ErrorParent(e) + err = ErrorSMTPClientStartTLS.Error(e) return } else if e == nil && try { s.cfg.SetTlsMode(smtptl.TLSStartTLS) @@ -151,13 +151,13 @@ func (s *smtpClient) auth(cli *smtp.Client, addr string) liberr.Error { } /* if e := cli.Auth(smtp.CRAMMD5Auth(usr, pwd)); e != nil { - err.AddParent(e) + err.Add(e) } else { return nil } */ if e := cli.Auth(smtp.PlainAuth("", usr, pwd, addr)); e != nil { - err.AddParent(e) + err.Add(e) } else { return nil } diff --git a/smtp/interface.go b/smtp/interface.go index 654df5f4..8d40d0b5 100644 --- a/smtp/interface.go +++ b/smtp/interface.go @@ -33,7 +33,6 @@ import ( "sync" libctx "github.com/nabbar/golib/context" - liberr "github.com/nabbar/golib/errors" montps "github.com/nabbar/golib/monitor/types" smtpcf "github.com/nabbar/golib/smtp/config" libver "github.com/nabbar/golib/version" @@ -45,9 +44,9 @@ type SMTP interface { UpdConfig(cfg smtpcf.SMTP, tslConfig *tls.Config) - Client(ctx context.Context) (*smtp.Client, liberr.Error) - Check(ctx context.Context) liberr.Error - Send(ctx context.Context, from string, to []string, data io.WriterTo) liberr.Error + Client(ctx context.Context) (*smtp.Client, error) + Check(ctx context.Context) error + Send(ctx context.Context, from string, to []string, data io.WriterTo) error Monitor(ctx libctx.FuncContext, vrs libver.Version) (montps.Monitor, error) } @@ -57,7 +56,7 @@ type SMTP interface { // - params available are : ServerName (string), SkipVerify (boolean). // - tls mode acceptable are : starttls, tls, . // - net acceptable are : tcp4, tcp6, unix. -func New(cfg smtpcf.SMTP, tlsConfig *tls.Config) (SMTP, liberr.Error) { +func New(cfg smtpcf.SMTP, tlsConfig *tls.Config) (SMTP, error) { if tlsConfig == nil { /* #nosec */ //nolint #nosec diff --git a/smtp/model.go b/smtp/model.go index 10343cf2..5805fd76 100644 --- a/smtp/model.go +++ b/smtp/model.go @@ -32,7 +32,6 @@ import ( "strings" "sync" - liberr "github.com/nabbar/golib/errors" smtpcf "github.com/nabbar/golib/smtp/config" ) @@ -44,7 +43,7 @@ type smtpClient struct { cfg smtpcf.SMTP } -func (s *smtpClient) _ValidateLine(line string) liberr.Error { +func (s *smtpClient) _ValidateLine(line string) error { if strings.ContainsAny(line, "\n\r") { return ErrorSMTPLineCRLF.Error(nil) } diff --git a/static/pathfile.go b/static/pathfile.go index adb373c9..8c8a4817 100644 --- a/static/pathfile.go +++ b/static/pathfile.go @@ -70,7 +70,7 @@ func (s *staticHandler) _setBase(base ...string) { func (s *staticHandler) _listEmbed(root string) ([]fs.DirEntry, liberr.Error) { if root == "" { - return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathfile is empty")) + return nil, ErrorParamEmpty.Error(fmt.Errorf("pathfile is empty")) } s.m.RLock() @@ -79,9 +79,9 @@ func (s *staticHandler) _listEmbed(root string) ([]fs.DirEntry, liberr.Error) { val, err := s.c.ReadDir(root) if err != nil && errors.Is(err, fs.ErrNotExist) { - return nil, ErrorFileNotFound.ErrorParent(err) + return nil, ErrorFileNotFound.Error(err) } else if err != nil { - return nil, ErrorFileOpen.ErrorParent(err) + return nil, ErrorFileOpen.Error(err) } else { return val, nil } @@ -89,7 +89,7 @@ func (s *staticHandler) _listEmbed(root string) ([]fs.DirEntry, liberr.Error) { func (s *staticHandler) _fileGet(pathFile string) (fs.FileInfo, io.ReadCloser, liberr.Error) { if len(pathFile) < 1 { - return nil, nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathfile is empty")) + return nil, nil, ErrorParamEmpty.Error(fmt.Errorf("pathfile is empty")) } if inf, err := s._fileInfo(pathFile); err != nil { @@ -105,7 +105,7 @@ func (s *staticHandler) _fileGet(pathFile string) (fs.FileInfo, io.ReadCloser, l func (s *staticHandler) _fileInfo(pathFile string) (fs.FileInfo, liberr.Error) { if pathFile == "" { - return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathfile is empty")) + return nil, ErrorParamEmpty.Error(fmt.Errorf("pathfile is empty")) } s.m.RLock() @@ -115,9 +115,9 @@ func (s *staticHandler) _fileInfo(pathFile string) (fs.FileInfo, liberr.Error) { obj, err := s.c.Open(pathFile) if err != nil && errors.Is(err, fs.ErrNotExist) { - return nil, ErrorFileNotFound.ErrorParent(err) + return nil, ErrorFileNotFound.Error(err) } else if err != nil { - return nil, ErrorFileOpen.ErrorParent(err) + return nil, ErrorFileOpen.Error(err) } defer func() { @@ -127,9 +127,9 @@ func (s *staticHandler) _fileInfo(pathFile string) (fs.FileInfo, liberr.Error) { inf, err = obj.Stat() if err != nil && errors.Is(err, fs.ErrNotExist) { - return nil, ErrorFileNotFound.ErrorParent(err) + return nil, ErrorFileNotFound.Error(err) } else if err != nil { - return nil, ErrorFileOpen.ErrorParent(err) + return nil, ErrorFileOpen.Error(err) } return inf, nil @@ -137,7 +137,7 @@ func (s *staticHandler) _fileInfo(pathFile string) (fs.FileInfo, liberr.Error) { func (s *staticHandler) _fileBuff(pathFile string) (io.ReadCloser, liberr.Error) { if pathFile == "" { - return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathfile is empty")) + return nil, ErrorParamEmpty.Error(fmt.Errorf("pathfile is empty")) } s.m.RLock() @@ -146,9 +146,9 @@ func (s *staticHandler) _fileBuff(pathFile string) (io.ReadCloser, liberr.Error) obj, err := s.c.ReadFile(pathFile) if err != nil && errors.Is(err, fs.ErrNotExist) { - return nil, ErrorFileNotFound.ErrorParent(err) + return nil, ErrorFileNotFound.Error(err) } else if err != nil { - return nil, ErrorFileOpen.ErrorParent(err) + return nil, ErrorFileOpen.Error(err) } else { return libiot.NewBufferReadCloser(bytes.NewBuffer(obj)), nil } @@ -156,7 +156,7 @@ func (s *staticHandler) _fileBuff(pathFile string) (io.ReadCloser, liberr.Error) func (s *staticHandler) _fileTemp(pathFile string) (libfpg.Progress, liberr.Error) { if pathFile == "" { - return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("pathfile is empty")) + return nil, ErrorParamEmpty.Error(fmt.Errorf("pathfile is empty")) } s.m.RLock() @@ -166,9 +166,9 @@ func (s *staticHandler) _fileTemp(pathFile string) (libfpg.Progress, liberr.Erro obj, err := s.c.Open(pathFile) if err != nil && errors.Is(err, fs.ErrNotExist) { - return nil, ErrorFileNotFound.ErrorParent(err) + return nil, ErrorFileNotFound.Error(err) } else if err != nil { - return nil, ErrorFileOpen.ErrorParent(err) + return nil, ErrorFileOpen.Error(err) } defer func() { @@ -177,12 +177,12 @@ func (s *staticHandler) _fileTemp(pathFile string) (libfpg.Progress, liberr.Erro tmp, err = libfpg.Temp("") if err != nil { - return nil, ErrorFiletemp.ErrorParent(err) + return nil, ErrorFiletemp.Error(err) } _, e := io.Copy(tmp, obj) if e != nil { - return nil, ErrorFiletemp.ErrorParent(e) + return nil, ErrorFiletemp.Error(e) } return tmp, nil diff --git a/status/config.go b/status/config.go index 55ce7782..6f1df2b5 100644 --- a/status/config.go +++ b/status/config.go @@ -57,12 +57,12 @@ func (o Config) Validate() error { if err := libval.New().Struct(o); err != nil { if er, ok := err.(*libval.InvalidValidationError); ok { - e.AddParent(er) + e.Add(er) } for _, er := range err.(libval.ValidationErrors) { //nolint #goerr113 - e.AddParent(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) + e.Add(fmt.Errorf("config field '%s' is not validated by constraint '%s'", er.Namespace(), er.ActualTag())) } } diff --git a/status/encode.go b/status/encode.go index b4be7238..2294f4fc 100644 --- a/status/encode.go +++ b/status/encode.go @@ -170,7 +170,7 @@ func (o *sts) getEncodeModel() Encode { func (o *sts) getMarshal() (Encode, liberr.Error) { if !o.checkFunc() { - return nil, ErrorParamEmpty.ErrorParent(fmt.Errorf("missing status info for API")) + return nil, ErrorParamEmpty.Error(fmt.Errorf("missing status info for API")) } return o.getEncodeModel(), nil } diff --git a/version/version.go b/version/version.go index 5cf4dc2b..10af0fc7 100644 --- a/version/version.go +++ b/version/version.go @@ -111,17 +111,17 @@ func NewVersion(License license, Package, Description, Date, Build, Release, Aut func (v versionModel) CheckGo(RequireGoVersion, RequireGoContraint string) liberr.Error { constraint, err := govers.NewConstraint(RequireGoContraint + RequireGoVersion) if err != nil { - return ErrorGoVersionInit.ErrorParent(err) + return ErrorGoVersionInit.Error(err) } goVersion, err := govers.NewVersion(runtime.Version()[2:]) if err != nil { - return ErrorGoVersionRuntime.ErrorParent(err) + return ErrorGoVersionRuntime.Error(err) } if !constraint.Check(goVersion) { //nolint #goerr113 - return ErrorGoVersionConstraint.ErrorParent(fmt.Errorf("must be compiled with Go version %s (instead of %s)", RequireGoVersion, goVersion)) + return ErrorGoVersionConstraint.Error(fmt.Errorf("must be compiled with Go version %s (instead of %s)", RequireGoVersion, goVersion)) } return nil diff --git a/viper/config.go b/viper/config.go index 49d767df..94738f06 100644 --- a/viper/config.go +++ b/viper/config.go @@ -35,7 +35,7 @@ func (v *viper) Config(logLevelRemoteKO, logLevelRemoteOK loglvl.Level) liberr.E if err := v.initAddRemote(); err == nil { v.initWatchRemote(logLevelRemoteKO, logLevelRemoteOK) return nil - } else if !err.IsCodeError(ErrorParamMissing) { + } else if !err.IsCode(ErrorParamMissing) { return err } @@ -48,11 +48,11 @@ func (v *viper) Config(logLevelRemoteKO, logLevelRemoteOK loglvl.Level) liberr.E if v.deft != nil { v.v.SetConfigType("json") if err = v.v.ReadConfig(v.deft()); err != nil { - return ErrorConfigReadDefault.ErrorParent(err) + return ErrorConfigReadDefault.Error(err) } return ErrorConfigIsDefault.Error(nil) } - return ErrorConfigRead.ErrorParent(err) + return ErrorConfigRead.Error(err) } diff --git a/viper/model.go b/viper/model.go index 70588759..5faf6e57 100644 --- a/viper/model.go +++ b/viper/model.go @@ -111,14 +111,14 @@ func (v *viper) SetConfigFile(fileConfig string) liberr.Error { // Find home directory. home, err := libhom.Dir() if err != nil { - return ErrorHomePathNotFound.ErrorParent(err) + return ErrorHomePathNotFound.Error(err) } // Search config in home directory with name defined in SetConfigName (without extension). v.v.AddConfigPath(home) if v.base == "" { - return ErrorBasePathNotFound.ErrorParent(fmt.Errorf("base name of config file is empty")) + return ErrorBasePathNotFound.Error(fmt.Errorf("base name of config file is empty")) } v.v.SetConfigName("." + v.base) diff --git a/viper/remote.go b/viper/remote.go index 95bae529..5189a2e7 100644 --- a/viper/remote.go +++ b/viper/remote.go @@ -37,10 +37,10 @@ func (v *viper) initAddRemote() liberr.Error { if v.remote.secure != "" { if err := v.v.AddSecureRemoteProvider(v.remote.provider, v.remote.endpoint, v.remote.path, v.remote.secure); err != nil { - return ErrorRemoteProviderSecure.ErrorParent(err) + return ErrorRemoteProviderSecure.Error(err) } } else if err := v.v.AddRemoteProvider(v.remote.provider, v.remote.endpoint, v.remote.path); err != nil { - return ErrorRemoteProvider.ErrorParent(err) + return ErrorRemoteProvider.Error(err) } return v.initSetRemote() @@ -50,11 +50,11 @@ func (v *viper) initSetRemote() liberr.Error { v.v.SetConfigType("json") if err := v.v.ReadRemoteConfig(); err != nil { - return ErrorRemoteProviderRead.ErrorParent(err) + return ErrorRemoteProviderRead.Error(err) } if err := v.v.Unmarshal(v.remote.model); err != nil { - return ErrorRemoteProviderMarshall.ErrorParent(err) + return ErrorRemoteProviderMarshall.Error(err) } return nil