Skip to content

Commit

Permalink
fix(plugin): log JSON decoding errors for lines that appear to be JSON (
Browse files Browse the repository at this point in the history
#481)

Previously, anything that failed to decode would silently be converted
to a text line. With this change, a line that fails to decode but looks
like it is JSON will result in a warning.
  • Loading branch information
alecthomas authored Oct 11, 2023
1 parent 1ad1869 commit 82c7277
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 4 additions & 0 deletions backend/common/log/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func JSONStreamer(r io.Reader, log *Logger, defaultLevel Level) error {
line := scan.Bytes()
err := json.Unmarshal(line, &entry)
if err != nil {
if len(line) > 0 && line[0] == '{' {
log.Warnf("Invalid JSON log entry: %s", err)
log.Warnf("Entry: %s", line)
}
log.Log(Entry{Level: defaultLevel, Time: time.Now(), Message: string(line)})
} else {
if entry.Error != "" {
Expand Down
3 changes: 1 addition & 2 deletions backend/common/plugin/spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package plugin

import (
"context"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -156,7 +155,7 @@ func Spawn[Client PingableClient](
}()

// Write the PID file.
err = ioutil.WriteFile(pidFile, []byte(strconv.Itoa(cmd.Process.Pid)), 0600)
err = os.WriteFile(pidFile, []byte(strconv.Itoa(cmd.Process.Pid)), 0600)
if err != nil {
return nil, nil, errors.WithStack(err)
}
Expand Down

0 comments on commit 82c7277

Please sign in to comment.