Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions auth/dialog/dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (d Dialog) Phone(ctx context.Context) (string, error) {
"",
)
if err != nil {
return "", errors.Errorf("show dialog: %w", err)
return "", errors.Wrap(err, "show dialog")
}
if !ok {
return "", errDialogClosed
Expand All @@ -60,7 +60,7 @@ func (d Dialog) Password(ctx context.Context) (string, error) {
d.printer.Sprintf(localization.PasswordDialogPrompt),
)
if err != nil {
return "", errors.Errorf("show dialog: %w", err)
return "", errors.Wrap(err, "show dialog")
}
if !ok {
return "", errDialogClosed
Expand All @@ -77,7 +77,7 @@ func (d Dialog) AcceptTermsOfService(ctx context.Context, tos tg.HelpTermsOfServ
false,
)
if err != nil {
return errors.Errorf("show dialog: %w", err)
return errors.Wrap(err, "show dialog")
}
if !ok {
return errDialogClosed
Expand All @@ -94,7 +94,7 @@ func (d Dialog) SignUp(ctx context.Context) (tgauth.UserInfo, error) {
"",
)
if err != nil {
return tgauth.UserInfo{}, errors.Errorf("show dialog: %w", err)
return tgauth.UserInfo{}, errors.Wrap(err, "show dialog")
}
if !ok {
return tgauth.UserInfo{}, errDialogClosed
Expand All @@ -106,7 +106,7 @@ func (d Dialog) SignUp(ctx context.Context) (tgauth.UserInfo, error) {
"",
)
if err != nil {
return tgauth.UserInfo{}, errors.Errorf("show dialog: %w", err)
return tgauth.UserInfo{}, errors.Wrap(err, "show dialog")
}
if !ok {
return tgauth.UserInfo{}, errDialogClosed
Expand All @@ -125,7 +125,7 @@ func (d Dialog) Code(ctx context.Context, sentCode *tg.AuthSentCode) (string, er
for {
code, ok, err := dlgs.Entry(title, prompt, "")
if err != nil {
return "", errors.Errorf("show dialog: %w", err)
return "", errors.Wrap(err, "show dialog")
}
if !ok {
return "", errDialogClosed
Expand All @@ -143,7 +143,7 @@ func (d Dialog) Code(ctx context.Context, sentCode *tg.AuthSentCode) (string, er
if len(code) != length {
_, err := dlgs.Error(title, d.printer.Sprintf(localization.CodeInvalidLength, length)+"\n")
if err != nil {
return "", errors.Errorf("write error message: %w", err)
return "", errors.Wrap(err, "write error message")
}
continue
}
Expand Down
10 changes: 5 additions & 5 deletions auth/terminal/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (t *Terminal) Code(ctx context.Context, sentCode *tg.AuthSentCode) (string,
if len(code) != length {
_, err := io.WriteString(t.Terminal, t.printer.Sprintf(localization.CodeInvalidLength, length)+"\n")
if err != nil {
return "", errors.Errorf("write error message: %w", err)
return "", errors.Wrap(err, "write error message")
}
continue
}
Expand All @@ -104,12 +104,12 @@ func (t *Terminal) Code(ctx context.Context, sentCode *tg.AuthSentCode) (string,
func (t *Terminal) SignUp(ctx context.Context) (u tgauth.UserInfo, err error) {
u.FirstName, err = t.read(t.printer.Sprintf(localization.FirstNameDialogPrompt) + ":")
if err != nil {
return u, errors.Errorf("read first name: %w", err)
return u, errors.Wrap(err, "read first name")
}

u.LastName, err = t.read(t.printer.Sprintf(localization.SecondNameDialogPrompt) + ":")
if err != nil {
return u, errors.Errorf("read first name: %w", err)
return u, errors.Wrap(err, "read first name")
}

return u, nil
Expand All @@ -120,7 +120,7 @@ func (t *Terminal) SignUp(ctx context.Context) (u tgauth.UserInfo, err error) {
func (t *Terminal) AcceptTermsOfService(ctx context.Context, tos tg.HelpTermsOfService) error {
_, err := io.WriteString(t.Terminal, t.printer.Sprintf(localization.TOSDialogTitle)+"\n\n"+tos.Text)
if err != nil {
return errors.Errorf("write terms of service: %w", err)
return errors.Wrap(err, "write terms of service")
}

t.SetPrompt(t.printer.Sprintf(localization.TOSDialogPrompt) + "(Y/N):")
Expand All @@ -129,7 +129,7 @@ func (t *Terminal) AcceptTermsOfService(ctx context.Context, tos tg.HelpTermsOfS
loop:
y, err := t.ReadLine()
if err != nil {
return errors.Errorf("read answer: %w", err)
return errors.Wrap(err, "read answer")
}
switch strings.ToLower(y) {
case "y", "yes":
Expand Down
4 changes: 2 additions & 2 deletions bbolt/auth_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import (
func bboltAuth(ctx context.Context) error {
db, err := bboltdb.Open("bbolt.db", 0666, &bboltdb.Options{}) // nolint:gocritic
if err != nil {
return errors.Errorf("create bbolt storage: %w", err)
return errors.Wrap(err, "create bbolt storage")
}
cred := bbolt.NewCredentials(db, []byte("bucket")).
WithPhoneKey("phone").
WithPasswordKey("password")

client, err := telegram.ClientFromEnvironment(telegram.Options{})
if err != nil {
return errors.Errorf("create client: %w", err)
return errors.Wrap(err, "create client")
}

return client.Run(ctx, func(ctx context.Context) error {
Expand Down
4 changes: 2 additions & 2 deletions bbolt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func (p bboltStorage) Set(ctx context.Context, k, v string) (rerr error) {
return p.db.Batch(func(tx *bbolt.Tx) error {
bucket, err := tx.CreateBucketIfNotExists(p.bucket)
if err != nil {
return errors.Errorf("create bucket: %w", err)
return errors.Wrap(err, "create bucket")
}

if err := bucket.Put([]byte(k), []byte(v)); err != nil {
return errors.Errorf("put: %w", err)
return errors.Wrap(err, "put")
}
return nil
})
Expand Down
14 changes: 7 additions & 7 deletions bbolt/peer_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (p *bboltIterator) Value() storage.Peer {
func (s PeerStorage) Iterate(ctx context.Context) (storage.PeerIterator, error) {
tx, err := s.bbolt.Begin(false)
if err != nil {
return nil, errors.Errorf("create tx: %w", err)
return nil, errors.Wrap(err, "create tx")
}

bucket := tx.Bucket(s.bucket)
Expand All @@ -93,22 +93,22 @@ func (s PeerStorage) add(associated []string, value storage.Peer) (err error) {
err = s.bbolt.Batch(func(tx *bbolt.Tx) error {
bucket, err := tx.CreateBucketIfNotExists(s.bucket)
if err != nil {
return errors.Errorf("create bucket: %w", err)
return errors.Wrap(err, "create bucket")
}

data, err := json.Marshal(value)
if err != nil {
return errors.Errorf("marshal: %w", err)
return errors.Wrap(err, "marshal")
}
id := storage.KeyFromPeer(value).Bytes(nil)

if err := bucket.Put(id, data); err != nil {
return errors.Errorf("set id <-> data: %w", err)
return errors.Wrap(err, "set id <-> data")
}

for _, key := range associated {
if err := bucket.Put([]byte(key), id); err != nil {
return errors.Errorf("set key <-> id: %w", err)
return errors.Wrap(err, "set key <-> id")
}
}

Expand Down Expand Up @@ -139,7 +139,7 @@ func (s PeerStorage) Find(ctx context.Context, key storage.PeerKey) (p storage.P
if errors.Is(err, storage.ErrPeerUnmarshalMustInvalidate) {
return storage.ErrPeerNotFound
}
return errors.Errorf("unmarshal: %w", err)
return errors.Wrap(err, "unmarshal")
}
return nil
})
Expand Down Expand Up @@ -173,7 +173,7 @@ func (s PeerStorage) Resolve(ctx context.Context, key string) (p storage.Peer, r
if errors.Is(err, storage.ErrPeerUnmarshalMustInvalidate) {
return storage.ErrPeerNotFound
}
return errors.Errorf("unmarshal: %w", err)
return errors.Wrap(err, "unmarshal")
}
return nil
})
Expand Down
4 changes: 2 additions & 2 deletions bbolt/session_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (
func bboltStorage(ctx context.Context) error {
db, err := bboltdb.Open("bbolt.db", 0666, &bboltdb.Options{}) // nolint:gocritic
if err != nil {
return errors.Errorf("create bbolt storage: %w", err)
return errors.Wrap(err, "create bbolt storage")
}
storage := bbolt.NewSessionStorage(db, "session", []byte("bucket"))

client, err := telegram.ClientFromEnvironment(telegram.Options{
SessionStorage: storage,
})
if err != nil {
return errors.Errorf("create client: %w", err)
return errors.Wrap(err, "create client")
}

return client.Run(ctx, func(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion invoker/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (h UpdateHook) Handle(next tg.Invoker) telegram.InvokeFunc {
}
if u, ok := output.(*tg.UpdatesBox); ok {
if err := h(ctx, u.Updates); err != nil {
return errors.Errorf("hook: %w", err)
return errors.Wrap(err, "hook")
}
}

Expand Down
4 changes: 2 additions & 2 deletions middleware/floodwait/flood.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
// perTypeWaitErrors is the set of code 420 errors that represent a per-method
// rate limit: every request of the same type is throttled, so the waiter may
// proactively delay future requests of that type.
var perTypeWaitErrors = []string{
var perTypeWaitErrors = []string{ // nolint:gochecknoglobals
errFloodWait,
errFloodPremiumWait,
}
Expand All @@ -50,7 +50,7 @@ var perTypeWaitErrors = []string{
// Telethon notes "SLOW_MODE_WAIT is chat-specific, not request-specific" and
// does not cache these per CONSTRUCTOR_ID; we likewise retry only the offending
// request without throttling unrelated calls of the same type.
var localWaitErrors = []string{
var localWaitErrors = []string{ // nolint:gochecknoglobals
errSlowmodeWait,
err2FAConfirmWait,
errTakeoutInitDelay,
Expand Down
6 changes: 4 additions & 2 deletions middleware/floodwait/flood_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ func TestAsWait(t *testing.T) {
wantOK: true,
},
{
name: "ClampHigh",
err: tgerr.New(420, "FLOOD_WAIT_9999999999"),
name: "ClampHigh",
// Above maxWaitSeconds but within a 32-bit int so the argument
// parses on 386 as well as 64-bit platforms.
err: tgerr.New(420, "FLOOD_WAIT_99999999"),
want: maxFloodWait,
wantPerType: true,
wantOK: true,
Expand Down
4 changes: 2 additions & 2 deletions pebble/auth_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (
func pebbleAuth(ctx context.Context) error {
db, err := pebbledb.Open("pebble.db", &pebbledb.Options{})
if err != nil {
return errors.Errorf("create pebble storage: %w", err)
return errors.Wrap(err, "create pebble storage")
}
cred := pebble.NewCredentials(db).
WithPhoneKey("phone").
WithPasswordKey("password")

client, err := telegram.ClientFromEnvironment(telegram.Options{})
if err != nil {
return errors.Errorf("create client: %w", err)
return errors.Wrap(err, "create client")
}

return client.Run(ctx, func(ctx context.Context) error {
Expand Down
18 changes: 9 additions & 9 deletions pebble/peer_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (p *pebbleIterator) Next(ctx context.Context) bool {
}

if err := json.Unmarshal(p.iter.Value(), &p.value); err != nil {
p.lastErr = errors.Errorf("unmarshal: %w", err)
p.lastErr = errors.Wrap(err, "unmarshal")
return false
}

Expand Down Expand Up @@ -95,7 +95,7 @@ func (s PeerStorage) Iterate(ctx context.Context) (storage.PeerIterator, error)
iter, err := snap.NewIter(prefixIterOptions(storage.PeerKeyPrefix))
if err != nil {
_ = snap.Close()
return nil, errors.Errorf("new iter: %w", err)
return nil, errors.Wrap(err, "new iter")
}
iter.First()

Expand All @@ -108,7 +108,7 @@ func (s PeerStorage) Iterate(ctx context.Context) (storage.PeerIterator, error)
func (s PeerStorage) add(associated []string, value storage.Peer) (rerr error) {
data, err := json.Marshal(value)
if err != nil {
return errors.Errorf("marshal: %w", err)
return errors.Wrap(err, "marshal")
}
id := storage.KeyFromPeer(value).Bytes(nil)

Expand All @@ -130,7 +130,7 @@ func (s PeerStorage) add(associated []string, value storage.Peer) (rerr error) {
}

if err := b.Commit(nil); err != nil {
return errors.Errorf("commit: %w", err)
return errors.Wrap(err, "commit")
}

return nil
Expand All @@ -150,7 +150,7 @@ func (s PeerStorage) Find(ctx context.Context, key storage.PeerKey) (_ storage.P
if errors.Is(err, pebble.ErrNotFound) {
return storage.Peer{}, storage.ErrPeerNotFound
}
return storage.Peer{}, errors.Errorf("get %q: %w", id, err)
return storage.Peer{}, errors.Wrapf(err, "get %q", id)
}
defer func() {
multierr.AppendInto(&rerr, closer.Close())
Expand All @@ -161,7 +161,7 @@ func (s PeerStorage) Find(ctx context.Context, key storage.PeerKey) (_ storage.P
if errors.Is(err, storage.ErrPeerUnmarshalMustInvalidate) {
return storage.Peer{}, storage.ErrPeerNotFound
}
return storage.Peer{}, errors.Errorf("unmarshal: %w", err)
return storage.Peer{}, errors.Wrap(err, "unmarshal")
}

return b, nil
Expand All @@ -186,7 +186,7 @@ func (s PeerStorage) Resolve(ctx context.Context, key string) (_ storage.Peer, r
if errors.Is(err, pebble.ErrNotFound) {
return storage.Peer{}, storage.ErrPeerNotFound
}
return storage.Peer{}, errors.Errorf("get %q: %w", key, err)
return storage.Peer{}, errors.Wrapf(err, "get %q", key)
}
defer func() {
multierr.AppendInto(&rerr, idCloser.Close())
Expand All @@ -198,7 +198,7 @@ func (s PeerStorage) Resolve(ctx context.Context, key string) (_ storage.Peer, r
if errors.Is(err, pebble.ErrNotFound) {
return storage.Peer{}, storage.ErrPeerNotFound
}
return storage.Peer{}, errors.Errorf("get %q: %w", id, err)
return storage.Peer{}, errors.Wrapf(err, "get %q", id)
}
defer func() {
multierr.AppendInto(&rerr, dataCloser.Close())
Expand All @@ -209,7 +209,7 @@ func (s PeerStorage) Resolve(ctx context.Context, key string) (_ storage.Peer, r
if errors.Is(err, storage.ErrPeerUnmarshalMustInvalidate) {
return storage.Peer{}, storage.ErrPeerNotFound
}
return storage.Peer{}, errors.Errorf("unmarshal: %w", err)
return storage.Peer{}, errors.Wrap(err, "unmarshal")
}

return b, nil
Expand Down
4 changes: 2 additions & 2 deletions pebble/session_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (
func pebbleStorage(ctx context.Context) error {
db, err := pebbledb.Open("pebble.db", &pebbledb.Options{})
if err != nil {
return errors.Errorf("create pebble storage: %w", err)
return errors.Wrap(err, "create pebble storage")
}
storage := pebble.NewSessionStorage(db, "session")

client, err := telegram.ClientFromEnvironment(telegram.Options{
SessionStorage: storage,
})
if err != nil {
return errors.Errorf("create client: %w", err)
return errors.Wrap(err, "create client")
}

return client.Run(ctx, func(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion redis/auth_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func redisAuth(ctx context.Context) error {

client, err := telegram.ClientFromEnvironment(telegram.Options{})
if err != nil {
return errors.Errorf("create client: %w", err)
return errors.Wrap(err, "create client")
}

return client.Run(ctx, func(ctx context.Context) error {
Expand Down
Loading
Loading