error handling enhancements
This commit is contained in:
parent
ee914fade3
commit
59f6cda4d6
|
@ -5,11 +5,17 @@ import (
|
|||
"os/exec"
|
||||
)
|
||||
|
||||
func getErrorMessage(err *exec.ExitError) string {
|
||||
stderr := string(err.Stderr)
|
||||
if len(stderr) == 0 {
|
||||
return err.Error()
|
||||
} else {
|
||||
return fmt.Sprintf("%.200s", stderr)
|
||||
func getErrorMessage(err error) string {
|
||||
|
||||
exitErr, ok := err.(*exec.ExitError)
|
||||
message := err.Error()
|
||||
|
||||
if ok {
|
||||
stderr := string(exitErr.Stderr)
|
||||
if len(stderr) != 0 {
|
||||
message = fmt.Sprintf("%.200s", stderr)
|
||||
}
|
||||
}
|
||||
|
||||
return message
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package data
|
|||
|
||||
import (
|
||||
"github.com/sqshq/sampler/config"
|
||||
"os/exec"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -57,7 +56,7 @@ func (s *Sampler) sample(item Item, options config.Options) {
|
|||
} else {
|
||||
s.consumer.AlertChannel <- &Alert{
|
||||
Title: "SAMPLING FAILURE",
|
||||
Text: getErrorMessage(err.(*exec.ExitError)),
|
||||
Text: getErrorMessage(err),
|
||||
Color: item.Color,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ func (t *Trigger) evaluate(sample *Sample) bool {
|
|||
if err != nil {
|
||||
t.consumer.AlertChannel <- &Alert{
|
||||
Title: "TRIGGER CONDITION FAILURE",
|
||||
Text: getErrorMessage(err.(*exec.ExitError)),
|
||||
Text: getErrorMessage(err),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue