Skip to content

Commit

Permalink
Move util.IgnoreError to errorutil.IgnoreErrror
Browse files Browse the repository at this point in the history
 -Part of Mesos-DNS#223, to be explicit about ignoring errors
  • Loading branch information
sargun committed Nov 16, 2015
1 parent ada9e7e commit 7d0d3ea
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
12 changes: 12 additions & 0 deletions errorutil/errorutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package errorutil

// ErrorFunction A function definition that returns an error
// to be passed to the Ignore or Panic error handler
type ErrorFunction func() error

// IgnoreError Calls an ErrorFunction, and ignores the result.
// This allows us to be more explicit when there is no error
// handling to be done, for example in defers
func IgnoreError(f ErrorFunction) {
_ = f()
}
4 changes: 2 additions & 2 deletions records/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"strings"
"time"

"github.com/mesosphere/mesos-dns/errorutil"
"github.com/mesosphere/mesos-dns/logging"
"github.com/mesosphere/mesos-dns/records/labels"
"github.com/mesosphere/mesos-dns/records/state"
"github.com/mesosphere/mesos-dns/util"
)

// Map host/service name to DNS answer
Expand Down Expand Up @@ -138,7 +138,7 @@ func (rg *RecordGenerator) loadFromMaster(ip string, port string) (state.State,
return state.State{}, err
}

defer util.IgnoreError(resp.Body.Close)
defer errorutil.IgnoreError(resp.Body.Close)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
logging.Error.Println(err)
Expand Down
11 changes: 0 additions & 11 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,3 @@ func logPanic(r interface{}) {
}
log.Printf("Recovered from panic: %#v (%v)\n%v", r, r, callers)
}

// ErrorFunction A function definition that returns an error
// to be passed to the Ignore or Panic error handler
type ErrorFunction func() error

// IgnoreError Calls an ErrorFunction, and ignores the result.
// This allows us to be more explicit when there is no error
// handling to be done, for example in defers
func IgnoreError(f ErrorFunction) {
_ = f()
}
15 changes: 0 additions & 15 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package util

import (
"errors"
"testing"
)

Expand Down Expand Up @@ -53,17 +52,3 @@ func TestCustomHandleCrash(t *testing.T) {
t.Errorf("did not receive custom handler")
}
}

func returnsError() error {
return errors.New("test")
}
func TestIgnoreHandler(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Fatal("IgnoreHandler did not ignore Error")
}
}()

IgnoreError(returnsError)

}

0 comments on commit 7d0d3ea

Please sign in to comment.