Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Logs now shows complete error with fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Alrim42 committed Aug 9, 2017
1 parent c1afeb2 commit e5d973b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 57 deletions.
4 changes: 2 additions & 2 deletions cmd/snaptel/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func createTaskUsingTaskManifest(ctx *cli.Context) error {

if r.Err != nil {
errors := strings.Split(r.Err.Error(), " -- ")
errString := "Error creating task:"
errString := "Error creating task: "
for _, err := range errors {
errString += fmt.Sprintf("%v\n", err)
}
Expand Down Expand Up @@ -448,7 +448,7 @@ func createTaskUsingWFManifest(ctx *cli.Context) error {
r := pClient.CreateTask(t.Schedule, wf, t.Name, t.Deadline, !ctx.IsSet("no-start"), t.MaxFailures)
if r.Err != nil {
errors := strings.Split(r.Err.Error(), " -- ")
errString := "Error creating task:"
errString := "Error creating task: "
for _, err := range errors {
errString += fmt.Sprintf("%v\n", err)
}
Expand Down
8 changes: 8 additions & 0 deletions core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,15 @@ func CreateTaskFromContent(body io.ReadCloser,
var errMsg string
for _, e := range errs.Errors() {
errMsg = errMsg + e.Error() + " -- "

log.WithFields(log.Fields{
"_file": "core/task.go",
"_function": "CreateTaskFromContent",
"_error": e.Error(),
"_fields": e.Fields(),
}).Error("error creating task")
}

return nil, errors.New(errMsg[:len(errMsg)-4])
}
return task, nil
Expand Down
81 changes: 26 additions & 55 deletions core/task_medium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func TestUnmarshalBodyTask(t *testing.T) {
Convey("Bad JSON file", t, func() {
err := createTaskFile(YAML_FILE, YAML_FILE_CONTENT)
So(err, ShouldBeNil)
defer deleteTaskFile(YAML_FILE)

var tr TaskReq1
file, err := os.Open(YAML_FILE)
Expand All @@ -182,14 +183,12 @@ func TestUnmarshalBodyTask(t *testing.T) {
So(code, ShouldEqual, 400)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "invalid character '-' in numeric literal")

err = deleteTaskFile(YAML_FILE)
So(err, ShouldBeNil)
})

Convey("Proper JSON file", t, func() {
err := createTaskFile(JSON_FILE, JSON_FILE_CONTENT)
So(err, ShouldBeNil)
defer deleteTaskFile(JSON_FILE)

var tr TaskReq1
file, err := os.Open(JSON_FILE)
Expand All @@ -198,9 +197,6 @@ func TestUnmarshalBodyTask(t *testing.T) {
code, err := UnmarshalBody(&tr, file)
So(code, ShouldEqual, 0)
So(err, ShouldBeNil)

err = deleteTaskFile(JSON_FILE)
So(err, ShouldBeNil)
})
}

Expand All @@ -219,6 +215,7 @@ func TestCreateTaskRequest(t *testing.T) {
Convey("Bad JSON file", t, func() {
err := createTaskFile(YAML_FILE, YAML_FILE_CONTENT)
So(err, ShouldBeNil)
defer deleteTaskFile(YAML_FILE)

file, err := os.Open(YAML_FILE)
So(file, ShouldNotBeNil)
Expand All @@ -227,14 +224,12 @@ func TestCreateTaskRequest(t *testing.T) {
So(task, ShouldBeNil)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "invalid character '-' in numeric literal")

err = deleteTaskFile(YAML_FILE)
So(err, ShouldBeNil)
})

Convey("Proper JSON file", t, func() {
err := createTaskFile(JSON_FILE, JSON_FILE_CONTENT)
So(err, ShouldBeNil)
defer deleteTaskFile(JSON_FILE)

file, err := os.Open(JSON_FILE)
So(file, ShouldNotBeNil)
Expand All @@ -249,9 +244,6 @@ func TestCreateTaskRequest(t *testing.T) {
So(task.Schedule.StartTimestamp, ShouldBeNil)
So(task.Schedule.StopTimestamp, ShouldBeNil)
So(task.Start, ShouldEqual, false)

err = deleteTaskFile(JSON_FILE)
So(err, ShouldBeNil)
})
}

Expand All @@ -271,6 +263,7 @@ func TestCreateTaskFromContent(t *testing.T) {
Convey("Bad JSON file", t, func() {
err := createTaskFile(YAML_FILE, YAML_FILE_CONTENT)
So(err, ShouldBeNil)
defer deleteTaskFile(YAML_FILE)

file, err := os.Open(YAML_FILE)
So(file, ShouldNotBeNil)
Expand All @@ -280,58 +273,36 @@ func TestCreateTaskFromContent(t *testing.T) {
So(task, ShouldBeNil)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "invalid character '-' in numeric literal")

err = deleteTaskFile(YAML_FILE)
So(err, ShouldBeNil)
})

Convey("Proper JSON file no workflow routine", t, func() {
err := createTaskFile(JSON_FILE, JSON_FILE_CONTENT)
So(err, ShouldBeNil)

file, err := os.Open(JSON_FILE)
So(file, ShouldNotBeNil)
So(err, ShouldBeNil)
autoStart := true
task, err := CreateTaskFromContent(file, &autoStart, nil)
So(task, ShouldBeNil)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "Missing workflow creation routine")

err = deleteTaskFile(JSON_FILE)
So(err, ShouldBeNil)
})

Convey("Proper JSON file erroring routine", t, func() {
err := createTaskFile(JSON_FILE, JSON_FILE_CONTENT)
So(err, ShouldBeNil)

file, err := os.Open(JSON_FILE)
So(file, ShouldNotBeNil)
So(err, ShouldBeNil)
autoStart := true
task, err := CreateTaskFromContent(file, &autoStart, koRoutine)
So(task, ShouldBeNil)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "Dummy error")

err = deleteTaskFile(JSON_FILE)
So(err, ShouldBeNil)
})

Convey("Proper JSON file proper routine", t, func() {
Convey("Use proper JSON file", t, func() {
err := createTaskFile(JSON_FILE, JSON_FILE_CONTENT)
So(err, ShouldBeNil)
defer deleteTaskFile(JSON_FILE)

file, err := os.Open(JSON_FILE)
So(file, ShouldNotBeNil)
So(err, ShouldBeNil)
autoStart := true
task, err := CreateTaskFromContent(file, &autoStart, okRoutine)
So(task, ShouldBeNil)
So(err, ShouldBeNil)

err = deleteTaskFile(JSON_FILE)
So(err, ShouldBeNil)
Convey("Proper JSON file - no workflow routine", func() {
task, err := CreateTaskFromContent(file, &autoStart, nil)
So(task, ShouldBeNil)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "Missing workflow creation routine")
})

Convey("Proper JSON file - erroring routine", func() {
task, err := CreateTaskFromContent(file, &autoStart, koRoutine)
So(task, ShouldBeNil)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "Dummy error")
})

Convey("Proper JSON file - proper routine", func() {
task, err := CreateTaskFromContent(file, &autoStart, okRoutine)
So(task, ShouldBeNil)
So(err, ShouldBeNil)
})
})
}

0 comments on commit e5d973b

Please sign in to comment.