feat: improve error handling
This commit is contained in:
parent
af9ab60092
commit
e6299c0010
4 changed files with 21 additions and 15 deletions
|
@ -83,15 +83,6 @@ func location(skip int) string {
|
||||||
return fmt.Sprintf("%s:%d", file, line)
|
return fmt.Sprintf("%s:%d", file, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
ErrBadRole = errors.New("bad role")
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrBadTestingStrategy = errors.New("bad testing strategy")
|
|
||||||
ErrBadResult = errors.New("bad result")
|
|
||||||
)
|
|
||||||
|
|
||||||
type Error struct {
|
type Error struct {
|
||||||
src error
|
src error
|
||||||
layer layer
|
layer layer
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "git.sch9.ru/new_gate/ms-tester/internal/lib"
|
import (
|
||||||
|
"errors"
|
||||||
|
"git.sch9.ru/new_gate/ms-tester/internal/lib"
|
||||||
|
)
|
||||||
|
|
||||||
type Result int32
|
type Result int32
|
||||||
|
|
||||||
|
@ -14,10 +17,12 @@ const (
|
||||||
Testing Result = 6
|
Testing Result = 6
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrBadResult = errors.New("bad result")
|
||||||
|
|
||||||
func (result Result) Valid() error {
|
func (result Result) Valid() error {
|
||||||
switch result {
|
switch result {
|
||||||
case NotTested, Accepted, TimeLimitExceeded, MemoryLimitExceeded, CompilationError, SystemFailDuringTesting:
|
case NotTested, Accepted, TimeLimitExceeded, MemoryLimitExceeded, CompilationError, SystemFailDuringTesting:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return lib.ErrBadResult
|
return lib.ServiceError(ErrBadResult, lib.ErrValidationFailed, "bad result")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "git.sch9.ru/new_gate/ms-tester/internal/lib"
|
import (
|
||||||
|
"errors"
|
||||||
|
"git.sch9.ru/new_gate/ms-tester/internal/lib"
|
||||||
|
)
|
||||||
|
|
||||||
type Role int32
|
type Role int32
|
||||||
|
|
||||||
|
@ -35,12 +38,14 @@ func (role Role) AtMost(other Role) bool {
|
||||||
return role <= other
|
return role <= other
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ErrBadRole = errors.New("bad role")
|
||||||
|
|
||||||
func (role Role) Valid() error {
|
func (role Role) Valid() error {
|
||||||
switch role {
|
switch role {
|
||||||
case RoleSpectator, RoleParticipant, RoleModerator, RoleAdmin:
|
case RoleSpectator, RoleParticipant, RoleModerator, RoleAdmin:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return lib.ErrBadRole
|
return lib.ServiceError(ErrBadRole, lib.ErrValidationFailed, "bad role")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (role Role) AsPointer() *Role {
|
func (role Role) AsPointer() *Role {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import "git.sch9.ru/new_gate/ms-tester/internal/lib"
|
import (
|
||||||
|
"errors"
|
||||||
|
"git.sch9.ru/new_gate/ms-tester/internal/lib"
|
||||||
|
)
|
||||||
|
|
||||||
type TestingStrategy int32
|
type TestingStrategy int32
|
||||||
|
|
||||||
|
@ -20,10 +23,12 @@ type TestGroupData struct {
|
||||||
TestAmount int32
|
TestAmount int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ErrBadTestingStrategy = errors.New("bad testing strategy")
|
||||||
|
|
||||||
func (ts TestingStrategy) Valid() error {
|
func (ts TestingStrategy) Valid() error {
|
||||||
switch ts {
|
switch ts {
|
||||||
case EachTestTS, CompleteGroupTS:
|
case EachTestTS, CompleteGroupTS:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return lib.ErrBadTestingStrategy
|
return lib.ServiceError(ErrBadTestingStrategy, lib.ErrValidationFailed, "bad testing strategy")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue