Skip to content

Commit

Permalink
Use %w on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Yorick Smilda committed Jan 31, 2023
1 parent 489d4c8 commit 662831e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
22 changes: 11 additions & 11 deletions internal/model/end-device-frequency-plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,57 +35,57 @@ func (f FrequencyPlanEndDevice) Parse(file string) (Definition, error) {
func (f FrequencyPlanEndDevice) Validate() error {
for i, subBand := range f.SubBands {
if err := subBand.Validate(); err != nil {
return fmt.Errorf("SubBand %d: %s", i, err)
return fmt.Errorf("SubBand %d: %w", i, err)
}
}
for i, channel := range f.Channels {
if err := channel.Validate(); err != nil {
return fmt.Errorf("Channel %d: %s", i, err)
return fmt.Errorf("Channel %d: %w", i, err)
}
}
if f.LoRaStandardChannel != nil {
if err := f.LoRaStandardChannel.Validate(); err != nil {
return fmt.Errorf("LoRaStandardChannel: %s", err)
return fmt.Errorf("LoRaStandardChannel: %w", err)
}
}
if f.FSKChannel != nil {
if err := f.FSKChannel.Validate(); err != nil {
return fmt.Errorf("FSKChannel: %s", err)
return fmt.Errorf("FSKChannel: %w", err)
}
}
if f.TimeOffAir != nil {
if err := f.TimeOffAir.Validate(); err != nil {
return fmt.Errorf("TimeOffAir: %s", err)
return fmt.Errorf("TimeOffAir: %w", err)
}
}
if f.DwellTime != nil {
if err := f.DwellTime.Validate(); err != nil {
return fmt.Errorf("DwellTime: %s", err)
return fmt.Errorf("DwellTime: %w", err)
}
}
if f.ListenBeforeTalk != nil {
if err := f.ListenBeforeTalk.Validate(); err != nil {
return fmt.Errorf("ListenBeforeTalk: %s", err)
return fmt.Errorf("ListenBeforeTalk: %w", err)
}
}
if f.PingSlot != nil {
if err := f.PingSlot.Validate(); err != nil {
return fmt.Errorf("PingSlot: %s", err)
return fmt.Errorf("PingSlot: %w", err)
}
}
if f.PingSlotDefaultDataRate != nil {
if err := validateDataRate(*f.PingSlotDefaultDataRate); err != nil {
return fmt.Errorf("PingSlotDefaultDataRate: %s", err)
return fmt.Errorf("PingSlotDefaultDataRate: %w", err)
}
}
if f.RX2Channel != nil {
if err := f.RX2Channel.Validate(); err != nil {
return fmt.Errorf("RX2Channel: %s", err)
return fmt.Errorf("RX2Channel: %w", err)
}
}
if f.RX2DefaultDataRate != nil {
if err := validateDataRate(*f.RX2DefaultDataRate); err != nil {
return fmt.Errorf("RX2DefaultDataRate: %s", err)
return fmt.Errorf("RX2DefaultDataRate: %w", err)
}
}
return nil
Expand Down
14 changes: 7 additions & 7 deletions internal/model/gateway-frequency-plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,37 @@ func (f FrequencyPlanGateway) Parse(file string) (Definition, error) {
func (f FrequencyPlanGateway) Validate() error {
for i, subBand := range f.SubBands {
if err := subBand.Validate(); err != nil {
return fmt.Errorf("SubBand %d: %s", i, err)
return fmt.Errorf("SubBand %d: %w", i, err)
}
}
for i, channel := range f.Channels {
if err := channel.Validate(); err != nil {
return fmt.Errorf("Channel %d: %s", i, err)
return fmt.Errorf("Channel %d: %w", i, err)
}
}
if f.LoRaStandardChannel != nil {
if err := f.LoRaStandardChannel.Validate(); err != nil {
return fmt.Errorf("LoRaStandardChannel: %s", err)
return fmt.Errorf("LoRaStandardChannel: %w", err)
}
}
if f.FSKChannel != nil {
if err := f.FSKChannel.Validate(); err != nil {
return fmt.Errorf("FSKChannel: %s", err)
return fmt.Errorf("FSKChannel: %w", err)
}
}
if f.TimeOffAir != nil {
if err := f.TimeOffAir.Validate(); err != nil {
return fmt.Errorf("TimeOffAir: %s", err)
return fmt.Errorf("TimeOffAir: %w", err)
}
}
if f.DwellTime != nil {
if err := f.DwellTime.Validate(); err != nil {
return fmt.Errorf("DwellTime: %s", err)
return fmt.Errorf("DwellTime: %w", err)
}
}
for i, radio := range f.Radios {
if err := radio.Validate(); err != nil {
return fmt.Errorf("Radio %d: %s", i, err)
return fmt.Errorf("Radio %d: %w", i, err)
}
}
return nil
Expand Down

0 comments on commit 662831e

Please sign in to comment.