Skip to content

Commit

Permalink
all: use errors from the standard library
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed Jan 22, 2022
1 parent f2a7d45 commit be2933a
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 22 deletions.
7 changes: 3 additions & 4 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package telebot
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
Expand All @@ -12,8 +13,6 @@ import (
"strconv"
"strings"
"time"

"github.com/pkg/errors"
)

// Raw lets you call any method of Bot API manually.
Expand Down Expand Up @@ -73,7 +72,7 @@ func (b *Bot) sendFiles(method string, files map[string]File, params map[string]
case f.FileReader != nil:
rawFiles[name] = f.FileReader
default:
return nil, errors.Errorf("telebot: file for field %s doesn't exist", name)
return nil, fmt.Errorf("telebot: file for field %s doesn't exist", name)
}
}

Expand Down Expand Up @@ -140,7 +139,7 @@ func addFileToWriter(writer *multipart.Writer, filename, field string, file inte
defer f.Close()
reader = f
} else {
return errors.Errorf("telebot: file for field %v should be io.ReadCloser or string", field)
return fmt.Errorf("telebot: file for field %v should be io.ReadCloser or string", field)
}

part, err := writer.CreateFormFile(field, filename)
Expand Down
8 changes: 3 additions & 5 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"regexp"
"strconv"
"strings"

"github.com/pkg/errors"
)

// NewBot does try to build a Bot with token `token`, which
Expand Down Expand Up @@ -600,7 +598,7 @@ func (b *Bot) SendAlbum(to Recipient, a Album, opts ...interface{}) ([]Message,
repr = "attach://" + strconv.Itoa(i)
files[strconv.Itoa(i)] = *file
default:
return nil, errors.Errorf("telebot: album entry #%d does not exist", i)
return nil, fmt.Errorf("telebot: album entry #%d does not exist", i)
}

im := x.InputMedia()
Expand Down Expand Up @@ -890,7 +888,7 @@ func (b *Bot) EditMedia(msg Editable, media Inputtable, opts ...interface{}) (*M
repr = "attach://" + s
files[s] = *file
default:
return nil, errors.Errorf("telebot: cannot edit media, it does not exist")
return nil, fmt.Errorf("telebot: cannot edit media, it does not exist")
}

switch m := media.(type) {
Expand Down Expand Up @@ -1152,7 +1150,7 @@ func (b *Bot) File(file *File) (io.ReadCloser, error) {

if resp.StatusCode != http.StatusOK {
resp.Body.Close()
return nil, errors.Errorf("telebot: expected status 200 but got %s", resp.Status)
return nil, fmt.Errorf("telebot: expected status 200 but got %s", resp.Status)
}

return resp.Body, nil
Expand Down
3 changes: 1 addition & 2 deletions context.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package telebot

import (
"errors"
"strings"
"sync"
"time"

"github.com/pkg/errors"
)

// HandlerFunc represents a handler function, which is
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/fatih/color v1.13.0 // indirect
github.com/goccy/go-yaml v1.9.5
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/pkg/errors v0.9.1
github.com/spf13/cast v1.3.1
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
Expand Down
4 changes: 1 addition & 3 deletions inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package telebot
import (
"encoding/json"
"fmt"

"github.com/pkg/errors"
)

// Query is an incoming inline query. When the user sends
Expand Down Expand Up @@ -134,7 +132,7 @@ func inferIQR(result Result) error {
case *StickerResult:
r.Type = "sticker"
default:
return errors.Errorf("telebot: result %v is not supported", result)
return fmt.Errorf("telebot: result %v is not supported", result)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion telebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//
package telebot

import "github.com/pkg/errors"
import "errors"

var (
ErrBadRecipient = errors.New("telebot: recipient is nil")
Expand Down
6 changes: 2 additions & 4 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"log"
"net/http"
"strconv"

"github.com/pkg/errors"
)

var defaultOnError = func(err error, c Context) {
Expand All @@ -24,7 +22,7 @@ func (b *Bot) deferDebug() {
if err, ok := r.(error); ok {
b.debug(err)
} else if str, ok := r.(string); ok {
b.debug(errors.Errorf("%s", str))
b.debug(fmt.Errorf("%s", str))
}
}
}
Expand Down Expand Up @@ -52,7 +50,7 @@ func applyMiddleware(h HandlerFunc, middleware ...MiddlewareFunc) HandlerFunc {

// wrapError returns new wrapped telebot-related error.
func wrapError(err error) error {
return errors.Wrap(err, "telebot")
return fmt.Errorf("telebot: %w", err)
}

// extractOk checks given result for error. If result is ok returns nil.
Expand Down

0 comments on commit be2933a

Please sign in to comment.