diff --git a/.travis.yml b/.travis.yml index 8074a76..b660ad5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,9 @@ language: go sudo: false go: - - "1.12" - "1.13" - "1.14" + - "1.15" - "tip" before_install: @@ -22,6 +22,3 @@ matrix: git: depth: 10 - -env: - - GO111MODULE=on \ No newline at end of file diff --git a/alert.go b/alert.go index baf1858..998e9fb 100644 --- a/alert.go +++ b/alert.go @@ -2,7 +2,7 @@ package sarah import ( "context" - "golang.org/x/xerrors" + "fmt" "strings" ) @@ -46,7 +46,14 @@ func (a *alerters) alertAll(ctx context.Context, botType BotType, err error) err func() { defer func() { if r := recover(); r != nil { - alertErrs.appendError(xerrors.Errorf("panic on Alerter.Alert: %w", r)) + e, ok := r.(error) + var err error + if ok { + err = fmt.Errorf("panic on Alerter.Alert: %w", e) + } else { + err = fmt.Errorf("panic on Alerter.Alert: %+v", r) + } + alertErrs.appendError(err) } }() err := alerter.Alert(ctx, botType, err) diff --git a/alert_test.go b/alert_test.go index fb4894e..030a786 100644 --- a/alert_test.go +++ b/alert_test.go @@ -78,7 +78,13 @@ func TestAlerters_alertAll(t *testing.T) { t.Errorf("Expected no error to be returned, but got %s.", err.Error()) } + wrappedErr := errors.New("panic with an error") a = &alerters{ + &DummyAlerter{ + AlertFunc: func(_ context.Context, _ BotType, _ error) error { + panic(wrappedErr) + }, + }, &DummyAlerter{ AlertFunc: func(_ context.Context, _ BotType, _ error) error { panic("PANIC!!") @@ -100,9 +106,17 @@ func TestAlerters_alertAll(t *testing.T) { if err == nil { t.Fatal("Expected error to be returned") } - if e, ok := err.(*alertErrs); !ok { + + typed, ok := err.(*alertErrs) + if !ok { t.Fatalf("Expected error type of *alertErrs, but was %T.", err) - } else if len(*e) != 2 { - t.Errorf("Expected 2 errors to be stored: %#v.", err) + } + if len(*typed) != 3 { + t.Fatalf("Expected 3 errors to be stored: %#v.", err) + } + + e := errors.Unwrap((*typed)[0]) + if e != wrappedErr { + t.Errorf("Expected error is not wrapped: %+v", e) } } diff --git a/alerter/line/client.go b/alerter/line/client.go index 716c0b5..b3b5cc0 100644 --- a/alerter/line/client.go +++ b/alerter/line/client.go @@ -7,7 +7,6 @@ import ( "context" "fmt" "github.com/oklahomer/go-sarah/v3" - "golang.org/x/xerrors" "net/http" "net/url" "strings" @@ -84,7 +83,7 @@ func (c *Client) Alert(ctx context.Context, botType sarah.BotType, err error) er } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return xerrors.Errorf("response status %d is returned", resp.StatusCode) + return fmt.Errorf("response status %d is returned", resp.StatusCode) } return nil diff --git a/command.go b/command.go index 51a91d8..c53b694 100644 --- a/command.go +++ b/command.go @@ -2,8 +2,9 @@ package sarah import ( "context" + "errors" + "fmt" "github.com/oklahomer/go-sarah/v3/log" - "golang.org/x/xerrors" "reflect" "regexp" "strings" @@ -13,7 +14,7 @@ import ( var ( // ErrCommandInsufficientArgument depicts an error that not enough arguments are set to CommandProps. // This is returned on CommandProps.Build() inside of runner.Run() - ErrCommandInsufficientArgument = xerrors.New("BotType, Identifier, InstructionFunc, MatchFunc and (Configurable)Func must be set.") + ErrCommandInsufficientArgument = errors.New("BotType, Identifier, InstructionFunc, MatchFunc and (Configurable)Func must be set") ) // CommandResponse is returned by Command or Task when the execution is finished. @@ -118,9 +119,9 @@ func buildCommand(ctx context.Context, props *CommandProps, watcher ConfigWatche }() var notFoundErr *ConfigNotFoundError - if err != nil && !xerrors.As(err, ¬FoundErr) { + if err != nil && !errors.As(err, ¬FoundErr) { // Unacceptable error - return nil, xerrors.Errorf("failed to read config for %s:%s: %w", props.botType, props.identifier, err) + return nil, fmt.Errorf("failed to read config for %s:%s: %w", props.botType, props.identifier, err) } return &defaultCommand{ @@ -361,7 +362,7 @@ func (builder *CommandPropsBuilder) Build() (*CommandProps, error) { func (builder *CommandPropsBuilder) MustBuild() *CommandProps { props, err := builder.Build() if err != nil { - panic(xerrors.Errorf("error on building CommandProps: %w", err)) + panic(fmt.Errorf("error on building CommandProps: %w", err)) } return props diff --git a/command_test.go b/command_test.go index b93b9c5..64c015a 100644 --- a/command_test.go +++ b/command_test.go @@ -2,7 +2,8 @@ package sarah import ( "context" - "golang.org/x/xerrors" + "errors" + "fmt" "reflect" "regexp" "strconv" @@ -489,11 +490,11 @@ func Test_buildCommand(t *testing.T) { validateConfig: func(cfg interface{}) error { config, ok := cfg.(*config) if !ok { - return xerrors.Errorf("Unexpected type is passed: %T.", cfg) + return fmt.Errorf("unexpected type is passed: %T", cfg) } if config.text != "texts" { - return xerrors.Errorf("Unexpected value is set: %s", config.text) + return fmt.Errorf("nexpected value is set: %s", config.text) } return nil @@ -531,11 +532,11 @@ func Test_buildCommand(t *testing.T) { validateConfig: func(cfg interface{}) error { config, ok := cfg.(config) // Value is passed if !ok { - return xerrors.Errorf("Unexpected type is passed: %T.", cfg) + return fmt.Errorf("unexpected type is passed: %T", cfg) } if config.text != "texts" { - return xerrors.Errorf("Unexpected value is set: %s", config.text) + return fmt.Errorf("unexpected value is set: %s", config.text) } return nil @@ -568,11 +569,11 @@ func Test_buildCommand(t *testing.T) { validateConfig: func(cfg interface{}) error { config, ok := cfg.(*config) if !ok { - return xerrors.Errorf("Unexpected type is passed: %T.", cfg) + return fmt.Errorf("unexpected type is passed: %T", cfg) } if config.text != "" { - return xerrors.Errorf("Unexpected value is set: %s", config.text) + return fmt.Errorf("unexpected value is set: %s", config.text) } return nil @@ -596,7 +597,7 @@ func Test_buildCommand(t *testing.T) { }, watcher: &DummyConfigWatcher{ ReadFunc: func(_ context.Context, _ BotType, _ string, _ interface{}) error { - return xerrors.New("unacceptable error") + return errors.New("unacceptable error") }, }, hasErr: true, diff --git a/examples/simple/plugins/worldweather/client.go b/examples/simple/plugins/worldweather/client.go index 46cce1f..78dc4b5 100644 --- a/examples/simple/plugins/worldweather/client.go +++ b/examples/simple/plugins/worldweather/client.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "golang.org/x/xerrors" "io/ioutil" "net/http" "net/url" @@ -47,7 +46,7 @@ func (client *Client) buildEndpoint(apiType string, queryParams *url.Values) *ur requestURL, err := url.Parse(fmt.Sprintf(weatherAPIEndpointFormat, apiType)) if err != nil { - panic(xerrors.Errorf("failed to parse construct URL for %s: %w", apiType, err)) + panic(fmt.Errorf("failed to parse construct URL for %s: %w", apiType, err)) } requestURL.RawQuery = queryParams.Encode() @@ -59,26 +58,26 @@ func (client *Client) Get(ctx context.Context, apiType string, queryParams *url. endpoint := client.buildEndpoint(apiType, queryParams) req, err := http.NewRequest(http.MethodGet, endpoint.String(), nil) if err != nil { - return xerrors.Errorf("failed to build request: %w", err) + return fmt.Errorf("failed to build request: %w", err) } resp, err := http.DefaultClient.Do(req) if err != nil { - return xerrors.Errorf("failed on GET request for %s: %w", apiType, err) + return fmt.Errorf("failed on GET request for %s: %w", apiType, err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return xerrors.Errorf("response status %d is returned", resp.StatusCode) + return fmt.Errorf("response status %d is returned", resp.StatusCode) } body, err := ioutil.ReadAll(resp.Body) if err != nil { - return xerrors.Errorf("failed to read response: %w", err) + return fmt.Errorf("failed to read response: %w", err) } if err := json.Unmarshal(body, data); err != nil { - return xerrors.Errorf("failed to parse returned json data: %w", err) + return fmt.Errorf("failed to parse returned json data: %w", err) } return nil @@ -90,7 +89,7 @@ func (client *Client) LocalWeather(ctx context.Context, location string) (*Local queryParams.Add("q", location) data := &LocalWeatherResponse{} if err := client.Get(ctx, "weather", queryParams, data); err != nil { - return nil, xerrors.Errorf("failed getting weather data: %w", err) + return nil, fmt.Errorf("failed getting weather data: %w", err) } return data, nil diff --git a/examples/simple/plugins/worldweather/client_test.go b/examples/simple/plugins/worldweather/client_test.go index c978730..956226f 100644 --- a/examples/simple/plugins/worldweather/client_test.go +++ b/examples/simple/plugins/worldweather/client_test.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "errors" - "golang.org/x/xerrors" "io/ioutil" "net/http" "net/url" @@ -186,7 +185,7 @@ func TestClient_GetRequestError(t *testing.T) { } var urlErr *url.Error - if !xerrors.As(err, &urlErr) { + if !errors.As(err, &urlErr) { t.Errorf("Unexpected error is returned: %#v.", err) } } diff --git a/examples/status/config.go b/examples/status/config.go index 7d0c946..353e12b 100644 --- a/examples/status/config.go +++ b/examples/status/config.go @@ -1,10 +1,10 @@ package main import ( + "fmt" "github.com/oklahomer/go-sarah/v3" "github.com/oklahomer/go-sarah/v3/slack" "github.com/oklahomer/go-sarah/v3/workers" - "golang.org/x/xerrors" "gopkg.in/yaml.v2" "io/ioutil" ) @@ -12,7 +12,7 @@ import ( func readConfig(path string) (*config, error) { body, err := ioutil.ReadFile(path) if err != nil { - return nil, xerrors.Errorf("failed to read file: %w", err) + return nil, fmt.Errorf("failed to read file: %w", err) } // Populate with default configuration value by calling each constructor. @@ -24,7 +24,7 @@ func readConfig(path string) (*config, error) { } err = yaml.Unmarshal(body, c) if err != nil { - return nil, xerrors.Errorf("failed to read yaml: %w", err) + return nil, fmt.Errorf("failed to read yaml: %w", err) } return c, nil diff --git a/examples/status/main.go b/examples/status/main.go index a3ce1b9..aeefb47 100644 --- a/examples/status/main.go +++ b/examples/status/main.go @@ -9,11 +9,11 @@ package main import ( "context" "flag" + "fmt" "github.com/oklahomer/go-sarah/v3" "github.com/oklahomer/go-sarah/v3/log" "github.com/oklahomer/go-sarah/v3/slack" "github.com/oklahomer/go-sarah/v3/workers" - "golang.org/x/xerrors" "os" "os/signal" "time" @@ -80,11 +80,11 @@ func setupSlackBot(cfg *config) (sarah.Bot, error) { storage := sarah.NewUserContextStorage(cfg.ContextCache) slackAdapter, err := slack.NewAdapter(cfg.Slack) if err != nil { - return nil, xerrors.Errorf("failed to initialize Slack adapter: %w", err) + return nil, fmt.Errorf("failed to initialize Slack adapter: %w", err) } slackBot, err := sarah.NewBot(slackAdapter, sarah.BotWithStorage(storage)) if err != nil { - return nil, xerrors.Errorf("failed to initialize Bot with given Slack adapter: %w", err) + return nil, fmt.Errorf("failed to initialize Bot with given Slack adapter: %w", err) } return slackBot, nil } diff --git a/gitter/adapter.go b/gitter/adapter.go index 976f64d..cfb9932 100644 --- a/gitter/adapter.go +++ b/gitter/adapter.go @@ -2,10 +2,11 @@ package gitter import ( "context" + "errors" + "fmt" "github.com/oklahomer/go-sarah/v3" "github.com/oklahomer/go-sarah/v3/log" "github.com/oklahomer/go-sarah/v3/retry" - "golang.org/x/xerrors" ) const ( @@ -119,21 +120,21 @@ func receiveMessageRecursive(messageReceiver MessageReceiver, enqueueInput func( message, err := messageReceiver.Receive() var malformedErr *MalformedPayloadError - if xerrors.Is(err, ErrEmptyPayload) { + if errors.Is(err, ErrEmptyPayload) { // https://developer.gitter.im/docs/streaming-api // Parsers must be tolerant of occasional extra newline characters placed between messages. // These characters are sent as periodic "keep-alive" messages to tell clients and NAT firewalls // that the connection is still alive during low message volume periods. continue - } else if xerrors.As(err, &malformedErr) { + } else if errors.As(err, &malformedErr) { log.Warnf("Skipping malformed input: %+v", err) continue } else if err != nil { // At this point, assume connection is unstable or is closed. // Let caller proceed to reconnect or quit. - return xerrors.Errorf("failed to receive input: %w", err) + return fmt.Errorf("failed to receive input: %w", err) } diff --git a/gitter/connection.go b/gitter/connection.go index 648766f..b7b6667 100644 --- a/gitter/connection.go +++ b/gitter/connection.go @@ -4,16 +4,16 @@ import ( "bufio" "bytes" "encoding/json" + "errors" "fmt" "github.com/oklahomer/go-sarah/v3" - "golang.org/x/xerrors" "io" "time" ) var ( // ErrEmptyPayload is an error that represents empty payload. - ErrEmptyPayload = xerrors.New("empty payload was given") + ErrEmptyPayload = errors.New("empty payload was given") ) // MessageReceiver defines an interface that receives RoomMessage. diff --git a/gitter/rest.go b/gitter/rest.go index 79ecc3d..641fb24 100644 --- a/gitter/rest.go +++ b/gitter/rest.go @@ -3,8 +3,8 @@ package gitter import ( "context" "encoding/json" + "fmt" "github.com/oklahomer/go-sarah/v3/log" - "golang.org/x/xerrors" "io/ioutil" "net/http" "net/url" @@ -138,7 +138,7 @@ func (client *RestAPIClient) PostMessage(ctx context.Context, room *Room, text s message := &Message{} err := client.Post(ctx, []string{"rooms", room.ID, "chatMessages"}, &PostingMessage{Text: text}, message) if err != nil { - return nil, xerrors.Errorf("failed to post message: %w", err) + return nil, fmt.Errorf("failed to post message: %w", err) } return message, nil } diff --git a/go.mod b/go.mod index f4502f2..60baa39 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,5 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/robfig/cron/v3 v3.0.1 golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 gopkg.in/yaml.v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 0efd9bc..3a5c152 100644 --- a/go.sum +++ b/go.sum @@ -37,8 +37,6 @@ golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 h1:5B6i6EAiSYyejWfvc5Rc9BbI3 golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/runner.go b/runner.go index 28e0525..b0edfd6 100644 --- a/runner.go +++ b/runner.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/oklahomer/go-sarah/v3/log" "github.com/oklahomer/go-sarah/v3/workers" - "golang.org/x/xerrors" "runtime" "strings" "sync" @@ -171,12 +170,12 @@ func RegisterBotErrorSupervisor(fnc func(BotType, error) *SupervisionDirective) func Run(ctx context.Context, config *Config) error { err := runnerStatus.start() if err != nil { - return xerrors.Errorf("failed to start bot process: %w", err) + return fmt.Errorf("failed to start bot process: %w", err) } runner, err := newRunner(ctx, config) if err != nil { - return xerrors.Errorf("failed to start bot process: %w", err) + return fmt.Errorf("failed to start bot process: %w", err) } go runner.run(ctx) @@ -186,7 +185,7 @@ func Run(ctx context.Context, config *Config) error { func newRunner(ctx context.Context, config *Config) (*runner, error) { loc, err := time.LoadLocation(config.TimeZone) if err != nil { - return nil, xerrors.Errorf(`given timezone "%s" cannot be converted to time.Location: %w`, config.TimeZone, err) + return nil, fmt.Errorf(`given timezone "%s" cannot be converted to time.Location: %w`, config.TimeZone, err) } r := &runner{ @@ -208,7 +207,7 @@ func newRunner(ctx context.Context, config *Config) (*runner, error) { if r.worker == nil { w, e := workers.Run(ctx, workers.NewConfig()) if e != nil { - return nil, xerrors.Errorf("worker could not run: %w", e) + return nil, fmt.Errorf("worker could not run: %w", e) } r.worker = w diff --git a/runner_test.go b/runner_test.go index 2078cf1..c7615b2 100644 --- a/runner_test.go +++ b/runner_test.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "github.com/oklahomer/go-sarah/v3/log" - "golang.org/x/xerrors" "io/ioutil" stdLogger "log" "os" @@ -663,20 +662,20 @@ func Test_runner_superviseBot(t *testing.T) { shutdown: true, }, { - escalated: xerrors.New("plain error"), + escalated: errors.New("plain error"), directive: nil, shutdown: false, }, { - escalated: xerrors.New("plain error"), + escalated: errors.New("plain error"), directive: &SupervisionDirective{ - AlertingErr: xerrors.New("this is sent via alerter"), + AlertingErr: errors.New("this is sent via alerter"), StopBot: true, }, shutdown: true, }, { - escalated: xerrors.New("plain error"), + escalated: errors.New("plain error"), directive: &SupervisionDirective{ AlertingErr: nil, StopBot: true, @@ -684,15 +683,15 @@ func Test_runner_superviseBot(t *testing.T) { shutdown: true, }, { - escalated: xerrors.New("plain error"), + escalated: errors.New("plain error"), directive: &SupervisionDirective{ - AlertingErr: xerrors.New("this is sent via alerter"), + AlertingErr: errors.New("this is sent via alerter"), StopBot: false, }, shutdown: false, }, { - escalated: xerrors.New("plain error"), + escalated: errors.New("plain error"), directive: &SupervisionDirective{ AlertingErr: nil, StopBot: false, @@ -781,7 +780,7 @@ func Test_runner_superviseBot(t *testing.T) { // See if a succeeding call block nonBlocking := make(chan bool) go func() { - errSupervisor(xerrors.New("succeeding calls should never block")) + errSupervisor(errors.New("succeeding calls should never block")) nonBlocking <- true }() select { @@ -929,10 +928,10 @@ func Test_registerCommands(t *testing.T) { { configWatcher: &DummyConfigWatcher{ ReadFunc: func(_ context.Context, _ BotType, _ string, _ interface{}) error { - return xerrors.Errorf("configuration error") + return errors.New("configuration error") }, WatchFunc: func(_ context.Context, _ BotType, _ string, _ func()) error { - return xerrors.New("subscription error") + return errors.New("subscription error") }, }, props: []*CommandProps{ @@ -1106,7 +1105,7 @@ func Test_registerScheduledTasks(t *testing.T) { { configWatcher: &DummyConfigWatcher{ WatchFunc: func(_ context.Context, _ BotType, _ string, _ func()) error { - return xerrors.New("subscription error") + return errors.New("subscription error") }, }, props: []*ScheduledTaskProps{ @@ -1137,7 +1136,7 @@ func Test_registerScheduledTasks(t *testing.T) { scheduler: &DummyScheduler{ UpdateFunc: func(_ BotType, _ ScheduledTask, _ func()) error { if tt.updateError { - return xerrors.New("update error") + return errors.New("update error") } regNum++ return nil diff --git a/scheduler.go b/scheduler.go index 2f48016..59a1bb3 100644 --- a/scheduler.go +++ b/scheduler.go @@ -2,9 +2,9 @@ package sarah import ( "context" + "fmt" "github.com/oklahomer/go-sarah/v3/log" "github.com/robfig/cron/v3" - "golang.org/x/xerrors" "time" ) @@ -100,7 +100,7 @@ func (s *taskScheduler) receiveEvent(ctx context.Context) { case add := <-s.updatingTask: if add.task.Schedule() == "" { - add.err <- xerrors.Errorf("empty schedule is given for %s", add.task.Identifier()) + add.err <- fmt.Errorf("empty schedule is given for %s", add.task.Identifier()) continue } diff --git a/slack/adapter.go b/slack/adapter.go index edff6e4..b6afde5 100644 --- a/slack/adapter.go +++ b/slack/adapter.go @@ -2,6 +2,7 @@ package slack import ( "context" + "errors" "fmt" "github.com/oklahomer/go-sarah/v3" "github.com/oklahomer/go-sarah/v3/log" @@ -10,7 +11,6 @@ import ( "github.com/oklahomer/golack/v2/eventsapi" "github.com/oklahomer/golack/v2/rtmapi" "github.com/oklahomer/golack/v2/webapi" - "golang.org/x/xerrors" "time" ) @@ -20,7 +20,7 @@ const ( ) // ErrNonSupportedEvent is returned when given event is not supported by this adapter. -var ErrNonSupportedEvent = xerrors.New("event not supported") +var ErrNonSupportedEvent = errors.New("event not supported") // AdapterOption defines function signature that Adapter's functional option must satisfy. type AdapterOption func(adapter *Adapter) @@ -146,7 +146,7 @@ func NewAdapter(config *Config, options ...AdapterOption) (*Adapter, error) { // If not, use golack with given configuration. if adapter.client == nil { if config.Token == "" { - return nil, xerrors.New("Slack client must be provided with WithSlackClient option or must be configurable with given *Config") + return nil, errors.New("Slack client must be provided with WithSlackClient option or must be configurable with given *Config") } golackConfig := golack.NewConfig() @@ -161,7 +161,7 @@ func NewAdapter(config *Config, options ...AdapterOption) (*Adapter, error) { } if adapter.apiSpecificAdapterBuilder == nil { - return nil, xerrors.New("RTM or Events API configuration must be applied with WithRTMPayloadHandler or WithEventsPayloadHandler") + return nil, errors.New("RTM or Events API configuration must be applied with WithRTMPayloadHandler or WithEventsPayloadHandler") } return adapter, nil @@ -345,7 +345,7 @@ func IsThreadMessage(input *Input) bool { func NewResponse(input sarah.Input, msg string, options ...RespOption) (*sarah.CommandResponse, error) { typed, ok := input.(*Input) if !ok { - return nil, xerrors.Errorf("%T is not currently supported to automatically generate response", input) + return nil, fmt.Errorf("%T is not currently supported to automatically generate response", input) } stash := &respOptions{ diff --git a/slack/eventsapi_test.go b/slack/eventsapi_test.go index 0250109..df5abe4 100644 --- a/slack/eventsapi_test.go +++ b/slack/eventsapi_test.go @@ -2,10 +2,10 @@ package slack import ( "context" + "errors" "github.com/oklahomer/go-sarah/v3" "github.com/oklahomer/golack/v2/event" "github.com/oklahomer/golack/v2/eventsapi" - "golang.org/x/xerrors" "testing" "time" ) @@ -44,7 +44,7 @@ func Test_eventsAPIAdapter_run(t *testing.T) { t.Run("Running server returns an error", func(t *testing.T) { // Prepare an adapter with a client that fails to run a server. - expectedErr := xerrors.New("ERROR") + expectedErr := errors.New("ERROR") client := &DummyClient{ RunServerFunc: func(_ context.Context, _ eventsapi.EventReceiver) <-chan error { ch := make(chan error, 1) @@ -70,7 +70,7 @@ func Test_eventsAPIAdapter_run(t *testing.T) { select { case err := <-errCh: var target *sarah.BotNonContinuableError - if !xerrors.As(err, &target) { + if !errors.As(err, &target) { t.Errorf("Expected error is not returned: %#v", err) } diff --git a/slack/rtmapi.go b/slack/rtmapi.go index bf89e8c..aa62eb5 100644 --- a/slack/rtmapi.go +++ b/slack/rtmapi.go @@ -2,12 +2,12 @@ package slack import ( "context" + "fmt" "github.com/oklahomer/go-sarah/v3" "github.com/oklahomer/go-sarah/v3/log" "github.com/oklahomer/go-sarah/v3/retry" "github.com/oklahomer/golack/v2/event" "github.com/oklahomer/golack/v2/rtmapi" - "golang.org/x/xerrors" "strings" "time" ) @@ -122,7 +122,7 @@ func (r *rtmAPIAdapter) superviseConnection(connCtx context.Context, payloadSend log.Debug("Send ping") err := payloadSender.Ping() if err != nil { - return xerrors.Errorf("error on ping: %w", err) + return fmt.Errorf("error on ping: %w", err) } } } diff --git a/slack/rtmapi_test.go b/slack/rtmapi_test.go index 72d7d55..f39fcd6 100644 --- a/slack/rtmapi_test.go +++ b/slack/rtmapi_test.go @@ -7,7 +7,6 @@ import ( "github.com/oklahomer/go-sarah/v3/retry" "github.com/oklahomer/golack/v2/event" "github.com/oklahomer/golack/v2/rtmapi" - "golang.org/x/xerrors" "reflect" "testing" "time" @@ -119,7 +118,7 @@ func Test_rtmAPIAdapter_run(t *testing.T) { select { case err := <-errCh: var target *sarah.BotNonContinuableError - if !xerrors.As(err, &target) { + if !errors.As(err, &target) { t.Errorf("Expected error is not returned: %#v", err) } @@ -328,7 +327,7 @@ func Test_rtmAPIAdapter_superviseConnection(t *testing.T) { t.Run("Ping error", func(t *testing.T) { // Prepare a connection that returns error on Ping. - expectedErr := xerrors.New("PING ERROR") + expectedErr := errors.New("PING ERROR") conn := &DummyConnection{ PingFunc: func() error { return expectedErr @@ -358,7 +357,7 @@ func Test_rtmAPIAdapter_superviseConnection(t *testing.T) { // See if expected error is returned. select { case err := <-conErr: - if !xerrors.Is(err, expectedErr) { + if !errors.Is(err, expectedErr) { t.Errorf("Expected error is not returned: %#v", err) } diff --git a/status.go b/status.go index 0339f93..cef56b6 100644 --- a/status.go +++ b/status.go @@ -1,8 +1,8 @@ package sarah import ( + "errors" "github.com/oklahomer/go-sarah/v3/log" - "golang.org/x/xerrors" "sync" ) @@ -10,7 +10,7 @@ var runnerStatus = &status{} // ErrRunnerAlreadyRunning indicates that sarah.Run() is already called and the process is already running. // When this is returned, a second or later activations are prevented so the initially activated process is still protected. -var ErrRunnerAlreadyRunning = xerrors.New("go-sarah's process is already running") +var ErrRunnerAlreadyRunning = errors.New("go-sarah's process is already running") // CurrentStatus returns the current status of go-sarah. // This can still be called even if sarah.Run() is not called, yet. diff --git a/storage.go b/storage.go index 6a0b431..96ca6a6 100644 --- a/storage.go +++ b/storage.go @@ -2,8 +2,9 @@ package sarah import ( "context" + "errors" + "fmt" "github.com/patrickmn/go-cache" - "golang.org/x/xerrors" "time" ) @@ -99,7 +100,7 @@ func (storage *defaultUserContextStorage) Get(key string) (ContextualFunc, error return v.Next, nil default: - return nil, xerrors.Errorf("cached value has illegal type of %T", v) + return nil, fmt.Errorf("cached value has illegal type of %T", v) } } @@ -115,7 +116,7 @@ func (storage *defaultUserContextStorage) Delete(key string) error { // Stored context is tied to given key, which represents a particular user. func (storage *defaultUserContextStorage) Set(key string, userContext *UserContext) error { if userContext.Next == nil { - return xerrors.New("required UserContext.Next is not set. defaultUserContextStorage only supports in-memory ContextualFunc cache.") + return errors.New("required UserContext.Next is not set. defaultUserContextStorage only supports in-memory ContextualFunc cache") } storage.cache.Set(key, userContext, cache.DefaultExpiration) diff --git a/task.go b/task.go index b9d70ef..f80f8c6 100644 --- a/task.go +++ b/task.go @@ -2,17 +2,18 @@ package sarah import ( "context" - "golang.org/x/xerrors" + "errors" + "fmt" "reflect" "sync" ) var ( // ErrTaskInsufficientArgument is returned when required parameters are not set. - ErrTaskInsufficientArgument = xerrors.New("one or more of required fields -- BotType, Identifier or Func -- are empty") + ErrTaskInsufficientArgument = errors.New("one or more of required fields -- BotType, Identifier or Func -- are empty") // ErrTaskScheduleNotGiven is returned when schedule is provided by neither ScheduledTaskPropsBuilder's parameter nor config. - ErrTaskScheduleNotGiven = xerrors.New("task schedule is not set or given from config struct") + ErrTaskScheduleNotGiven = errors.New("task schedule is not set or given from config struct") ) // ScheduledTaskResult is a struct that ScheduledTask returns on its execution. @@ -144,9 +145,9 @@ func buildScheduledTask(ctx context.Context, props *ScheduledTaskProps, watcher }() var notFoundErr *ConfigNotFoundError - if err != nil && !xerrors.As(err, ¬FoundErr) { + if err != nil && !errors.As(err, ¬FoundErr) { // Unacceptable error - return nil, xerrors.Errorf("failed to read config for %s:%s: %w", props.botType, props.identifier, err) + return nil, fmt.Errorf("failed to read config for %s:%s: %w", props.botType, props.identifier, err) } // Setup execution schedule @@ -286,7 +287,7 @@ func (builder *ScheduledTaskPropsBuilder) Build() (*ScheduledTaskProps, error) { func (builder *ScheduledTaskPropsBuilder) MustBuild() *ScheduledTaskProps { task, err := builder.Build() if err != nil { - panic(xerrors.Errorf("error on building ScheduledTaskProps: %w", err)) + panic(fmt.Errorf("error on building ScheduledTaskProps: %w", err)) } return task diff --git a/task_test.go b/task_test.go index e0697e1..a7f5eb8 100644 --- a/task_test.go +++ b/task_test.go @@ -2,7 +2,8 @@ package sarah import ( "context" - "golang.org/x/xerrors" + "errors" + "fmt" "strconv" "testing" ) @@ -325,11 +326,11 @@ func Test_buildScheduledTask(t *testing.T) { validateConfig: func(cfg interface{}) error { config, ok := cfg.(*DummyScheduledTaskConfig) if !ok { - return xerrors.Errorf("Unexpected type is passed: %T.", cfg) + return fmt.Errorf("unexpected type is passed: %T", cfg) } if config.ScheduleValue != "" { - return xerrors.Errorf("Unexpected value is set: %s", config.ScheduleValue) + return fmt.Errorf("unexpected value is set: %s", config.ScheduleValue) } return nil @@ -363,11 +364,11 @@ func Test_buildScheduledTask(t *testing.T) { validateConfig: func(cfg interface{}) error { config, ok := cfg.(*DummyScheduledTaskConfig) if !ok { - return xerrors.Errorf("Unexpected type is passed: %T.", cfg) + return fmt.Errorf("unexpected type is passed: %T", cfg) } if config.ScheduleValue != "@every 1m" { - return xerrors.Errorf("Unexpected value is set: %s", config.ScheduleValue) + return fmt.Errorf("unexpected value is set: %s", config.ScheduleValue) } return nil @@ -397,11 +398,11 @@ func Test_buildScheduledTask(t *testing.T) { validateConfig: func(cfg interface{}) error { config, ok := cfg.(*DummyScheduledTaskConfig) if !ok { - return xerrors.Errorf("Unexpected type is passed: %T.", cfg) + return fmt.Errorf("unexpected type is passed: %T", cfg) } if config.ScheduleValue != "" { - return xerrors.Errorf("Unexpected value is set: %s", config.ScheduleValue) + return fmt.Errorf("unexpected value is set: %s", config.ScheduleValue) } return nil @@ -436,11 +437,11 @@ func Test_buildScheduledTask(t *testing.T) { validateConfig: func(cfg interface{}) error { config, ok := cfg.(DummyScheduledTaskConfig) // Value is passed if !ok { - return xerrors.Errorf("Unexpected type is passed: %T.", cfg) + return fmt.Errorf("unexpected type is passed: %T", cfg) } if config.ScheduleValue != "@every 1m" { - return xerrors.Errorf("Unexpected value is set: %s", config.ScheduleValue) + return fmt.Errorf("unexpected value is set: %s", config.ScheduleValue) } return nil @@ -461,7 +462,7 @@ func Test_buildScheduledTask(t *testing.T) { }, watcher: &DummyConfigWatcher{ ReadFunc: func(_ context.Context, _ BotType, _ string, _ interface{}) error { - return xerrors.New("unacceptable error") + return errors.New("unacceptable error") }, }, hasErr: true, diff --git a/watcher.go b/watcher.go index 67eacd6..b3cec2c 100644 --- a/watcher.go +++ b/watcher.go @@ -2,15 +2,15 @@ package sarah import ( "context" + "errors" "fmt" - "golang.org/x/xerrors" ) // ErrWatcherNotRunning is returned when ConfigWatcher.Unwatch() is called but the context is already canceled. -var ErrWatcherNotRunning = xerrors.New("context is already canceled") +var ErrWatcherNotRunning = errors.New("context is already canceled") // ErrAlreadySubscribing is returned when duplicated calls to ConfigWatcher.Watch() occur. -var ErrAlreadySubscribing = xerrors.New("already subscribing") +var ErrAlreadySubscribing = errors.New("already subscribing") // ConfigNotFoundError is returned when corresponding configuration is not found. // This is typically returned when the caller tries to see if there is any configuration available via ConfigWatcher.Read(). diff --git a/watchers/filewatcher.go b/watchers/filewatcher.go index 9c36869..2fc17d7 100644 --- a/watchers/filewatcher.go +++ b/watchers/filewatcher.go @@ -3,11 +3,11 @@ package watchers import ( "context" "encoding/json" + "errors" "fmt" "github.com/fsnotify/fsnotify" "github.com/oklahomer/go-sarah/v3" "github.com/oklahomer/go-sarah/v3/log" - "golang.org/x/xerrors" "gopkg.in/yaml.v2" "io/ioutil" "os" @@ -36,7 +36,7 @@ type subscription struct { func NewFileWatcher(ctx context.Context, baseDir string) (sarah.ConfigWatcher, error) { fsWatcher, err := fsnotify.NewWatcher() if err != nil { - return nil, xerrors.Errorf("failed to start file watcher: %w", err) + return nil, fmt.Errorf("failed to start file watcher: %w", err) } w := &fileWatcher{ @@ -72,7 +72,7 @@ func (w *fileWatcher) Read(ctx context.Context, botType sarah.BotType, id string buf, err := ioutil.ReadFile(file.absPath) if err != nil { - return xerrors.Errorf("failed to read configuration file at %s: %w", file.absPath, err) + return fmt.Errorf("failed to read configuration file at %s: %w", file.absPath, err) } switch file.fileType { @@ -84,7 +84,7 @@ func (w *fileWatcher) Read(ctx context.Context, botType sarah.BotType, id string default: // Should never come. findPluginConfigFile guarantees that. - return xerrors.Errorf("unsupported file type: %s", file.absPath) + return fmt.Errorf("unsupported file type: %s", file.absPath) } } @@ -93,7 +93,7 @@ func (w *fileWatcher) Watch(_ context.Context, botType sarah.BotType, id string, configDir := filepath.Join(w.baseDir, botType.String()) absDir, err := filepath.Abs(configDir) if err != nil { - return xerrors.Errorf("failed to construct absolute config absPath for %s: %w", botType, err) + return fmt.Errorf("failed to construct absolute config absPath for %s: %w", botType, err) } s := &subscription{ @@ -148,7 +148,7 @@ OP: log.Infof("Received %s event for %s.", event.Op.String(), event.Name) configFile, err := plainPathToFile(event.Name) - if xerrors.Is(err, errUnableToDetermineConfigFileFormat) || xerrors.Is(err, errUnsupportedConfigFileFormat) { + if errors.Is(err, errUnableToDetermineConfigFileFormat) || errors.Is(err, errUnsupportedConfigFileFormat) { // Irrelevant file is updated continue OP } else if err != nil { @@ -236,8 +236,8 @@ const ( ) var ( - errUnableToDetermineConfigFileFormat = xerrors.New("can not determine file format") - errUnsupportedConfigFileFormat = xerrors.New("unsupported file format") + errUnableToDetermineConfigFileFormat = errors.New("can not determine file format") + errUnsupportedConfigFileFormat = errors.New("unsupported file format") configFileCandidates = []struct { ext string fileType fileType @@ -291,7 +291,7 @@ func findPluginConfigFile(configDir, id string) *pluginConfigFile { func plainPathToFile(path string) (*pluginConfigFile, error) { absPath, err := filepath.Abs(path) if err != nil { - return nil, xerrors.Errorf("failed to get absolute path of %s: %w", path, err) + return nil, fmt.Errorf("failed to get absolute path of %s: %w", path, err) } ext := filepath.Ext(absPath) diff --git a/watchers/filewatcher_test.go b/watchers/filewatcher_test.go index 213bb82..3ea494a 100644 --- a/watchers/filewatcher_test.go +++ b/watchers/filewatcher_test.go @@ -2,11 +2,11 @@ package watchers import ( "context" + "errors" "fmt" "github.com/fsnotify/fsnotify" "github.com/oklahomer/go-sarah/v3" "github.com/oklahomer/go-sarah/v3/log" - "golang.org/x/xerrors" "io/ioutil" stdLogger "log" "os" @@ -121,7 +121,7 @@ func TestFileWatcher_Watch(t *testing.T) { err error }{ { - err: xerrors.New("err"), + err: errors.New("err"), }, { err: nil, @@ -233,7 +233,7 @@ func TestFileWatcher_run(t *testing.T) { { absdir: invalidDir, id: "error", - watcherErr: xerrors.New("error"), + watcherErr: errors.New("error"), notify: nil, }, } @@ -268,7 +268,7 @@ func TestFileWatcher_run(t *testing.T) { errs := make(chan error, 1) go w.run(ctx, events, errs) go func() { - e := xerrors.New("watccher error") + e := errors.New("watcher error") for { select { case <-ctx.Done(): @@ -393,7 +393,7 @@ func TestFileWatcher_run_cancel(t *testing.T) { err error }{ { - err: xerrors.New(""), + err: errors.New(""), }, { err: nil, diff --git a/workers/worker.go b/workers/worker.go index 3c67669..f178abc 100644 --- a/workers/worker.go +++ b/workers/worker.go @@ -5,9 +5,9 @@ package workers import ( "context" + "errors" "fmt" "github.com/oklahomer/go-sarah/v3/log" - "golang.org/x/xerrors" "runtime" "strings" "time" @@ -15,10 +15,10 @@ import ( var ( // ErrEnqueueAfterWorkerShutdown is returned when job is given after worker context cancellation. - ErrEnqueueAfterWorkerShutdown = xerrors.New("job can not be enqueued after worker shutdown") + ErrEnqueueAfterWorkerShutdown = errors.New("job can not be enqueued after worker shutdown") // ErrQueueOverflow is returned when job is given, but all workers are busy and queue is full. - ErrQueueOverflow = xerrors.New("queue is full") + ErrQueueOverflow = errors.New("queue is full") ) // Config contains some configuration variables. diff --git a/workers/worker_test.go b/workers/worker_test.go index 20f2e3f..29c6f2f 100644 --- a/workers/worker_test.go +++ b/workers/worker_test.go @@ -3,9 +3,9 @@ package workers import ( "context" "encoding/json" + "errors" "fmt" "github.com/oklahomer/go-sarah/v3/log" - "golang.org/x/xerrors" "gopkg.in/yaml.v2" "io/ioutil" stdLogger "log" @@ -164,7 +164,7 @@ func TestRun_ErrEnqueueAfterShutdown(t *testing.T) { err = worker.Enqueue(func() {}) - if !xerrors.Is(err, ErrEnqueueAfterWorkerShutdown) { + if !errors.Is(err, ErrEnqueueAfterWorkerShutdown) { t.Errorf("Expected error is not returned: %+v", err) } } @@ -193,7 +193,7 @@ func TestRun_ErrQueueOverflow(t *testing.T) { // Next job should be blocked with no buffered channel. err = worker.Enqueue(func() {}) - if !xerrors.Is(err, ErrQueueOverflow) { + if !errors.Is(err, ErrQueueOverflow) { t.Errorf("Expected error is not returned: %+v", err) } }