diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-10-07 17:58:28 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-10-07 17:58:28 +0900 |
| commit | 2489766efe7b94873a04339009c3609c55e3856f (patch) | |
| tree | 35d186f02e65b52bb9f0d49e34f7cda981c03ec4 /hst/config.go | |
| parent | 9e48d7f5626aa966a23754534f3120855d6a7c32 (diff) | |
hst/config: identity bounds check early
This makes sense to do here instead of in internal/app.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'hst/config.go')
| -rw-r--r-- | hst/config.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/hst/config.go b/hst/config.go index 8581bbcf..4629d3db 100644 --- a/hst/config.go +++ b/hst/config.go @@ -2,6 +2,7 @@ package hst import ( "errors" + "strconv" "time" "hakurei.app/container" @@ -118,15 +119,28 @@ type ( } ) -// ErrConfigNull is returned by [Config.Validate] for an invalid configuration that contains a null value for any -// field that must not be null. -var ErrConfigNull = errors.New("unexpected null in config") +var ( + // ErrConfigNull is returned by [Config.Validate] for an invalid configuration that contains a null value for any + // field that must not be null. + ErrConfigNull = errors.New("unexpected null in config") + // ErrIdentityBounds is returned by [Config.Validate] for an out of bounds [Config.Identity] value. + ErrIdentityBounds = errors.New("identity out of bounds") +) + +// Validate checks [Config] and returns [AppError] if an invalid value is encountered. func (config *Config) Validate() error { if config == nil { return &AppError{Step: "validate configuration", Err: ErrConfigNull, Msg: "invalid configuration"} } + + // this is checked again in hsu + if config.Identity < IdentityMin || config.Identity > IdentityMax { + return &AppError{Step: "validate configuration", Err: ErrIdentityBounds, + Msg: "identity " + strconv.Itoa(config.Identity) + " out of range"} + } + if config.Container == nil { return &AppError{Step: "validate configuration", Err: ErrConfigNull, Msg: "configuration missing container state"} |
