Skip to content

Commit

Permalink
add some error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousm4x committed Feb 1, 2023
1 parent ed285f5 commit 482a988
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions backend/networking/shutdown.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package networking

import (
"bytes"
"fmt"
"os/exec"
"runtime"
Expand Down Expand Up @@ -28,9 +29,14 @@ func ShutdownDevice(device *models.Record) error {
}

cmd := exec.Command(shell, shell_arg, shutdown_cmd)
var stderr bytes.Buffer
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return err
}
if stderr.Len() > 0 {
return fmt.Errorf("%s", stderr.String())
}

// check state every second for 2 min
start := time.Now()
Expand Down
3 changes: 3 additions & 0 deletions backend/pb/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/models"
"github.com/seriousm4x/upsnap/logger"
"github.com/seriousm4x/upsnap/networking"
)

Expand All @@ -23,6 +24,7 @@ func HandlerWake(c echo.Context) error {
record.Set("status", "pending")
App.Dao().SaveRecord(record)
if err := networking.WakeDevice(record); err != nil {
logger.Error.Println(err)
record.Set("status", "offline")
} else {
record.Set("status", "online")
Expand All @@ -41,6 +43,7 @@ func HandlerShutdown(c echo.Context) error {
record.Set("status", "pending")
App.Dao().SaveRecord(record)
if err := networking.ShutdownDevice(record); err != nil {
logger.Error.Println(err)
record.Set("status", "online")
} else {
record.Set("status", "offline")
Expand Down
3 changes: 1 addition & 2 deletions backend/pb/pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pb

import (
"io/fs"
"log"
"net/http"
"os"

Expand Down Expand Up @@ -112,7 +111,7 @@ func StartPocketBase(distDirFS fs.FS) {

// start pocketbase
if err := App.Start(); err != nil {
log.Fatal(err)
logger.Error.Fatalln(err)
}
}

Expand Down

0 comments on commit 482a988

Please sign in to comment.