Skip to content

Commit

Permalink
pkg/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed May 17, 2017
1 parent 366a7e1 commit b935d82
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 14 deletions.
5 changes: 2 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ type Config struct {

// Get the config
func Get() (cfg Config) {
var err = env.Parse(&cfg)
if err != nil {
log.WithError(err).Fatal("failed to laod config")
if err := env.Parse(&cfg); err != nil {
log.WithError(err).Fatal("failed to load config")
}
return
}
3 changes: 2 additions & 1 deletion datastore/database/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -48,7 +49,7 @@ func (db *Tokenstore) Schedule(userID int64, date time.Time) error {
func tokenToJSON(token *oauth2.Token) (string, error) {
d, err := json.Marshal(token)
if err != nil {
return "", err
return "", errors.Wrap(err, "failed to marshall json token")
}
return string(d), nil
}
4 changes: 2 additions & 2 deletions github/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package email

import (
"context"
"errors"

"github.com/google/go-github/github"
"github.com/pkg/errors"
)

// Get the primary and verified user email
func Get(ctx context.Context, client *github.Client) (email string, err error) {
emails, _, err := client.Users.ListEmails(ctx, &github.ListOptions{PerPage: 10})
if err != nil {
return
return email, errors.Wrap(err, "failed to get current user email addresses")
}
for _, e := range emails {
if *e.Primary && *e.Verified {
Expand Down
3 changes: 2 additions & 1 deletion github/followers/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/google/go-github/github"
"github.com/pkg/errors"
)

// Get the list of followers of a given user
Expand All @@ -15,7 +16,7 @@ func Get(
for {
followers, nextPage, err := getPage(ctx, client, opt)
if err != nil {
return result, err
return result, errors.Wrap(err, "failed to get followers")
}
result = append(result, followers...)
if opt.Page = nextPage; nextPage == 0 {
Expand Down
3 changes: 2 additions & 1 deletion github/repos/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/google/go-github/github"
"github.com/pkg/errors"
)

// Get all user's repos
Expand All @@ -17,7 +18,7 @@ func Get(
for {
repos, nextPage, err := getPage(ctx, client, opt)
if err != nil {
return result, err
return result, errors.Wrap(err, "failed to get repositories")
}
for _, repo := range repos {
if repo.GetFork() || repo.GetPrivate() {
Expand Down
3 changes: 2 additions & 1 deletion github/stargazers/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/caarlos0/watchub/shared/model"
"github.com/google/go-github/github"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)

Expand All @@ -22,7 +23,7 @@ func Get(
g.Go(func() error {
r, er := processRepo(ctx, client, repo)
if er != nil {
return er
return errors.Wrap(er, "failed to get repository stars")
}
m.Lock()
defer m.Unlock()
Expand Down
6 changes: 3 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import:
- errgroup
- package: github.com/gorilla/sessions
version: v1.1
- package: github.com/pkg/errors
version: ~0.8.0
testImport:
- package: github.com/stretchr/testify
version: v1.1.4
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,7 @@ func main() {
ReadTimeout: 15 * time.Second,
}
log.WithField("addr", server.Addr).Info("started")
log.WithError(server.ListenAndServe()).Error("failed to start up server")
if err := server.ListenAndServe(); err != nil {
log.WithError(err).Fatal("failed to start up server")
}
}
4 changes: 3 additions & 1 deletion shared/token/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package token
import (
"encoding/json"

"github.com/pkg/errors"
"golang.org/x/oauth2"
)

// FromJSON extract an oauth from a json string
func FromJSON(str string) (*oauth2.Token, error) {
var token oauth2.Token
if err := json.Unmarshal([]byte(str), &token); err != nil {
return nil, err
return nil, errors.Wrap(err, "failed unmarshall json token")
}
return &token, nil
}

0 comments on commit b935d82

Please sign in to comment.