Skip to content

Commit

Permalink
feat(common.FirewallError): add AsError
Browse files Browse the repository at this point in the history
  • Loading branch information
mjholub committed Feb 16, 2024
1 parent 0d9c456 commit 6966e3b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion daemon/firewall/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ func (e *FirewallError) Error() string {
return fmt.Sprintf("IPv4 error: %v, IPv6 error: %v", e.Err4, e.Err6)
}

// AsError returns combined standard error for both IPv4 and IPv6
// Only the non-nil errors are formatted into the error
func (e *FirewallError) AsError() error {
switch {
case e.Err4 == nil && e.Err6 != nil:
return e.Err6
case e.Err4 != nil && e.Err6 == nil:
return e.Err4
case e == &FirewallError{} || e == nil:
return nil
default:
return fmt.Errorf("%v", e.Error())
}
}

// HasError simplifies error handling of the FirewallError type.
func (e *FirewallError) HasError() bool {
return e.Err4 != nil || e.Err6 != nil
Expand All @@ -60,6 +75,8 @@ func (s *stopChecker) exit() <-chan bool {
s.RLock()
defer s.RUnlock()
return s.ch
}

// ErrorsChan returns the channel where the errors are sent to.
func (c *Common) ErrorsChan() <-chan string {
return c.ErrChan
Expand Down Expand Up @@ -111,7 +128,6 @@ func (c *Common) SetQueueNum(qNum *int) {
if qNum != nil {
c.QueueNum = uint16(*qNum)
}

}

// IsRunning returns if the firewall is running or not.
Expand Down

0 comments on commit 6966e3b

Please sign in to comment.