From e051c4a982f9d7703064bdeaea65ecb0d56327bd Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Fri, 13 Jul 2018 09:28:45 +0700 Subject: [PATCH] Removing errors dependency in client and runner packages --- client/gen.go | 2 -- client/targettype.go | 2 -- runner/runner.go | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/client/gen.go b/client/gen.go index f473f48..35ed799 100644 --- a/client/gen.go +++ b/client/gen.go @@ -93,7 +93,6 @@ const ( // Code generated by gen.go. DO NOT EDIT. import ( - // "errors" easyjson "github.com/mailru/easyjson" jlexer "github.com/mailru/easyjson/jlexer" jwriter "github.com/mailru/easyjson/jwriter" @@ -129,7 +128,6 @@ func (tt *TargetType) UnmarshalEasyJSON(in *jlexer.Lexer) { %s default: - // in.AddError(errors.New("unknown TargetType")) *tt = z } } diff --git a/client/targettype.go b/client/targettype.go index 073eecc..50e918e 100644 --- a/client/targettype.go +++ b/client/targettype.go @@ -3,7 +3,6 @@ package client // Code generated by gen.go. DO NOT EDIT. import ( - // "errors" easyjson "github.com/mailru/easyjson" jlexer "github.com/mailru/easyjson/jlexer" jwriter "github.com/mailru/easyjson/jwriter" @@ -70,7 +69,6 @@ func (tt *TargetType) UnmarshalEasyJSON(in *jlexer.Lexer) { *tt = Worker default: - // in.AddError(errors.New("unknown TargetType")) *tt = z } } diff --git a/runner/runner.go b/runner/runner.go index b21afbe..c2623c2 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -3,7 +3,6 @@ package runner import ( "context" - "errors" "fmt" "io/ioutil" "net/url" @@ -17,6 +16,32 @@ import ( "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 ( // DefaultUserDataDirPrefix is the default user data directory prefix. DefaultUserDataDirPrefix = "chromedp-runner.%d." @@ -128,7 +153,7 @@ func (r *Runner) Start(ctxt context.Context) error { r.rw.RUnlock() if cmd != nil { - return errors.New("already started") + return ErrAlreadyStarted } // setup context @@ -150,7 +175,7 @@ func (r *Runner) Start(ctxt context.Context) error { // ensure exec-path set execPath, ok := r.opts["exec-path"] if !ok { - return errors.New("exec-path command line option not set, or chrome executable not found in $PATH") + return ErrExecPathNotSet } // create cmd @@ -235,7 +260,7 @@ func (r *Runner) Wait() error { r.rw.RUnlock() if waiting { - return errors.New("already waiting") + return ErrAlreadyWaiting } r.rw.Lock() @@ -427,7 +452,7 @@ func CmdOpt(o func(*exec.Cmd) error) CommandLineOption { if e, ok := m["cmd-opts"]; ok { opts, ok = e.([]func(*exec.Cmd) error) 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 { opts, ok = e.([]func(*os.Process) error) if !ok { - return errors.New("process-opts is in invalid state") + return ErrInvalidProcessOpts } }