-
-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
The ev3go/ev3dev package was easy to start with errors.New and fmt.Errorf, but it makes mechanical error handling difficult. So add three (?) error interface types and relevant implementations:
Interfaces
type ValidValuer interface {
ValidValues() []string
}
type ValidRanger interface {
ValidRange() (min, max int)
}
type ValidDurationRanger interface {
ValidDurationRange() (min, max time.Duration)
}
Implementation example
type NegativeDuration time.Duration
func (d NegativeDuration) Error() string {
if d >= 0 {
panic(fmt.Sprintf("ev3dev: invalid negative duration: %v", d))
}
return fmt.Sprintf("ev3dev: invalid duration: %v (must be positive)", time.Duration(d))
}
func (d NegativeDuration) ValidDurationRange() (min, max time.Duration) {
if d >= 0 {
panic(fmt.Sprintf("ev3dev: invalid negative duration: %v", d))
}
return 0, MaxInt64
}
Metadata
Metadata
Assignees
Labels
No labels