Skip to content

Commit

Permalink
wrap errors in database hooks
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Nov 19, 2023
1 parent d2b507e commit 2f7de40
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions hscontrol/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (n *Node) BeforeSave(tx *gorm.DB) (err error) {

hi, err := json.Marshal(n.Hostinfo)
if err != nil {
return err
return fmt.Errorf("failed to marshal Hostinfo to store in db: %w", err)
}
n.HostinfoDatabaseField = string(hi)

Expand All @@ -291,27 +291,27 @@ func (n *Node) BeforeSave(tx *gorm.DB) (err error) {
func (n *Node) AfterFind(tx *gorm.DB) (err error) {
var machineKey key.MachinePublic
if err := machineKey.UnmarshalText([]byte(n.MachineKeyDatabaseField)); err != nil {
return err
return fmt.Errorf("failed to unmarshal machine key from db: %w", err)
}
n.MachineKey = machineKey

var nodeKey key.NodePublic
if err := nodeKey.UnmarshalText([]byte(n.NodeKeyDatabaseField)); err != nil {
return err
return fmt.Errorf("failed to unmarshal node key from db: %w", err)
}
n.NodeKey = nodeKey

var discoKey key.DiscoPublic
if err := discoKey.UnmarshalText([]byte(n.DiscoKeyDatabaseField)); err != nil {
return err
return fmt.Errorf("failed to unmarshal disco key from db: %w", err)
}
n.DiscoKey = discoKey

var endpoints []netip.AddrPort
for _, ep := range n.EndpointsDatabaseField {
addrPort, err := netip.ParseAddrPort(ep)
if err != nil {
return err
return fmt.Errorf("failed to parse endpoint from db: %w", err)
}

endpoints = append(endpoints, addrPort)
Expand All @@ -320,7 +320,7 @@ func (n *Node) AfterFind(tx *gorm.DB) (err error) {

var hi tailcfg.Hostinfo
if err := json.Unmarshal([]byte(n.HostinfoDatabaseField), &hi); err != nil {
return err
return fmt.Errorf("failed to unmarshal Hostinfo from db: %w", err)
}
n.Hostinfo = &hi

Expand Down

0 comments on commit 2f7de40

Please sign in to comment.