You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
}
The text was updated successfully, but these errors were encountered:
The ev3go/ev3dev package was easy to start with
errors.New
andfmt.Errorf
, but it makes mechanical error handling difficult. So add three (?) error interface types and relevant implementations:Interfaces
Implementation example
The text was updated successfully, but these errors were encountered: