Skip to content

Commit

Permalink
Explicitly ignore error at many call sites for clarity
Browse files Browse the repository at this point in the history
Used the following:
  go get github.com/kisielk/errcheck
  errcheck -ignore 'Close|rintf' ./...

While some are irrelevant, there were some genuine issues so this is worth
enforcing, hence a few innocuous places were 'fixed' so that the list could go
down to zero.

Do not enforce this in travis yet, but should be done soon.
  • Loading branch information
maruel committed Jul 31, 2018
1 parent f34a1b4 commit 4e2dc6d
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 31 deletions.
4 changes: 3 additions & 1 deletion cmd/ir/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func mainImpl() error {
signal.Notify(ctrlC, os.Interrupt)

first := true
defer os.Stdout.Write([]byte("\n"))
defer func() {
_, _ = os.Stdout.Write([]byte("\n"))
}()
for {
select {
case msg, ok := <-c:
Expand Down
2 changes: 1 addition & 1 deletion conn/pin/pinreg/pinreg.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Register(name string, allPins [][]pin.Pin) error {
if _, ok := p.(gpio.PinIO); ok {
if err := gpioreg.RegisterAlias(name+"_"+strconv.Itoa(count), p.Name()); err != nil {
// Unregister as much as possible.
unregister(name)
_ = unregister(name)
return errors.New("pinreg: " + err.Error())
}
}
Expand Down
4 changes: 3 additions & 1 deletion devices/apa102/apa102_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,9 @@ func BenchmarkHalt(b *testing.B) {
d, _ := New(spitest.NewRecordRaw(ioutil.Discard), &DefaultOpts)
b.ResetTimer()
for i := 0; i < b.N; i++ {
d.Halt()
if err := d.Halt(); err != nil {
b.Fatal(err)
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions experimental/cmd/periph-web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func newWebServer(hostport string, state *periph.State, verbose bool) (*webServe
return nil, err
}
s.server.Addr = s.ln.Addr().String()
go s.server.Serve(s.ln)
go func() {
_ = s.server.Serve(s.ln)
}()
return s, nil
}

Expand Down Expand Up @@ -272,6 +274,6 @@ func (s *webServer) api(h interface{}) http.HandlerFunc {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Cache-Control", cacheControlNone)
w.WriteHeader(int(out[1].Int()))
w.Write(raw)
_, _ = w.Write(raw)
})
}
6 changes: 3 additions & 3 deletions experimental/cmd/periph-web/web_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *webServer) getRoot(w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("Content-Type", "text/html")
w.Header().Set("Cache-Control", cacheControlContent)
w.Write(content)
_, _ = w.Write(content)
}

// /favicon.ico
Expand All @@ -48,7 +48,7 @@ func (s *webServer) getFavicon(w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("Content-Type", "image/png")
w.Header().Set("Cache-Control", cacheControlContent)
w.Write(content)
_, _ = w.Write(content)
}

// Other handlers
Expand All @@ -63,5 +63,5 @@ func (s *webServer) apiXSRFTokenHandler(w http.ResponseWriter, r *http.Request)
w.Header().Set("Content-Type", "text/plain")
w.Header().Set("Cache-Control", cacheControlNone)
w.WriteHeader(200)
w.Write([]byte(t))
_, _ = w.Write([]byte(t))
}
5 changes: 3 additions & 2 deletions experimental/devices/mpu9250/mpu9250.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ func (m *MPU9250) Init() error {
// Calibrate Calibrates the device using maximum precision for both Gyroscope and Accelerometer.
func (m *MPU9250) Calibrate() error {

m.transferBatch(calibrateSequence, "error calibrating %d: [%x:%x] => %v")

if err := m.transferBatch(calibrateSequence, "error calibrating %d: [%x:%x] => %v"); err != nil {
return err
}
reads, err := m.GetFIFOCount() // read FIFO sample count
if err != nil {
return wrapf("can't get FIFO => %v", err)
Expand Down
3 changes: 1 addition & 2 deletions experimental/devices/unicornhd/unicornhd.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ func (device *Dev) String() string {
// Halting the unicorn HD sets all the pixels to black. Error is always nil.
func (device *Dev) Halt() error {
black := color.RGBA{0, 0, 0, 0}
device.Draw(device.Bounds(), &image.Uniform{black}, image.ZP)
return nil
return device.Draw(device.Bounds(), &image.Uniform{black}, image.ZP)
}

// ColorModel implements devices.Display. There's no surprise, it is
Expand Down
24 changes: 15 additions & 9 deletions experimental/devices/unicornhd/unicornhd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ func TestHalt(t *testing.T) {
}
buf := bytes.Buffer{}
dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf))

dev.Halt()
if err := dev.Halt(); err != nil {
t.Fatal(err)
}

if !bytes.Equal(expectedAllBlack, buf.Bytes()) {
t.Fatalf("%#v != %#v", expectedAllBlack, buf.Bytes())
Expand Down Expand Up @@ -163,8 +164,9 @@ func TestDrawWritesBlackImageToSpi(t *testing.T) {
buf := bytes.Buffer{}
dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf))
black := color.RGBA{0, 0, 0, 0}

dev.Draw(dev.Bounds(), &image.Uniform{black}, image.ZP)
if err := dev.Draw(dev.Bounds(), &image.Uniform{black}, image.ZP); err != nil {
t.Fatal(err)
}

if !bytes.Equal(expectedAllBlack, buf.Bytes()) {
t.Fatalf("%#v != %#v", expectedAllBlack, buf.Bytes())
Expand Down Expand Up @@ -217,8 +219,9 @@ func TestDrawWritesWhiteImageToSpi(t *testing.T) {
buf := bytes.Buffer{}
dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf))
white := color.RGBA{255, 255, 255, 255}

dev.Draw(dev.Bounds(), &image.Uniform{white}, image.ZP)
if err := dev.Draw(dev.Bounds(), &image.Uniform{white}, image.ZP); err != nil {
t.Fatal(err)
}

if !bytes.Equal(expectedAllWhite, buf.Bytes()) {
t.Fatalf("%#v != %#v", expectedAllWhite, buf.Bytes())
Expand Down Expand Up @@ -288,7 +291,9 @@ func TestDrawWritesSequenceImageToSpi(t *testing.T) {
img.Set(x, y, clr)
}
}
dev.Draw(dev.Bounds(), img, image.ZP)
if err := dev.Draw(dev.Bounds(), img, image.ZP); err != nil {
t.Fatal(err)
}

if !bytes.Equal(expectedSequence, buf.Bytes()) {
t.Fatalf("%#v != %#v", expectedSequence, buf.Bytes())
Expand Down Expand Up @@ -349,8 +354,9 @@ func TestDrawSupportsPartialUpdates(t *testing.T) {
buf := bytes.Buffer{}
dev, _ := NewUnicornhd(spitest.NewRecordRaw(&buf))
white := color.RGBA{0xFF, 0xFF, 0xFF, 0xFF}

dev.Draw(image.Rect(0, 0, 3, 3), &image.Uniform{white}, image.ZP)
if err := dev.Draw(image.Rect(0, 0, 3, 3), &image.Uniform{white}, image.ZP); err != nil {
t.Fatal(err)
}

if !bytes.Equal(expectedWhiteSquare, buf.Bytes()) {
t.Fatalf("%#v != %#v", expectedWhiteSquare, buf.Bytes())
Expand Down
4 changes: 3 additions & 1 deletion host/allwinner/dma.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ func smokeTest() error {
drvDMA.dmaMemory.irqEn &^= 3 << uint(2*n+16)
drvDMA.dmaMemory.irqPendStas = 3 << uint(2*n+16)
ch := &drvDMA.dmaMemory.dedicated[n]
defer ch.release()
defer func() {
_ = ch.release()
}()
ch.set(uint32(pSrc), uint32(pDst)+holeSize, 4096-2*holeSize, false, false, ddmaDstDrqSDRAM|ddmaSrcDrqSDRAM)

for ch.cfg&ddmaBusy != 0 {
Expand Down
12 changes: 8 additions & 4 deletions host/bcm283x/bcm283xsmoketest/bcm283xsmoketest.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,15 @@ func (s *SmokeTest) testPWM(p1, p2 *loggingPin) error {
}

// testStreamIn tests gpiostream.StreamIn and gpio.PWM.
func (s *SmokeTest) testStreamIn(p1, p2 *loggingPin) error {
func (s *SmokeTest) testStreamIn(p1, p2 *loggingPin) (err error) {
const freq = 5 * physic.KiloHertz
fmt.Printf("- Testing StreamIn\n")
defer p2.Halt()
if err := p2.PWM(gpio.DutyHalf, freq); err != nil {
defer func() {
if err2 := p2.Halt(); err == nil {
err = err2
}
}()
if err = p2.PWM(gpio.DutyHalf, freq); err != nil {
return err
}
// Gather 0.1 second of readings at 10kHz sampling rate.
Expand All @@ -175,7 +179,7 @@ func (s *SmokeTest) testStreamIn(p1, p2 *loggingPin) error {
Freq: freq * 2,
LSBF: true,
}
if err := p1.StreamIn(gpio.PullDown, b); err != nil {
if err = p1.StreamIn(gpio.PullDown, b); err != nil {
fmt.Printf("%s\n", hex.EncodeToString(b.Bits))
return err
}
Expand Down
6 changes: 3 additions & 3 deletions host/bcm283x/dma.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,19 +694,19 @@ func dmaWriteStreamPCM(p *Pin, w gpiostream.Stream) error {
}
defer pCB.Close()
reg := drvDMA.pcmBaseAddr + 0x4 // pcmMap.fifo
if err := cb[0].initBlock(uint32(buf.PhysAddr()), reg, uint32(l), false, true, true, false, dmaPCMTX); err != nil {
if err = cb[0].initBlock(uint32(buf.PhysAddr()), reg, uint32(l), false, true, true, false, dmaPCMTX); err != nil {
return err
}

defer drvDMA.pcmMemory.reset()
// Start transfer
drvDMA.pcmMemory.set()
runIO(pCB, l <= maxLite)
err = runIO(pCB, l <= maxLite)
// We have to wait PCM to be finished even after DMA finished.
for drvDMA.pcmMemory.cs&pcmTXErr == 0 {
Nanospin(10 * time.Nanosecond)
}
return nil
return err
}

func dmaWritePWMFIFO() (*dmaChannel, *videocore.Mem, error) {
Expand Down
4 changes: 3 additions & 1 deletion host/bcm283x/dma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ func TestCopyStreamToDMAbuf(t *testing.T) {
Freq: physic.KiloHertz,
LSBF: false,
}
copyStreamToDMABuf(&stream, buf)
if err := copyStreamToDMABuf(&stream, buf); err != nil {
t.Fatal(err)
}
if buf[0] != 0x01020304 {
t.Fatalf("Unexpected 0x%x != 0x%x", buf[0], 0x01020304)
}
Expand Down
3 changes: 2 additions & 1 deletion host/sysfs/thermal_sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func (t *ThermalSensor) SenseContinuous(interval time.Duration) (<-chan physic.E
func (t *ThermalSensor) Precision(e *physic.Env) {
if t.precision == 0 {
dummy := physic.Env{}
t.Sense(&dummy)
// Ignore the error.
_ = t.Sense(&dummy)
}
t.mu.Lock()
defer t.mu.Unlock()
Expand Down

0 comments on commit 4e2dc6d

Please sign in to comment.