Skip to content
Snippets Groups Projects
Commit 017846ea authored by Julian Kornberger's avatar Julian Kornberger Committed by takt
Browse files

Wrap errors (#161)

Package errors provides simple error handling primitives.
Read more on https://github.com/pkg/errors
parent 857732ea
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/filter" "github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
) )
...@@ -144,7 +145,7 @@ func (nw *NetlinkWriter) addKernel(pfx bnet.Prefix) error { ...@@ -144,7 +145,7 @@ func (nw *NetlinkWriter) addKernel(pfx bnet.Prefix) error {
err = netlink.RouteAdd(route) err = netlink.RouteAdd(route)
if err != nil { if err != nil {
log.Errorf("Error while adding route: %v", err) log.Errorf("Error while adding route: %v", err)
return fmt.Errorf("Error while adding route: %v", err) return errors.Wrap(err, "Error while adding route")
} }
return nil return nil
...@@ -163,7 +164,7 @@ func (nw *NetlinkWriter) removeKernel(pfx bnet.Prefix, paths []*route.Path) erro ...@@ -163,7 +164,7 @@ func (nw *NetlinkWriter) removeKernel(pfx bnet.Prefix, paths []*route.Path) erro
err = netlink.RouteDel(route) err = netlink.RouteDel(route)
if err != nil { if err != nil {
return fmt.Errorf("Error while removing route: %v", err) return errors.Wrap(err, "Error while removing route")
} }
return nil return nil
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable" "github.com/bio-routing/bio-rd/routingtable"
"github.com/bio-routing/bio-rd/routingtable/filter" "github.com/bio-routing/bio-rd/routingtable/filter"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
...@@ -98,7 +99,7 @@ func (a *AdjRIBOut) AddPath(pfx bnet.Prefix, p *route.Path) error { ...@@ -98,7 +99,7 @@ func (a *AdjRIBOut) AddPath(pfx bnet.Prefix, p *route.Path) error {
if a.addPathTX { if a.addPathTX {
pathID, err := a.pathIDManager.addPath(p) pathID, err := a.pathIDManager.addPath(p)
if err != nil { if err != nil {
return fmt.Errorf("Unable to get path ID: %v", err) return errors.Wrap(err, "Unable to get path ID")
} }
p.BGPPath.PathIdentifier = pathID p.BGPPath.PathIdentifier = pathID
......
...@@ -3,7 +3,8 @@ package decode ...@@ -3,7 +3,8 @@ package decode
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"fmt"
"github.com/pkg/errors"
) )
// Decode reads fields from a buffer // Decode reads fields from a buffer
...@@ -12,7 +13,7 @@ func Decode(buf *bytes.Buffer, fields []interface{}) error { ...@@ -12,7 +13,7 @@ func Decode(buf *bytes.Buffer, fields []interface{}) error {
for _, field := range fields { for _, field := range fields {
err = binary.Read(buf, binary.BigEndian, field) err = binary.Read(buf, binary.BigEndian, field)
if err != nil { if err != nil {
return fmt.Errorf("Unable to read from buffer: %v", err) return errors.Wrap(err, "Unable to read from buffer")
} }
} }
return nil return nil
......
...@@ -3,7 +3,8 @@ package decoder ...@@ -3,7 +3,8 @@ package decoder
import ( import (
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"fmt"
"github.com/pkg/errors"
) )
// Decode decodes network packets // Decode decodes network packets
...@@ -12,7 +13,7 @@ func Decode(buf *bytes.Buffer, fields []interface{}) error { ...@@ -12,7 +13,7 @@ func Decode(buf *bytes.Buffer, fields []interface{}) error {
for _, field := range fields { for _, field := range fields {
err = binary.Read(buf, binary.BigEndian, field) err = binary.Read(buf, binary.BigEndian, field)
if err != nil { if err != nil {
return fmt.Errorf("Unable to read from buffer: %v", err) return errors.Wrap(err, "Unable to read from buffer")
} }
} }
return nil return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment