Improve error handling

This commit is contained in:
Elara 2022-04-22 18:43:13 -07:00
parent 7fd9af3288
commit d4a8a9f8c9

View File

@ -37,8 +37,9 @@ import (
"go.arsenm.dev/itd/api" "go.arsenm.dev/itd/api"
) )
// This type signifies an unneeded valie. // This type signifies an unneeded value.
// A struct{} is used as it takes no space in memory. // A struct{} is used as it takes no space in memory.
// This exists for readability purposes
type none = struct{} type none = struct{}
var ( var (
@ -100,14 +101,20 @@ func startSocket(dev *infinitime.Device) error {
dev: dev, dev: dev,
srv: srv, srv: srv,
} }
srv.Register(itdAPI, "") err = srv.Register(itdAPI, "")
if err != nil {
return err
}
fsAPI := &FS{ fsAPI := &FS{
dev: dev, dev: dev,
fs: fs, fs: fs,
srv: srv, srv: srv,
} }
srv.Register(fsAPI, "") err = srv.Register(fsAPI, "")
if err != nil {
return err
}
go srv.ServeListener("unix", ln) go srv.ServeListener("unix", ln)
@ -150,6 +157,7 @@ func (i *ITD) WatchHeartRate(ctx context.Context, _ none, out *string) error {
default: default:
data, err := msgpack.Marshal(heartRate) data, err := msgpack.Marshal(heartRate)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Error encoding heart rate")
continue continue
} }
@ -191,6 +199,7 @@ func (i *ITD) WatchBatteryLevel(ctx context.Context, _ none, out *string) error
default: default:
data, err := msgpack.Marshal(battLevel) data, err := msgpack.Marshal(battLevel)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Error encoding battery level")
continue continue
} }
@ -232,6 +241,7 @@ func (i *ITD) WatchMotion(ctx context.Context, _ none, out *string) error {
default: default:
data, err := msgpack.Marshal(motionVals) data, err := msgpack.Marshal(motionVals)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Error encoding motion values")
continue continue
} }
@ -273,6 +283,7 @@ func (i *ITD) WatchStepCount(ctx context.Context, _ none, out *string) error {
default: default:
data, err := msgpack.Marshal(stepCount) data, err := msgpack.Marshal(stepCount)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Error encoding step count")
continue continue
} }
@ -361,6 +372,7 @@ func (i *ITD) FirmwareUpgrade(ctx context.Context, reqData api.FwUpgradeData, ou
for event := range i.dev.DFU.Progress() { for event := range i.dev.DFU.Progress() {
data, err := msgpack.Marshal(event) data, err := msgpack.Marshal(event)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Error encoding DFU progress event")
continue continue
} }
@ -378,6 +390,7 @@ func (i *ITD) FirmwareUpgrade(ctx context.Context, reqData api.FwUpgradeData, ou
// Start DFU // Start DFU
err := i.dev.DFU.Start() err := i.dev.DFU.Start()
if err != nil { if err != nil {
log.Error().Err(err).Msg("Error while upgrading firmware")
firmwareUpdating = false firmwareUpdating = false
return return
} }
@ -478,6 +491,7 @@ func (fs *FS) Upload(ctx context.Context, paths [2]string, out *string) error {
Sent: sent, Sent: sent,
}) })
if err != nil { if err != nil {
log.Error().Err(err).Msg("Error encoding filesystem transfer progress event")
continue continue
} }
@ -521,6 +535,7 @@ func (fs *FS) Download(ctx context.Context, paths [2]string, out *string) error
Sent: rcvd, Sent: rcvd,
}) })
if err != nil { if err != nil {
log.Error().Err(err).Msg("Error encoding filesystem transfer progress event")
continue continue
} }