mirror of
https://github.com/nabbar/golib.git
synced 2025-10-05 07:46:56 +08:00
Fix error code collision:
- Package Config - Package Archive
This commit is contained in:
39
archive/archive/minPkgErr.go
Normal file
39
archive/archive/minPkgErr.go
Normal 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
|
||||
)
|
@@ -26,30 +26,29 @@
|
||||
|
||||
package bz2
|
||||
|
||||
import "github.com/nabbar/golib/errors"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
arcmod "github.com/nabbar/golib/archive/archive"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgArchive + 10
|
||||
ErrorParamEmpty liberr.CodeError = iota + arcmod.MinPkgArchiveBZ2
|
||||
ErrorFileSeek
|
||||
ErrorIOCopy
|
||||
)
|
||||
|
||||
var isCodeError = false
|
||||
|
||||
func IsCodeError() bool {
|
||||
return isCodeError
|
||||
}
|
||||
|
||||
func init() {
|
||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
||||
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||
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 {
|
||||
case errors.UNK_ERROR:
|
||||
return ""
|
||||
case ErrorParamsEmpty:
|
||||
case ErrorParamEmpty:
|
||||
return "given parameters is empty"
|
||||
case ErrorFileSeek:
|
||||
return "cannot seek into file"
|
||||
@@ -57,5 +56,5 @@ func getMessage(code errors.CodeError) (message string) {
|
||||
return "io copy occurs error"
|
||||
}
|
||||
|
||||
return ""
|
||||
return liberr.NullMessage
|
||||
}
|
||||
|
@@ -28,12 +28,12 @@ package archive
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
arcmod "github.com/nabbar/golib/archive/archive"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgArchive
|
||||
ErrorParamEmpty liberr.CodeError = iota + arcmod.MinPkgArchive
|
||||
ErrorFileSeek
|
||||
ErrorFileOpen
|
||||
ErrorFileClose
|
||||
@@ -45,7 +45,7 @@ const (
|
||||
|
||||
func init() {
|
||||
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||
panic(fmt.Errorf("error code collision"))
|
||||
panic(fmt.Errorf("error code collision golib/archive"))
|
||||
}
|
||||
liberr.RegisterIdFctMessage(ErrorParamEmpty, getMessage)
|
||||
}
|
||||
|
@@ -26,11 +26,16 @@
|
||||
|
||||
package gzip
|
||||
|
||||
import "github.com/nabbar/golib/errors"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
arcmod "github.com/nabbar/golib/archive/archive"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgArchive + 20
|
||||
ErrorParamsMismatching
|
||||
ErrorParamEmpty liberr.CodeError = iota + arcmod.MinPkgArchiveGZip
|
||||
ErrorParamMismatching
|
||||
ErrorGZCreate
|
||||
ErrorGZReader
|
||||
ErrorFileSeek
|
||||
@@ -38,24 +43,18 @@ const (
|
||||
ErrorFileOpen
|
||||
)
|
||||
|
||||
var isCodeError = false
|
||||
|
||||
func IsCodeError() bool {
|
||||
return isCodeError
|
||||
}
|
||||
|
||||
func init() {
|
||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
||||
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||
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 {
|
||||
case errors.UNK_ERROR:
|
||||
return ""
|
||||
case ErrorParamsEmpty:
|
||||
case ErrorParamEmpty:
|
||||
return "given parameters is empty"
|
||||
case ErrorParamsMismatching:
|
||||
case ErrorParamMismatching:
|
||||
return "given parameters is not matching the awaiting scope"
|
||||
case ErrorGZCreate:
|
||||
return "cannot create the GZip archive"
|
||||
@@ -69,5 +68,5 @@ func getMessage(code errors.CodeError) (message string) {
|
||||
return "cannot open file content"
|
||||
}
|
||||
|
||||
return ""
|
||||
return liberr.NullMessage
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content ..
|
||||
|
||||
if len(content) != 1 {
|
||||
//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 {
|
||||
@@ -54,7 +54,7 @@ func Create(archive io.WriteSeeker, stripPath string, comment string, content ..
|
||||
}
|
||||
|
||||
if _, err = os.Stat(content[0]); err != nil {
|
||||
return false, ErrorParamsEmpty.ErrorParent(err)
|
||||
return false, ErrorParamEmpty.ErrorParent(err)
|
||||
}
|
||||
|
||||
w = gzip.NewWriter(archive)
|
||||
|
@@ -26,10 +26,15 @@
|
||||
|
||||
package tar
|
||||
|
||||
import "github.com/nabbar/golib/errors"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
arcmod "github.com/nabbar/golib/archive/archive"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgArchive + 30
|
||||
ErrorParamEmpty liberr.CodeError = iota + arcmod.MinPkgArchiveTar
|
||||
ErrorTarNext
|
||||
ErrorFileOpen
|
||||
ErrorFileSeek
|
||||
@@ -47,22 +52,16 @@ const (
|
||||
ErrorTarCreateAddFile
|
||||
)
|
||||
|
||||
var isCodeError = false
|
||||
|
||||
func IsCodeError() bool {
|
||||
return isCodeError
|
||||
}
|
||||
|
||||
func init() {
|
||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
||||
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||
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 {
|
||||
case errors.UNK_ERROR:
|
||||
return ""
|
||||
case ErrorParamsEmpty:
|
||||
case ErrorParamEmpty:
|
||||
return "given parameters is empty"
|
||||
case ErrorTarNext:
|
||||
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 ""
|
||||
return liberr.NullMessage
|
||||
}
|
||||
|
@@ -26,10 +26,15 @@
|
||||
|
||||
package zip
|
||||
|
||||
import "github.com/nabbar/golib/errors"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
arcmod "github.com/nabbar/golib/archive/archive"
|
||||
liberr "github.com/nabbar/golib/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrorParamsEmpty errors.CodeError = iota + errors.MinPkgArchive + 40
|
||||
ErrorParamEmpty liberr.CodeError = iota + arcmod.MinPkgArchiveZip
|
||||
ErrorFileOpen
|
||||
ErrorFileClose
|
||||
ErrorFileSeek
|
||||
@@ -48,22 +53,16 @@ const (
|
||||
ErrorDestinationRemove
|
||||
)
|
||||
|
||||
var isCodeError = false
|
||||
|
||||
func IsCodeError() bool {
|
||||
return isCodeError
|
||||
}
|
||||
|
||||
func init() {
|
||||
isCodeError = errors.ExistInMapMessage(ErrorParamsEmpty)
|
||||
errors.RegisterIdFctMessage(ErrorParamsEmpty, getMessage)
|
||||
if liberr.ExistInMapMessage(ErrorParamEmpty) {
|
||||
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 {
|
||||
case errors.UNK_ERROR:
|
||||
return ""
|
||||
case ErrorParamsEmpty:
|
||||
case ErrorParamEmpty:
|
||||
return "given parameters is empty"
|
||||
case ErrorFileOpen:
|
||||
return "cannot open zipped file"
|
||||
@@ -99,5 +98,5 @@ func getMessage(code errors.CodeError) (message string) {
|
||||
return "cannot remove destination "
|
||||
}
|
||||
|
||||
return ""
|
||||
return liberr.NullMessage
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentRequest
|
||||
ErrorParamEmpty liberr.CodeError = iota + libcfg.MinErrorComponentLdap
|
||||
ErrorParamInvalid
|
||||
ErrorComponentNotInitialized
|
||||
ErrorConfigInvalid
|
||||
|
@@ -48,7 +48,8 @@ const (
|
||||
MinErrorComponentDatabase = MinErrorComponentAws + 10
|
||||
MinErrorComponentHead = MinErrorComponentDatabase + 10
|
||||
MinErrorComponentHttp = MinErrorComponentHead + 10
|
||||
MinErrorComponentLog = MinErrorComponentHttp + 10
|
||||
MinErrorComponentLdap = MinErrorComponentHttp + 10
|
||||
MinErrorComponentLog = MinErrorComponentLdap + 10
|
||||
MinErrorComponentMail = MinErrorComponentLog + 10
|
||||
MinErrorComponentNats = MinErrorComponentMail + 10
|
||||
MinErrorComponentNutsDB = MinErrorComponentNats + 10
|
||||
|
@@ -32,30 +32,30 @@ const (
|
||||
MinPkgCertificate = 300
|
||||
MinPkgCluster = 400
|
||||
MinPkgConfig = 500
|
||||
MinPkgConsole = 600
|
||||
MinPkgCrypt = 700
|
||||
MinPkgDatabase = 800
|
||||
MinPkgFTPClient = 900
|
||||
MinPkgHttpCli = 1000
|
||||
MinPkgHttpServer = 1100
|
||||
MinPkgIOUtils = 1200
|
||||
MinPkgLDAP = 1300
|
||||
MinPkgLogger = 1400
|
||||
MinPkgMail = 1500
|
||||
MinPkgMailer = 1600
|
||||
MinPkgMailPooler = 1700
|
||||
MinPkgNetwork = 1800
|
||||
MinPkgNats = 1900
|
||||
MinPkgNutsDB = 2000
|
||||
MinPkgOAuth = 2100
|
||||
MinPkgAws = 2200
|
||||
MinPkgRequest = 2300
|
||||
MinPkgRouter = 2400
|
||||
MinPkgSemaphore = 2500
|
||||
MinPkgSMTP = 2600
|
||||
MinPkgStatic = 2700
|
||||
MinPkgVersion = 2800
|
||||
MinPkgViper = 2900
|
||||
MinPkgConsole = 800
|
||||
MinPkgCrypt = 900
|
||||
MinPkgDatabase = 1000
|
||||
MinPkgFTPClient = 1100
|
||||
MinPkgHttpCli = 1200
|
||||
MinPkgHttpServer = 1300
|
||||
MinPkgIOUtils = 1400
|
||||
MinPkgLDAP = 1500
|
||||
MinPkgLogger = 1600
|
||||
MinPkgMail = 1700
|
||||
MinPkgMailer = 1800
|
||||
MinPkgMailPooler = 1900
|
||||
MinPkgNetwork = 2000
|
||||
MinPkgNats = 2100
|
||||
MinPkgNutsDB = 2200
|
||||
MinPkgOAuth = 2300
|
||||
MinPkgAws = 2400
|
||||
MinPkgRequest = 2500
|
||||
MinPkgRouter = 2600
|
||||
MinPkgSemaphore = 2700
|
||||
MinPkgSMTP = 2800
|
||||
MinPkgStatic = 2900
|
||||
MinPkgVersion = 3000
|
||||
MinPkgViper = 3100
|
||||
|
||||
MinAvailable = 4000
|
||||
|
||||
|
Reference in New Issue
Block a user