Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: context errors not captured #286

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 25 additions & 35 deletions internal/inputs/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,53 +130,43 @@ func commandRun(dataStore *[]interface{}, yml *load.Config, command load.Command
return
}

if err != nil {
contextError := ctx.Err()

if err != nil || contextError != nil {
contextErrorStr := ""
if contextError != nil {
contextErrorStr = contextError.Error()
}

load.Logrus.WithFields(logrus.Fields{
"exec": command.Run,
"err": err,
"context_err": contextErrorStr,
"suggestion": "if you are handling this error case, ignore",
}).Debug("command: failed")

if command.HideErrorExec {
load.Logrus.WithFields(logrus.Fields{
"exec": command.Run,
"err": err,
"suggestion": "if you are handling this error case, ignore",
}).Debug("command: failed")
errorSample := map[string]interface{}{
"error": err,
"error_msg": string(output),
"error_exec": "COMMAND HIDDEN!",
"error": err,
"error_msg": string(output),
"context_error": contextErrorStr,
"error_exec": "COMMAND HIDDEN!",
}
*dataStore = append(*dataStore, errorSample)
return
}
load.Logrus.WithFields(logrus.Fields{
"exec": command.Run,
"err": err,
"suggestion": "if you are handling this error case, ignore",
}).Debug("command: failed")

errorSample := map[string]interface{}{
"error": err,
"error_msg": string(output),
"error_exec": command.Run,
"error": err,
"error_msg": string(output),
"context_error": contextErrorStr,
"error_exec": command.Run,
}
*dataStore = append(*dataStore, errorSample)
return
}

err = ctx.Err()
if err != nil {
if err == context.DeadlineExceeded {
load.Logrus.WithFields(logrus.Fields{
"exec": command.Run,
"err": err,
}).Debug("command: timed out")
} else {
load.Logrus.WithFields(logrus.Fields{
"exec": command.Run,
"err": err,
}).Debug("command: execution failed")
}
errorSample := map[string]interface{}{
"error": err,
}
*dataStore = append(*dataStore, errorSample)
} else if len(output) > 0 {
if len(output) > 0 {
if command.SplitOutput != "" {
splitOutput(dataStore, string(output), command, startTime)
} else {
Expand Down