Skip to content

all: purge opaque errors from suite #24

Description

@kortschak

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
}

Activity

  1. kortschak commented on Apr 11, 2017

    @kortschak
    MemberAuthor

    Use of fmt.Errorf in:

    • led.go
    • buttons.go
    • ev3dev.go
    • lego_port.go
    • sensor.go
    • speaker.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions