Skip to content

Commit

Permalink
Fix some remaining lint issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Wood committed Jun 24, 2015
1 parent ef152bc commit e71644f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
3 changes: 1 addition & 2 deletions buffered_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ func (w *bufferedWorker) Push(work envelope) error {
}
}

func (w *bufferedWorker) Flush() error {
func (w *bufferedWorker) Flush() {
ch := make(chan bool)
w.ch <- func() error {
ch <- true
return nil
}
<-ch
return nil
}
10 changes: 7 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,20 @@ func (client *Client) Flush() {
}

// Notify reports the error err to the Honeybadger service.
func (client *Client) Notify(err interface{}, extra ...interface{}) string {
func (client *Client) Notify(err interface{}, extra ...interface{}) (string, error) {
extra = append([]interface{}{*client.context}, extra...)
notice := newNotice(client.Config, newError(err, 2), extra...)
client.worker.Push(func() error {
workerErr := client.worker.Push(func() error {
if err := client.Config.Backend.Notify(Notices, notice); err != nil {
return err
}
return nil
})
return notice.Token
if workerErr != nil {
client.Config.Logger.Printf("worker error: %v\n", workerErr)
return "", workerErr
}
return notice.Token, nil
}

// Monitor automatically reports panics which occur in the function it's called
Expand Down
8 changes: 4 additions & 4 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ func (e Error) Error() string {
func newError(thing interface{}, stackOffset int) Error {
var err error

switch thing := thing.(type) {
switch t := thing.(type) {
case Error:
return thing
return t
case error:
err = thing
err = t
default:
err = fmt.Errorf("%v", thing)
err = fmt.Errorf("%v", t)
}

return Error{
Expand Down
4 changes: 2 additions & 2 deletions honeybadger.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func SetContext(c Context) {
// case its formatted value will be used.
//
// It returns a string UUID which can be used to reference the error from the
// Honeybadger service.
func Notify(err interface{}, extra ...interface{}) string {
// Honeybadger service, and an error as a second argument.
func Notify(err interface{}, extra ...interface{}) (string, error) {
return client.Notify(newError(err, 2), extra...)
}

Expand Down
9 changes: 6 additions & 3 deletions honeybadger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestNotify(t *testing.T) {
setup(t)
defer teardown()

res := Notify(errors.New("Cobras!"))
res, _ := Notify(errors.New("Cobras!"))

if uuid.Parse(res) == nil {
t.Errorf("Expected Notify() to return a UUID. actual=%#v", res)
Expand Down Expand Up @@ -112,13 +112,16 @@ func TestNotifyWithContext(t *testing.T) {
// Helper functions.

func assertContext(t *testing.T, payload hash, expected Context) {
request, ok := payload["request"].(map[string]interface{})
var request, context hash
var ok bool

request, ok = payload["request"].(map[string]interface{})
if !ok {
t.Errorf("Missing request in payload actual=%#v.", payload)
return
}

context, ok := request["context"].(map[string]interface{})
context, ok = request["context"].(map[string]interface{})
if !ok {
t.Errorf("Missing context in request payload actual=%#v.", request)
return
Expand Down
10 changes: 5 additions & 5 deletions notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ func newNotice(config *Configuration, err Error, extra ...interface{}) *Notice {
}

for _, thing := range extra {
switch thing := thing.(type) {
switch t := thing.(type) {
case Context:
notice.setContext(thing)
notice.setContext(t)
case Params:
notice.Params = thing
notice.Params = t
case CGIData:
notice.CGIData = thing
notice.CGIData = t
case url.URL:
notice.URL = thing.String()
notice.URL = t.String()
}
}

Expand Down
2 changes: 1 addition & 1 deletion worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ type envelope func() error

type worker interface {
Push(envelope) error
Flush() error
Flush()
}

0 comments on commit e71644f

Please sign in to comment.