mirror of
https://github.com/go-task/task.git
synced 2025-01-26 05:27:15 +02:00
Move error types to its own file
This commit is contained in:
parent
b8116015c7
commit
a9b8e31228
33
errors.go
Normal file
33
errors.go
Normal file
@ -0,0 +1,33 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ErrNoTaskFile is returned when the program can not find a proper TaskFile
|
||||
var ErrNoTaskFile = fmt.Errorf(`No task file found (is it named "%s"?)`, TaskFilePath)
|
||||
|
||||
type taskNotFoundError struct {
|
||||
taskName string
|
||||
}
|
||||
|
||||
func (err *taskNotFoundError) Error() string {
|
||||
return fmt.Sprintf(`Task "%s" not found`, err.taskName)
|
||||
}
|
||||
|
||||
type taskRunError struct {
|
||||
taskName string
|
||||
err error
|
||||
}
|
||||
|
||||
func (err *taskRunError) Error() string {
|
||||
return fmt.Sprintf(`Failed to run task "%s": %v`, err.taskName, err.err)
|
||||
}
|
||||
|
||||
type cyclicDepError struct {
|
||||
taskName string
|
||||
}
|
||||
|
||||
func (err *cyclicDepError) Error() string {
|
||||
return fmt.Sprintf(`Cyclic dependency of task "%s" detected`, err.taskName)
|
||||
}
|
30
task.go
30
task.go
@ -2,8 +2,6 @@ package task
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
@ -49,31 +47,6 @@ type Task struct {
|
||||
Dir string
|
||||
}
|
||||
|
||||
type taskNotFoundError struct {
|
||||
taskName string
|
||||
}
|
||||
|
||||
func (err *taskNotFoundError) Error() string {
|
||||
return fmt.Sprintf(`Task "%s" not found`, err.taskName)
|
||||
}
|
||||
|
||||
type taskRunError struct {
|
||||
taskName string
|
||||
err error
|
||||
}
|
||||
|
||||
func (err *taskRunError) Error() string {
|
||||
return fmt.Sprintf(`Failed to run task "%s": %v`, err.taskName, err.err)
|
||||
}
|
||||
|
||||
type cyclicDepError struct {
|
||||
taskName string
|
||||
}
|
||||
|
||||
func (err *cyclicDepError) Error() string {
|
||||
return fmt.Sprintf(`Cyclic dependency of task "%s" detected`, err.taskName)
|
||||
}
|
||||
|
||||
// Run runs Task
|
||||
func Run() {
|
||||
log.SetFlags(0)
|
||||
@ -175,6 +148,3 @@ func readTaskfile() (tasks map[string]*Task, err error) {
|
||||
}
|
||||
return nil, ErrNoTaskFile
|
||||
}
|
||||
|
||||
// ErrNoTaskFile is returns when the program can not find a proper TaskFile
|
||||
var ErrNoTaskFile = errors.New("no task file found (is it named '" + TaskFilePath + "'?)")
|
||||
|
Loading…
x
Reference in New Issue
Block a user