Fix error code collision:

- Package Config
- Package Archive
This commit is contained in:
Nicolas JUHEL
2022-09-14 12:44:02 +02:00
parent 3dc1cbe9ff
commit 917819b8b7
10 changed files with 129 additions and 93 deletions

View File

@@ -0,0 +1,39 @@
/*
* MIT License
*
* Copyright (c) 2020 Nicolas JUHEL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*
*/
package archive
import (
liberr "github.com/nabbar/golib/errors"
)
const (
MinPkgArchive = liberr.MinPkgArchive
MinPkgArchiveBZ2 = MinPkgArchive + 20
MinPkgArchiveGZip = MinPkgArchiveBZ2 + 20
MinPkgArchiveTar = MinPkgArchiveGZip + 20
MinPkgArchiveZip = MinPkgArchiveTar + 20
)

View File

@@ -26,30 +26,29 @@
package bz2 package bz2
import "github.com/nabbar/golib/errors" import (
"fmt"
arcmod "github.com/nabbar/golib/archive/archive"
liberr "github.com/nabbar/golib/errors"
)
const ( const (
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgArchive + 10 ErrorParamEmpty liberr.CodeError = iota + arcmod.MinPkgArchiveBZ2
ErrorFileSeek ErrorFileSeek
ErrorIOCopy ErrorIOCopy
) )
var isCodeError = false
func IsCodeError() bool {
return isCodeError
}
func init() { func init() {
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty) if liberr.ExistInMapMessage(ErrorParamEmpty) {
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage) panic(fmt.Errorf("error code collision golib/archive/bz2"))
}
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
} }
func getMessage(code errors.CodeError) (message string) { func getMessage(code liberr.CodeError) (message string) {
switch code { switch code {
case errors.UNK_ERROR: case ErrorParamEmpty:
return ""
case ErrorParamsEmpty:
return "given parameters is empty" return "given parameters is empty"
case ErrorFileSeek: case ErrorFileSeek:
return "cannot seek into file" return "cannot seek into file"
@@ -57,5 +56,5 @@ func getMessage(code errors.CodeError) (message string) {
return "io copy occurs error" return "io copy occurs error"
} }
return "" return liberr.NullMessage
} }

View File

@@ -28,12 +28,12 @@ package archive
import ( import (
"fmt" "fmt"
arcmod "github.com/nabbar/golib/archive/archive"
liberr "github.com/nabbar/golib/errors" liberr "github.com/nabbar/golib/errors"
) )
const ( const (
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgArchive ErrorParamEmpty liberr.CodeError = iota + arcmod.MinPkgArchive
ErrorFileSeek ErrorFileSeek
ErrorFileOpen ErrorFileOpen
ErrorFileClose ErrorFileClose
@@ -45,7 +45,7 @@ const (
func init() { func init() {
if liberr.ExistInMapMessage(ErrorParamEmpty) { if liberr.ExistInMapMessage(ErrorParamEmpty) {
panic(fmt.Errorf("error code collision")) panic(fmt.Errorf("error code collision golib/archive"))
} }
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage) liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
} }

View File

@@ -26,11 +26,16 @@
package gzip package gzip
import "github.com/nabbar/golib/errors" import (
"fmt"
arcmod "github.com/nabbar/golib/archive/archive"
liberr "github.com/nabbar/golib/errors"
)
const ( const (
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgArchive + 20 ErrorParamEmpty liberr.CodeError = iota + arcmod.MinPkgArchiveGZip
ErrorParamsMismatching ErrorParamMismatching
ErrorGZCreate ErrorGZCreate
ErrorGZReader ErrorGZReader
ErrorFileSeek ErrorFileSeek
@@ -38,24 +43,18 @@ const (
ErrorFileOpen ErrorFileOpen
) )
var isCodeError = false
func IsCodeError() bool {
return isCodeError
}
func init() { func init() {
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty) if liberr.ExistInMapMessage(ErrorParamEmpty) {
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage) panic(fmt.Errorf("error code collision golib/archive/gzip"))
}
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
} }
func getMessage(code errors.CodeError) (message string) { func getMessage(code liberr.CodeError) (message string) {
switch code { switch code {
case errors.UNK_ERROR: case ErrorParamEmpty:
return ""
case ErrorParamsEmpty:
return "given parameters is empty" return "given parameters is empty"
case ErrorParamsMismatching: case ErrorParamMismatching:
return "given parameters is not matching the awaiting scope" return "given parameters is not matching the awaiting scope"
case ErrorGZCreate: case ErrorGZCreate:
return "cannot create the GZip archive" return "cannot create the GZip archive"
@@ -69,5 +68,5 @@ func getMessage(code errors.CodeError) (message string) {
return "cannot open file content" return "cannot open file content"
} }
return "" return liberr.NullMessage
} }

View File

@@ -46,7 +46,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content ..
if len(content) != 1 { if len(content) != 1 {
//nolint #goerr113 //nolint #goerr113
return false, ErrorParamsMismatching.ErrorParent(fmt.Errorf("content path must be limited to strictly one contents")) return false, ErrorParamMismatching.ErrorParent(fmt.Errorf("content path must be limited to strictly one contents"))
} }
if _, err = archive.Seek(0, io.SeekStart); err != nil { if _, err = archive.Seek(0, io.SeekStart); err != nil {
@@ -54,7 +54,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content ..
} }
if _, err = os.Stat(content[0]); err != nil { if _, err = os.Stat(content[0]); err != nil {
return false, ErrorParamsEmpty.ErrorParent(err) return false, ErrorParamEmpty.ErrorParent(err)
} }
w = gzip.NewWriter(archive) w = gzip.NewWriter(archive)

View File

@@ -26,10 +26,15 @@
package tar package tar
import "github.com/nabbar/golib/errors" import (
"fmt"
arcmod "github.com/nabbar/golib/archive/archive"
liberr "github.com/nabbar/golib/errors"
)
const ( const (
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgArchive + 30 ErrorParamEmpty liberr.CodeError = iota + arcmod.MinPkgArchiveTar
ErrorTarNext ErrorTarNext
ErrorFileOpen ErrorFileOpen
ErrorFileSeek ErrorFileSeek
@@ -47,22 +52,16 @@ const (
ErrorTarCreateAddFile ErrorTarCreateAddFile
) )
var isCodeError = false
func IsCodeError() bool {
return isCodeError
}
func init() { func init() {
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty) if liberr.ExistInMapMessage(ErrorParamEmpty) {
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage) panic(fmt.Errorf("error code collision golib/archive/tar"))
}
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
} }
func getMessage(code errors.CodeError) (message string) { func getMessage(code liberr.CodeError) (message string) {
switch code { switch code {
case errors.UNK_ERROR: case ErrorParamEmpty:
return ""
case ErrorParamsEmpty:
return "given parameters is empty" return "given parameters is empty"
case ErrorTarNext: case ErrorTarNext:
return "cannot get next tar file" return "cannot get next tar file"
@@ -96,5 +95,5 @@ func getMessage(code errors.CodeError) (message string) {
return "cannot add file content to tar archive" return "cannot add file content to tar archive"
} }
return "" return liberr.NullMessage
} }

View File

@@ -26,10 +26,15 @@
package zip package zip
import "github.com/nabbar/golib/errors" import (
"fmt"
arcmod "github.com/nabbar/golib/archive/archive"
liberr "github.com/nabbar/golib/errors"
)
const ( const (
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgArchive + 40 ErrorParamEmpty liberr.CodeError = iota + arcmod.MinPkgArchiveZip
ErrorFileOpen ErrorFileOpen
ErrorFileClose ErrorFileClose
ErrorFileSeek ErrorFileSeek
@@ -48,22 +53,16 @@ const (
ErrorDestinationRemove ErrorDestinationRemove
) )
var isCodeError = false
func IsCodeError() bool {
return isCodeError
}
func init() { func init() {
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty) if liberr.ExistInMapMessage(ErrorParamEmpty) {
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage) panic(fmt.Errorf("error code collision golib/archive/zip"))
}
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
} }
func getMessage(code errors.CodeError) (message string) { func getMessage(code liberr.CodeError) (message string) {
switch code { switch code {
case errors.UNK_ERROR: case ErrorParamEmpty:
return ""
case ErrorParamsEmpty:
return "given parameters is empty" return "given parameters is empty"
case ErrorFileOpen: case ErrorFileOpen:
return "cannot open zipped file" return "cannot open zipped file"
@@ -99,5 +98,5 @@ func getMessage(code errors.CodeError) (message string) {
return "cannot remove destination " return "cannot remove destination "
} }
return "" return liberr.NullMessage
} }

View File

@@ -34,7 +34,7 @@ import (
) )
const ( const (
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentRequest ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentLdap
ErrorParamInvalid ErrorParamInvalid
ErrorComponentNotInitialized ErrorComponentNotInitialized
ErrorConfigInvalid ErrorConfigInvalid

View File

@@ -48,7 +48,8 @@ const (
MinErrorComponentDatabase = MinErrorComponentAws + 10 MinErrorComponentDatabase = MinErrorComponentAws + 10
MinErrorComponentHead = MinErrorComponentDatabase + 10 MinErrorComponentHead = MinErrorComponentDatabase + 10
MinErrorComponentHttp = MinErrorComponentHead + 10 MinErrorComponentHttp = MinErrorComponentHead + 10
MinErrorComponentLog = MinErrorComponentHttp + 10 MinErrorComponentLdap = MinErrorComponentHttp + 10
MinErrorComponentLog = MinErrorComponentLdap + 10
MinErrorComponentMail = MinErrorComponentLog + 10 MinErrorComponentMail = MinErrorComponentLog + 10
MinErrorComponentNats = MinErrorComponentMail + 10 MinErrorComponentNats = MinErrorComponentMail + 10
MinErrorComponentNutsDB = MinErrorComponentNats + 10 MinErrorComponentNutsDB = MinErrorComponentNats + 10

View File

@@ -32,30 +32,30 @@ const (
MinPkgCertificate = 300 MinPkgCertificate = 300
MinPkgCluster = 400 MinPkgCluster = 400
MinPkgConfig = 500 MinPkgConfig = 500
MinPkgConsole = 600 MinPkgConsole = 800
MinPkgCrypt = 700 MinPkgCrypt = 900
MinPkgDatabase = 800 MinPkgDatabase = 1000
MinPkgFTPClient = 900 MinPkgFTPClient = 1100
MinPkgHttpCli = 1000 MinPkgHttpCli = 1200
MinPkgHttpServer = 1100 MinPkgHttpServer = 1300
MinPkgIOUtils = 1200 MinPkgIOUtils = 1400
MinPkgLDAP = 1300 MinPkgLDAP = 1500
MinPkgLogger = 1400 MinPkgLogger = 1600
MinPkgMail = 1500 MinPkgMail = 1700
MinPkgMailer = 1600 MinPkgMailer = 1800
MinPkgMailPooler = 1700 MinPkgMailPooler = 1900
MinPkgNetwork = 1800 MinPkgNetwork = 2000
MinPkgNats = 1900 MinPkgNats = 2100
MinPkgNutsDB = 2000 MinPkgNutsDB = 2200
MinPkgOAuth = 2100 MinPkgOAuth = 2300
MinPkgAws = 2200 MinPkgAws = 2400
MinPkgRequest = 2300 MinPkgRequest = 2500
MinPkgRouter = 2400 MinPkgRouter = 2600
MinPkgSemaphore = 2500 MinPkgSemaphore = 2700
MinPkgSMTP = 2600 MinPkgSMTP = 2800
MinPkgStatic = 2700 MinPkgStatic = 2900
MinPkgVersion = 2800 MinPkgVersion = 3000
MinPkgViper = 2900 MinPkgViper = 3100
MinAvailable = 4000 MinAvailable = 4000