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
This commit is contained in:
Nicolas JUHEL
2023-08-25 15:48:35 +02:00
parent a672f6ed10
commit 984ba51587
189 changed files with 1283 additions and 1435 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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()

View File

@@ -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()

View File

@@ -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