Skip to content

Commit

Permalink
Remove ErrLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
workanator committed Sep 27, 2017
1 parent 32f30d6 commit 5e5dbfe
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 120 deletions.
28 changes: 0 additions & 28 deletions errors/location.go

This file was deleted.

45 changes: 0 additions & 45 deletions errors/location_test.go

This file was deleted.

4 changes: 1 addition & 3 deletions run.go
Expand Up @@ -2,8 +2,6 @@ package floc

import "gopkg.in/workanator/go-floc.v2/errors"

const locRun = "Run"

// Run creates a new Context and Control and runs the flow.
func Run(job Job) (result Result, data interface{}, err error) {
// Create context and control
Expand Down Expand Up @@ -34,7 +32,7 @@ func RunWith(ctx Context, ctrl Control, job Job) (result Result, data interface{

// Return Failed if unhandled error left after the execution.
if unhandledErr != nil {
return Failed, nil, errors.NewErrLocation(unhandledErr, locRun)
return Failed, nil, unhandledErr
}

return None, nil, nil
Expand Down
4 changes: 1 addition & 3 deletions run/background.go
Expand Up @@ -4,8 +4,6 @@ import (
"gopkg.in/workanator/go-floc.v2"
)

const locBackground = "Background"

/*
Background starts the job in it's own goroutine. The function does not
track the lifecycle of the job started and does no synchronization with it
Expand Down Expand Up @@ -43,7 +41,7 @@ func Background(job floc.Job) floc.Job {
// Run the job in background
go func(job floc.Job) {
err := job(ctx, ctrl)
handleResult(ctrl, err, locBackground)
handleResult(ctrl, err)
}(job)

return nil
Expand Down
4 changes: 1 addition & 3 deletions run/delay.go
Expand Up @@ -6,8 +6,6 @@ import (
"gopkg.in/workanator/go-floc.v2"
)

const locDelay = "Delay"

/*
Delay does delay before starting the job.
Expand Down Expand Up @@ -38,7 +36,7 @@ func Delay(delay time.Duration, job floc.Job) floc.Job {
case <-timer.C:
// Do the job
err := job(ctx, ctrl)
if handlerErr := handleResult(ctrl, err, locDelay); handlerErr != nil {
if handlerErr := handleResult(ctrl, err); handlerErr != nil {
return handlerErr
}
}
Expand Down
9 changes: 3 additions & 6 deletions run/handle_result.go
Expand Up @@ -2,15 +2,12 @@ package run

import (
"gopkg.in/workanator/go-floc.v2"
"gopkg.in/workanator/go-floc.v2/errors"
)

func handleResult(ctrl floc.Control, err error, where string) error {
func handleResult(ctrl floc.Control, err error) error {
if err != nil {
locationErr := errors.NewErrLocation(err, where)
ctrl.Fail(nil, locationErr)

return locationErr
ctrl.Fail(nil, err)
return err
}

return nil
Expand Down
5 changes: 2 additions & 3 deletions run/if.go
Expand Up @@ -5,7 +5,6 @@ import (
)

const (
locIf = "If"
idxTrue = 0
idxFalse = 1
)
Expand Down Expand Up @@ -46,7 +45,7 @@ func If(predicate floc.Predicate, jobs ...floc.Job) floc.Job {
// Test the predicate and run the job on success
if predicate(ctx) {
err := jobs[idxTrue](ctx, ctrl)
if handledErr := handleResult(ctrl, err, locIf); handledErr != nil {
if handledErr := handleResult(ctrl, err); handledErr != nil {
return handledErr
}
}
Expand All @@ -68,7 +67,7 @@ func If(predicate floc.Predicate, jobs ...floc.Job) floc.Job {
err = jobs[idxFalse](ctx, ctrl)
}

if handlerErr := handleResult(ctrl, err, locIf); handlerErr != nil {
if handlerErr := handleResult(ctrl, err); handlerErr != nil {
return handlerErr
}

Expand Down
8 changes: 2 additions & 6 deletions run/if_not.go
Expand Up @@ -4,10 +4,6 @@ import (
"gopkg.in/workanator/go-floc.v2"
)

const (
locIfNot = "IfNot"
)

/*
IfNot runs the first job if the condition is not met and runs
the second job, if it's passed, if the condition is met.
Expand Down Expand Up @@ -44,7 +40,7 @@ func IfNot(predicate floc.Predicate, jobs ...floc.Job) floc.Job {
// Test the predicate and run the job on success
if !predicate(ctx) {
err := jobs[idxTrue](ctx, ctrl)
if handledErr := handleResult(ctrl, err, locIfNot); handledErr != nil {
if handledErr := handleResult(ctrl, err); handledErr != nil {
return handledErr
}
}
Expand All @@ -66,7 +62,7 @@ func IfNot(predicate floc.Predicate, jobs ...floc.Job) floc.Job {
err = jobs[idxFalse](ctx, ctrl)
}

if handlerErr := handleResult(ctrl, err, locIfNot); handlerErr != nil {
if handlerErr := handleResult(ctrl, err); handlerErr != nil {
return handlerErr
}

Expand Down
4 changes: 1 addition & 3 deletions run/loop.go
Expand Up @@ -4,8 +4,6 @@ import (
"gopkg.in/workanator/go-floc.v2"
)

const locLoop = "Loop"

/*
Loop repeats running the job forever.
Expand All @@ -30,7 +28,7 @@ func Loop(job floc.Job) floc.Job {

// Do the job
err := job(ctx, ctrl)
if handledErr := handleResult(ctrl, err, locLoop); handledErr != nil {
if handledErr := handleResult(ctrl, err); handledErr != nil {
return handledErr
}
}
Expand Down
4 changes: 1 addition & 3 deletions run/parallel.go
Expand Up @@ -5,8 +5,6 @@ import (
"gopkg.in/workanator/go-floc.v2/errors"
)

const locParallel = "Parallel"

/*
Parallel runs jobs in their own goroutines and waits until all of them finish.
Expand Down Expand Up @@ -58,7 +56,7 @@ func Parallel(jobs ...floc.Job) floc.Job {

case err := <-done:
// One of the jobs finished
if handledErr := handleResult(ctrl, err, locParallel); handledErr != nil {
if handledErr := handleResult(ctrl, err); handledErr != nil {
errs = append(errs, handledErr)
}

Expand Down
4 changes: 1 addition & 3 deletions run/repeat.go
Expand Up @@ -4,8 +4,6 @@ import (
"gopkg.in/workanator/go-floc.v2"
)

const locRepeat = "Repeat"

/*
Repeat repeats running the job for N times.
Expand All @@ -31,7 +29,7 @@ func Repeat(times int, job floc.Job) floc.Job {

// Do the job
err := job(ctx, ctrl)
if handledErr := handleResult(ctrl, err, locRepeat); handledErr != nil {
if handledErr := handleResult(ctrl, err); handledErr != nil {
return handledErr
}
}
Expand Down
4 changes: 1 addition & 3 deletions run/sequence.go
Expand Up @@ -4,8 +4,6 @@ import (
"gopkg.in/workanator/go-floc.v2"
)

const locSequence = "Sequence"

/*
Sequence runs jobs sequentially - one by one.
Expand All @@ -27,7 +25,7 @@ func Sequence(jobs ...floc.Job) floc.Job {

// Run the job
err := job(ctx, ctrl)
if handledErr := handleResult(ctrl, err, locSequence); handledErr != nil {
if handledErr := handleResult(ctrl, err); handledErr != nil {
return handledErr
}
}
Expand Down
4 changes: 1 addition & 3 deletions run/while.go
Expand Up @@ -4,8 +4,6 @@ import (
"gopkg.in/workanator/go-floc.v2"
)

const locWhile = "While"

/*
While repeats running the job while the condition is met.
Expand All @@ -25,7 +23,7 @@ func While(predicate floc.Predicate, job floc.Job) floc.Job {
return func(ctx floc.Context, ctrl floc.Control) error {
for !ctrl.IsFinished() && predicate(ctx) {
err := job(ctx, ctrl)
if handledErr := handleResult(ctrl, err, locWhile); handledErr != nil {
if handledErr := handleResult(ctrl, err); handledErr != nil {
return handledErr
}
}
Expand Down
10 changes: 2 additions & 8 deletions run_test.go
Expand Up @@ -3,8 +3,6 @@ package floc
import (
"fmt"
"testing"

"gopkg.in/workanator/go-floc.v2/errors"
)

func TestRun_NilJob(t *testing.T) {
Expand Down Expand Up @@ -146,11 +144,7 @@ func TestRun_UnhandledError(t *testing.T) {

if err == nil {
t.Fatalf("%s expects error to be not nil", t.Name())
} else if e, ok := err.(errors.ErrLocation); !ok {
t.Fatalf("%s expects error to be of type ErrLocation but has %T", t.Name(), err)
} else if e.What().Error() != tplError.Error() {
t.Fatalf("%s expects error message to be %s but has %s", t.Name(), tplError.Error(), e.What().Error())
} else if e.Where() != locRun {
t.Fatalf("%s expects error location to be %s but has %s", t.Name(), locRun, e.Where())
} else if err.Error() != tplError.Error() {
t.Fatalf("%s expects error message to be %s but has %s", t.Name(), tplError.Error(), err.Error())
}
}

0 comments on commit 5e5dbfe

Please sign in to comment.