Skip to content

Commit

Permalink
Feat: Refine error messages to include specific invalid values.
Browse files Browse the repository at this point in the history
Updated error messages in `server/config/types.go` to provide more context by including the invalid value in the error description. Modified error definitions in `server/errors/errors.go` accordingly. Changed `Learning` field type in `BruteforceSection` to a pointer to `Feature` for consistency.

Signed-off-by: Christian Roessner <[email protected]>
  • Loading branch information
Christian Roessner committed Nov 13, 2024
1 parent 97eb328 commit c7f2bc8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion server/config/bruteforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import "fmt"
type BruteForceSection struct {
IPWhitelist []string `mapstructure:"ip_whitelist"`
Buckets []BruteForceRule `mapstructure:"buckets"`
Learning []Feature `mapstructure:"learning"`
Learning []*Feature `mapstructure:"learning"`
}

func (b *BruteForceSection) String() string {
Expand Down
11 changes: 6 additions & 5 deletions server/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package config

import (
"fmt"
"strings"

"github.com/croessner/nauthilus/server/errors"
Expand Down Expand Up @@ -64,7 +65,7 @@ func (v *Verbosity) Set(value string) error {
case "debug":
v.verboseLevel = global.LogLevelDebug
default:
return errors.ErrWrongVerboseLevel
return fmt.Errorf(errors.ErrWrongVerboseLevel.Error(), value)
}

v.name = value
Expand Down Expand Up @@ -129,7 +130,7 @@ func (l *LDAPScope) Set(value string) error {
case "sub":
l.scope = ldap.ScopeWholeSubtree
default:
return errors.ErrWrongLDAPScope
return fmt.Errorf(errors.ErrWrongLDAPScope.Error(), value)
}

l.name = value
Expand Down Expand Up @@ -241,7 +242,7 @@ func (b *Backend) Set(value string) error {
case global.BackendLuaName:
b.backend = global.BackendLua
default:
return errors.ErrWrongPassDB
return fmt.Errorf(errors.ErrWrongPassDB.Error(), value)
}

return nil
Expand Down Expand Up @@ -293,7 +294,7 @@ func (f *Feature) Set(value string) error {
case global.FeatureTLSEncryption, global.FeatureRBL, global.FeatureRelayDomains, global.FeatureLua, global.FeatureBackendServersMonitoring, global.FeatureBruteForce:
f.name = value
default:
return errors.ErrWrongFeature
return fmt.Errorf(errors.ErrWrongFeature.Error(), value)
}

return nil
Expand Down Expand Up @@ -378,7 +379,7 @@ func (d *DbgModule) Set(value string) error {
case global.DbgFilterName:
d.module = global.DbgFilter
default:
return errors.ErrWrongDebugModule
return fmt.Errorf(errors.ErrWrongDebugModule.Error(), value)
}

d.name = value
Expand Down
10 changes: 5 additions & 5 deletions server/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ var (
// env.

var (
ErrWrongVerboseLevel = errors.New("wrong verbose level")
ErrWrongLDAPScope = errors.New("wrong LDAP scope")
ErrWrongPassDB = errors.New("wrong passdb backend")
ErrWrongFeature = errors.New("wrong feature")
ErrWrongDebugModule = errors.New("wrong debug module")
ErrWrongVerboseLevel = errors.New("wrong verbose level: <%s>")
ErrWrongLDAPScope = errors.New("wrong LDAP scope: <%s>")
ErrWrongPassDB = errors.New("wrong passdb backend: <%s>")
ErrWrongFeature = errors.New("wrong feature: <%s>")
ErrWrongDebugModule = errors.New("wrong debug module: <%s>")
)

// file.
Expand Down

0 comments on commit c7f2bc8

Please sign in to comment.