Log item parse error messages
This commit is contained in:
parent
154a4fc904
commit
b2f2cd0cef
@ -71,6 +71,11 @@ func Execute(
|
|||||||
|
|
||||||
makeErrorItem := makeMakeErrItem(source, argv)
|
makeErrorItem := makeMakeErrItem(source, argv)
|
||||||
var logs []string
|
var logs []string
|
||||||
|
addLog := func(format string, args ...any) {
|
||||||
|
msg := fmt.Sprintf(format, args...)
|
||||||
|
log.Print(msg)
|
||||||
|
logs = append(logs, msg)
|
||||||
|
}
|
||||||
|
|
||||||
if source == "" {
|
if source == "" {
|
||||||
err = fmt.Errorf("empty source")
|
err = fmt.Errorf("empty source")
|
||||||
@ -172,15 +177,14 @@ monitor:
|
|||||||
var item Item
|
var item Item
|
||||||
err := json.Unmarshal(data, &item)
|
err := json.Unmarshal(data, &item)
|
||||||
if err != nil || item.Id == "" {
|
if err != nil || item.Id == "" {
|
||||||
msg := fmt.Sprintf("[%s: stdout] %s", source, strings.TrimSpace(string(data)))
|
if err != nil {
|
||||||
log.Print(msg)
|
addLog("[%s: item] parse error: %v", source, err)
|
||||||
logs = append(logs, msg)
|
}
|
||||||
|
addLog("[%s: stdout] %s", source, strings.TrimSpace(string(data)))
|
||||||
parseError = true
|
parseError = true
|
||||||
} else {
|
} else {
|
||||||
if itemIds[item.Id] {
|
if itemIds[item.Id] {
|
||||||
msg := fmt.Sprintf("[%s: item] %s (duplicate)", source, item.Id)
|
addLog("[%s: item] %s (duplicate)", source, item.Id)
|
||||||
log.Print(msg)
|
|
||||||
logs = append(logs, msg)
|
|
||||||
duplicateItem = item.Id
|
duplicateItem = item.Id
|
||||||
cmd.Cancel()
|
cmd.Cancel()
|
||||||
break monitor
|
break monitor
|
||||||
@ -193,16 +197,12 @@ monitor:
|
|||||||
item.Active = true // These fields aren't up to
|
item.Active = true // These fields aren't up to
|
||||||
item.Created = 0 // the action to set and
|
item.Created = 0 // the action to set and
|
||||||
item.Source = source // shouldn't be overrideable
|
item.Source = source // shouldn't be overrideable
|
||||||
msg := fmt.Sprintf("[%s: item] %s", source, item.Id)
|
addLog("[%s: item] %s", source, item.Id)
|
||||||
log.Print(msg)
|
|
||||||
logs = append(logs, msg)
|
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
case data := <-cerr:
|
case data := <-cerr:
|
||||||
msg := fmt.Sprintf("[%s: stderr] %s", source, strings.TrimSpace(string(data)))
|
addLog("[%s: stderr] %s", source, strings.TrimSpace(string(data)))
|
||||||
log.Print(msg)
|
|
||||||
logs = append(logs, msg)
|
|
||||||
|
|
||||||
case <-coutDone:
|
case <-coutDone:
|
||||||
stdoutDone = true
|
stdoutDone = true
|
||||||
|
Loading…
Reference in New Issue
Block a user