all: use errors from the standard library

pull/452/head
Demian 2 years ago
parent f2a7d458a0
commit be2933a4fa

@ -3,6 +3,7 @@ package telebot
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
@ -12,8 +13,6 @@ import (
"strconv"
"strings"
"time"
"github.com/pkg/errors"
)
// Raw lets you call any method of Bot API manually.
@ -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)
}
}
@ -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)

@ -9,8 +9,6 @@ import (
"regexp"
"strconv"
"strings"
"github.com/pkg/errors"
)
// NewBot does try to build a Bot with token `token`, which
@ -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()
@ -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) {
@ -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

@ -1,11 +1,10 @@
package telebot
import (
"errors"
"strings"
"sync"
"time"
"github.com/pkg/errors"
)
// HandlerFunc represents a handler function, which is

@ -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

@ -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=

@ -3,8 +3,6 @@ package telebot
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
)
// Query is an incoming inline query. When the user sends
@ -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

@ -27,7 +27,7 @@
//
package telebot
import "github.com/pkg/errors"
import "errors"
var (
ErrBadRecipient = errors.New("telebot: recipient is nil")

@ -7,8 +7,6 @@ import (
"log"
"net/http"
"strconv"
"github.com/pkg/errors"
)
var defaultOnError = func(err error, c Context) {
@ -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))
}
}
}
@ -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.

Loading…
Cancel
Save