fix error log due to slog update

This commit is contained in:
Samuel Lorch 2023-05-15 20:22:30 +02:00
parent dd23131976
commit 3fefb7ca7c
7 changed files with 17 additions and 17 deletions

View file

@ -15,10 +15,10 @@ func (m *ConfigManager) ApplyPendingChanges() error {
for _, fn := range m.applyFunctions {
err := fn(*m.currentConfig, *m.pendingConfig)
if err != nil {
slog.Error("Applying Pending Changes", err)
slog.Error("Applying Pending Changes", "err", err)
err2 := revertToCurrent(m)
if err2 != nil {
slog.Error("Reverting Error", err2)
slog.Error("Reverting Error", "err", err2)
return fmt.Errorf("Apply Error %w; Reverting Error %w", err, err2)
}
return err

View file

@ -29,7 +29,7 @@ func NewHandler(maxRequestSize int64) *Handler {
func (h *Handler) HandleRequest(ctx context.Context, s *session.Session, r io.Reader, w io.Writer) error {
defer func() {
if r := recover(); r != nil {
slog.Error("Recovered Panic Handling JSONRPC Request", fmt.Errorf("%v", r), "stack", debug.Stack())
slog.Error("Recovered Panic Handling JSONRPC Request", "err", fmt.Errorf("%v", r), "stack", debug.Stack())
}
}()
var req request
@ -81,7 +81,7 @@ func (h *Handler) HandleRequest(ctx context.Context, s *session.Session, r io.Re
defer func() {
if r := recover(); r != nil {
slog.Error("Recovered Panic Executing API Method", fmt.Errorf("%v", r), "method", req.Method, "params", fmt.Sprintf("%+v", params[2]), "id", req.ID, "stack", debug.Stack())
slog.Error("Recovered Panic Executing API Method", "err", fmt.Errorf("%v", r), "method", req.Method, "params", fmt.Sprintf("%+v", params[2]), "id", req.ID, "stack", debug.Stack())
respondError(w, req.ID, ErrInternalError, fmt.Errorf("%v", r))
}
}()
@ -90,7 +90,7 @@ func (h *Handler) HandleRequest(ctx context.Context, s *session.Session, r io.Re
if !res[1].IsNil() {
reqerr := res[1].Interface().(error)
slog.Error("API Method", reqerr, "method", req.Method, "id", req.ID, "params", fmt.Sprintf("%+v", params[2]))
slog.Error("API Method", "err", reqerr, "method", req.Method, "id", req.ID, "params", fmt.Sprintf("%+v", params[2]))
respondError(w, req.ID, ErrInternalError, reqerr)
return nil
}

View file

@ -20,7 +20,7 @@ func HandleAPI(w http.ResponseWriter, r *http.Request) {
defer func() {
if r := recover(); r != nil {
slog.Error("Recovered Panic Handling HTTP API Request", fmt.Errorf("%v", r), "stack", debug.Stack())
slog.Error("Recovered Panic Handling HTTP API Request", "err", fmt.Errorf("%v", r), "stack", debug.Stack())
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
@ -30,6 +30,6 @@ func HandleAPI(w http.ResponseWriter, r *http.Request) {
err := apiHandler.HandleRequest(ctx, s, r.Body, w)
if err != nil {
slog.Error("Handling HTTP API Request", err)
slog.Error("Handling HTTP API Request", "err", err)
}
}

View file

@ -39,7 +39,7 @@ func StartWebserver(_configManager *config.ConfigManager, _apiHandler *jsonrpc.H
go func() {
if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
slog.Error("Webserver error", err)
slog.Error("Webserver error", "err", err)
}
slog.Info("Webserver Stopped")
}()

View file

@ -25,7 +25,7 @@ func HandleLogin(w http.ResponseWriter, r *http.Request) {
var req LoginRequest
err = json.Unmarshal(buf, &req)
if err != nil {
slog.Error("Unmarshal", err)
slog.Error("Unmarshal", "err", err)
return
}
err = auth.AuthenticateUser(configManager.GetCurrentConfig(), req.Username, req.Password)

View file

@ -24,7 +24,7 @@ func HandleWebsocketAPI(w http.ResponseWriter, r *http.Request) {
defer cancel()
c, err := websocket.Accept(w, r, nil)
if err != nil {
slog.Error("Accepting Websocket Connection", err)
slog.Error("Accepting Websocket Connection", "err", err)
return
}
defer c.Close(websocket.StatusInternalError, "Unexpected Closing")
@ -38,14 +38,14 @@ func HandleWebsocketAPI(w http.ResponseWriter, r *http.Request) {
cancel()
return
} else if err != nil {
slog.Error("API Websocket Closed Unexpectedly", err)
slog.Error("API Websocket Closed Unexpectedly", "err", err)
cancel()
}
go func() {
defer func() {
if r := recover(); r != nil {
slog.Error("Recovered Panic Handling Websocket API Request", fmt.Errorf("%v", r), "stack", debug.Stack())
slog.Error("Recovered Panic Handling Websocket API Request", "err", fmt.Errorf("%v", r), "stack", debug.Stack())
return
}
}()
@ -54,7 +54,7 @@ func HandleWebsocketAPI(w http.ResponseWriter, r *http.Request) {
err := apiHandler.HandleRequest(ctx, s, bytes.NewReader(m), w)
if err != nil {
slog.Error("Handling Websocket API Request", err)
slog.Error("Handling Websocket API Request", "err", err)
}
}()
}

View file

@ -32,7 +32,7 @@ func main() {
dbusConn, err := dbus.ConnectSystemBus()
if err != nil {
slog.Error("Connecting to DBus", err)
slog.Error("Connecting to DBus", "err", err)
// os.Exit(1)
}
defer dbusConn.Close()
@ -55,7 +55,7 @@ func main() {
err = configManager.LoadCurrentConfigFromDisk()
if err != nil {
slog.Error("Loading Current Config", err)
slog.Error("Loading Current Config", "err", err)
os.Exit(1)
}
@ -68,7 +68,7 @@ func main() {
}
err = configManager.DiscardPendingConfig()
if err != nil {
slog.Error("Discarding Pending Config", err)
slog.Error("Discarding Pending Config", "err", err)
os.Exit(1)
}
}
@ -77,7 +77,7 @@ func main() {
slog.Info("Applying Config...")
err := configManager.ApplyPendingChanges()
if err != nil {
slog.Error("Applying Pending Config", err)
slog.Error("Applying Pending Config", "err", err)
os.Exit(1)
}
slog.Info("Config Applied, Exiting...")