Removing errors dependency in client and runner packages

This commit is contained in:
Kenneth Shaw 2018-07-13 09:28:45 +07:00
parent 0406fa8a8a
commit e051c4a982
3 changed files with 31 additions and 10 deletions

View File

@ -93,7 +93,6 @@ const (
// Code generated by gen.go. DO NOT EDIT. // Code generated by gen.go. DO NOT EDIT.
import ( import (
// "errors"
easyjson "github.com/mailru/easyjson" easyjson "github.com/mailru/easyjson"
jlexer "github.com/mailru/easyjson/jlexer" jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter" jwriter "github.com/mailru/easyjson/jwriter"
@ -129,7 +128,6 @@ func (tt *TargetType) UnmarshalEasyJSON(in *jlexer.Lexer) {
%s %s
default: default:
// in.AddError(errors.New("unknown TargetType"))
*tt = z *tt = z
} }
} }

View File

@ -3,7 +3,6 @@ package client
// Code generated by gen.go. DO NOT EDIT. // Code generated by gen.go. DO NOT EDIT.
import ( import (
// "errors"
easyjson "github.com/mailru/easyjson" easyjson "github.com/mailru/easyjson"
jlexer "github.com/mailru/easyjson/jlexer" jlexer "github.com/mailru/easyjson/jlexer"
jwriter "github.com/mailru/easyjson/jwriter" jwriter "github.com/mailru/easyjson/jwriter"
@ -70,7 +69,6 @@ func (tt *TargetType) UnmarshalEasyJSON(in *jlexer.Lexer) {
*tt = Worker *tt = Worker
default: default:
// in.AddError(errors.New("unknown TargetType"))
*tt = z *tt = z
} }
} }

View File

@ -3,7 +3,6 @@ package runner
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/url" "net/url"
@ -17,6 +16,32 @@ import (
"github.com/chromedp/chromedp/client" "github.com/chromedp/chromedp/client"
) )
// Error is a runner error.
type Error string
// Error satisfies the error interface.
func (err Error) Error() string {
return string(err)
}
// Error values.
const (
// ErrAlreadyStarted is the already started error.
ErrAlreadyStarted Error = "already started"
// ErrAlreadyWaiting is the already waiting error.
ErrAlreadyWaiting Error = "already waiting"
// ErrInvalidCmdOpts is the invalid cmd-opts error.
ErrInvalidCmdOpts Error = "invalid cmd-opts"
// ErrInvalidProcessOpts is the invalid process-opts error.
ErrInvalidProcessOpts Error = "invalid process-opts"
// ErrExecPathNotSet is the exec-path not set set error.
ErrExecPathNotSet Error = "exec-path command line option not set, or chrome executable not found in PATH"
)
const ( const (
// DefaultUserDataDirPrefix is the default user data directory prefix. // DefaultUserDataDirPrefix is the default user data directory prefix.
DefaultUserDataDirPrefix = "chromedp-runner.%d." DefaultUserDataDirPrefix = "chromedp-runner.%d."
@ -128,7 +153,7 @@ func (r *Runner) Start(ctxt context.Context) error {
r.rw.RUnlock() r.rw.RUnlock()
if cmd != nil { if cmd != nil {
return errors.New("already started") return ErrAlreadyStarted
} }
// setup context // setup context
@ -150,7 +175,7 @@ func (r *Runner) Start(ctxt context.Context) error {
// ensure exec-path set // ensure exec-path set
execPath, ok := r.opts["exec-path"] execPath, ok := r.opts["exec-path"]
if !ok { if !ok {
return errors.New("exec-path command line option not set, or chrome executable not found in $PATH") return ErrExecPathNotSet
} }
// create cmd // create cmd
@ -235,7 +260,7 @@ func (r *Runner) Wait() error {
r.rw.RUnlock() r.rw.RUnlock()
if waiting { if waiting {
return errors.New("already waiting") return ErrAlreadyWaiting
} }
r.rw.Lock() r.rw.Lock()
@ -427,7 +452,7 @@ func CmdOpt(o func(*exec.Cmd) error) CommandLineOption {
if e, ok := m["cmd-opts"]; ok { if e, ok := m["cmd-opts"]; ok {
opts, ok = e.([]func(*exec.Cmd) error) opts, ok = e.([]func(*exec.Cmd) error)
if !ok { if !ok {
return errors.New("cmd-opts is in invalid state") return ErrInvalidCmdOpts
} }
} }
@ -446,7 +471,7 @@ func ProcessOpt(o func(*os.Process) error) CommandLineOption {
if e, ok := m["process-opts"]; ok { if e, ok := m["process-opts"]; ok {
opts, ok = e.([]func(*os.Process) error) opts, ok = e.([]func(*os.Process) error)
if !ok { if !ok {
return errors.New("process-opts is in invalid state") return ErrInvalidProcessOpts
} }
} }