diff --git a/ci/run-tests.go b/ci/run-tests.go index 051e6062b5db2609e610d95b0d0296a6923d74e5..64096c0ec4c3a6e2443ee55b0af56228997c93ea 100644 --- a/ci/run-tests.go +++ b/ci/run-tests.go @@ -10,14 +10,13 @@ import ( "bufio" "bytes" "flag" + "fmt" "io/ioutil" "log" "os" "os/exec" "strings" "time" - - "golang.org/x/xerrors" ) func main() { @@ -106,7 +105,7 @@ func pkgList() ([]string, error) { err := cmd.Run() if err != nil { - return nil, xerrors.Errorf("could not get package list: %w", err) + return nil, fmt.Errorf("could not get package list: %w", err) } var pkgs []string diff --git a/cmd/dif-dump/main.go b/cmd/dif-dump/main.go index 7d33a293a62014dd95888988524c31a6aad51166..6e221c266656961960839051a73d8d2e9fe6efd0 100644 --- a/cmd/dif-dump/main.go +++ b/cmd/dif-dump/main.go @@ -23,6 +23,7 @@ package main import ( + "errors" "flag" "fmt" "io" @@ -30,7 +31,6 @@ import ( "os" "github.com/go-lpc/mim/dif" - "golang.org/x/xerrors" ) func main() { @@ -79,7 +79,7 @@ Example: func process(w io.Writer, fname string) error { f, err := os.Open(fname) if err != nil { - return xerrors.Errorf("could not open %q: %w", fname, err) + return fmt.Errorf("could not open %q: %w", fname, err) } defer f.Close() @@ -89,10 +89,10 @@ loop: var d dif.DIF err := dec.Decode(&d) if err != nil { - if xerrors.Is(err, io.EOF) { + if errors.Is(err, io.EOF) { break loop } - return xerrors.Errorf("could not decode DIF: %w", err) + return fmt.Errorf("could not decode DIF: %w", err) } fmt.Fprintf(w, "=== DIF-ID 0x%x ===\n", d.Header.ID) fmt.Fprintf(w, "DIF trigger: % 10d\n", d.Header.DTC) diff --git a/cmd/dif-dump/main_test.go b/cmd/dif-dump/main_test.go index 07b1381e6d52f9b604c2f3d095f303dba4f94a96..0bf4dcdb01731815dfe4260e30d512fedcf14021 100644 --- a/cmd/dif-dump/main_test.go +++ b/cmd/dif-dump/main_test.go @@ -5,6 +5,7 @@ package main import ( + "fmt" "io" "io/ioutil" "os" @@ -13,7 +14,6 @@ import ( "testing" "github.com/go-lpc/mim/dif" - "golang.org/x/xerrors" ) func TestDump(t *testing.T) { @@ -71,7 +71,7 @@ Frames: 2 name: "invalid-dif", data: dif.DIF{}, want: string([]byte{0xb0, 0x42}), - err: xerrors.Errorf("could not decode DIF: dif: could not read DIF header: %w", io.ErrUnexpectedEOF), + err: fmt.Errorf("could not decode DIF: dif: could not read DIF header: %w", io.ErrUnexpectedEOF), }, } { t.Run(tc.name, func(t *testing.T) { diff --git a/dif/decoder.go b/dif/decoder.go index a400e778b40bc4902f2d00c3e9ee85f828e0e5e2..9dfc078448f269374f228f93399aabfbd57f60a9 100644 --- a/dif/decoder.go +++ b/dif/decoder.go @@ -6,10 +6,11 @@ package dif import ( "encoding/binary" + "errors" + "fmt" "io" "github.com/go-lpc/mim/internal/crc16" - "golang.org/x/xerrors" ) // Decoder reads and decodes DIF data from an input stream. @@ -49,12 +50,12 @@ func (dec *Decoder) Decode(dif *DIF) error { v := dec.readU8() if dec.err != nil { - return xerrors.Errorf("dif: could not read global header marker: %w", dec.err) + return fmt.Errorf("dif: could not read global header marker: %w", dec.err) } switch v { case gbHeader, gbHeaderB: // global header. ok default: - return xerrors.Errorf("dif: could not read global header marker (got=0x%x)", v) + return fmt.Errorf("dif: could not read global header marker (got=0x%x)", v) } dec.crcU8(v) @@ -69,13 +70,13 @@ func (dec *Decoder) Decode(dif *DIF) error { dec.read(hdr) if dec.err != nil { - return xerrors.Errorf("dif: could not read DIF header: %w", dec.err) + return fmt.Errorf("dif: could not read DIF header: %w", dec.err) } dec.crcw(hdr) difID := hdr[0] if difID != dec.dif { - return xerrors.Errorf("dif: invalid DIF ID (got=0x%x, want=0x%x)", difID, dec.dif) + return fmt.Errorf("dif: invalid DIF ID (got=0x%x, want=0x%x)", difID, dec.dif) } dif.Header.ID = hdr[0] @@ -98,7 +99,7 @@ loop: for { v := dec.readU8() if dec.err != nil { - return xerrors.Errorf( + return fmt.Errorf( "dif: DIF 0x%x could not read frame header/global trailer: %w", dec.dif, dec.err, ) @@ -107,21 +108,21 @@ loop: switch v { default: - return xerrors.Errorf("dif: DIF 0x%x invalid frame/global marker (got=0x%x)", dec.dif, v) + return fmt.Errorf("dif: DIF 0x%x invalid frame/global marker (got=0x%x)", dec.dif, v) case anHeader: // analog frame header. not supported. - return xerrors.Errorf("dif: DIF 0x%x contains an analog frame", dec.dif) + return fmt.Errorf("dif: DIF 0x%x contains an analog frame", dec.dif) case frHeader: frameLoop: for { v := dec.readU8() if dec.err != nil { - if xerrors.Is(dec.err, io.EOF) { + if errors.Is(dec.err, io.EOF) { dec.err = io.ErrUnexpectedEOF } - return xerrors.Errorf( + return fmt.Errorf( "dif: DIF 0x%x could not read frame trailer/hardroc header: %w", dec.dif, dec.err, ) @@ -132,7 +133,7 @@ loop: dec.crcU8(v) dec.read(hrData) if dec.err != nil { - return xerrors.Errorf( + return fmt.Errorf( "dif: DIF 0x%x could not read hardroc frame: %w", dec.dif, dec.err, ) @@ -146,7 +147,7 @@ loop: dif.Frames = append(dif.Frames, frame) case incFrame: - return xerrors.Errorf("dif: DIF 0x%x received an incomplete frame", dec.dif) + return fmt.Errorf("dif: DIF 0x%x received an incomplete frame", dec.dif) case frTrailer: dec.crcU8(v) @@ -160,14 +161,14 @@ loop: recvCRC = dec.readU16() ) if dec.err != nil { - return xerrors.Errorf( + return fmt.Errorf( "dif: DIF 0x%x could not receive CRC-16: %w", dec.dif, dec.err, ) } if compCRC != recvCRC { - return xerrors.Errorf( + return fmt.Errorf( "dif: DIF 0x%x inconsistent CRC: recv=0x%04x comp=0x%04x", dec.dif, recvCRC, compCRC, ) diff --git a/dif/device.go b/dif/device.go index 4429f1db5d8b2687b0116b5a99097142087eb7f3..f269cb2a5d31ea6ed4fe74e2577955d27fda85fb 100644 --- a/dif/device.go +++ b/dif/device.go @@ -6,10 +6,10 @@ package dif import ( "encoding/binary" + "fmt" "io" "github.com/ziutek/ftdi" - "golang.org/x/xerrors" ) type ftdiDevice interface { @@ -45,14 +45,14 @@ func ftdiOpenImpl(vid, pid uint16) (ftdiDevice, error) { func newDevice(vid, pid uint16) (*device, error) { ft, err := ftdiOpen(vid, pid) if err != nil { - return nil, xerrors.Errorf("could not open FTDI device (vid=0x%x, pid=0x%x): %w", vid, pid, err) + return nil, fmt.Errorf("could not open FTDI device (vid=0x%x, pid=0x%x): %w", vid, pid, err) } dev := &device{vid: vid, pid: pid, ft: ft} err = dev.init() if err != nil { ft.Close() - return nil, xerrors.Errorf("could not initialize FTDI device (vid=0x%x, pid=0x%x): %w", vid, pid, err) + return nil, fmt.Errorf("could not initialize FTDI device (vid=0x%x, pid=0x%x): %w", vid, pid, err) } return dev, nil @@ -63,44 +63,44 @@ func (dev *device) init() error { err = dev.ft.Reset() if err != nil { - return xerrors.Errorf("could not reset USB: %w", err) + return fmt.Errorf("could not reset USB: %w", err) } err = dev.ft.SetBitmode(0, ftdi.ModeBitbang) if err != nil { - return xerrors.Errorf("could not disable bitbang: %w", err) + return fmt.Errorf("could not disable bitbang: %w", err) } err = dev.ft.SetFlowControl(ftdi.FlowCtrlDisable) if err != nil { - return xerrors.Errorf("could not disable flow control: %w", err) + return fmt.Errorf("could not disable flow control: %w", err) } err = dev.ft.SetLatencyTimer(2) if err != nil { - return xerrors.Errorf("could not set latency timer to 2: %w", err) + return fmt.Errorf("could not set latency timer to 2: %w", err) } err = dev.ft.SetWriteChunkSize(0xffff) if err != nil { - return xerrors.Errorf("could not set write chunk-size to 0xffff: %w", err) + return fmt.Errorf("could not set write chunk-size to 0xffff: %w", err) } err = dev.ft.SetReadChunkSize(0xffff) if err != nil { - return xerrors.Errorf("could not set read chunk-size to 0xffff: %w", err) + return fmt.Errorf("could not set read chunk-size to 0xffff: %w", err) } if dev.pid == 0x6014 { err = dev.ft.SetBitmode(0, ftdi.ModeReset) if err != nil { - return xerrors.Errorf("could not reset bit mode: %w", err) + return fmt.Errorf("could not reset bit mode: %w", err) } } err = dev.ft.PurgeBuffers() if err != nil { - return xerrors.Errorf("could not purge USB buffers: %w", err) + return fmt.Errorf("could not purge USB buffers: %w", err) } return err @@ -117,14 +117,14 @@ func (dev *device) usbRegRead(addr uint32) (uint32, error) { n, err := dev.ft.Write(p[:2]) switch { case err != nil: - return 0, xerrors.Errorf("could not write USB addr 0x%x: %w", addr, err) + return 0, fmt.Errorf("could not write USB addr 0x%x: %w", addr, err) case n != len(p[:2]): - return 0, xerrors.Errorf("could not write USB addr 0x%x: %w", addr, io.ErrShortWrite) + return 0, fmt.Errorf("could not write USB addr 0x%x: %w", addr, io.ErrShortWrite) } _, err = io.ReadFull(dev.ft, p) if err != nil { - return 0, xerrors.Errorf("could not read register 0x%x: %w", addr, err) + return 0, fmt.Errorf("could not read register 0x%x: %w", addr, err) } v := binary.BigEndian.Uint32(p) @@ -138,9 +138,9 @@ func (dev *device) usbCmdWrite(cmd uint32) error { n, err := dev.ft.Write(buf) switch { case err != nil: - return xerrors.Errorf("could not write USB command 0x%x: %w", cmd, err) + return fmt.Errorf("could not write USB command 0x%x: %w", cmd, err) case n != len(buf): - return xerrors.Errorf("could not write USB command 0x%x: %w", cmd, io.ErrShortWrite) + return fmt.Errorf("could not write USB command 0x%x: %w", cmd, io.ErrShortWrite) } return nil @@ -159,9 +159,9 @@ func (dev *device) usbRegWrite(addr, v uint32) error { n, err := dev.ft.Write(p) switch { case err != nil: - return xerrors.Errorf("could not write USB register (0x%x, 0x%x): %w", addr, v, err) + return fmt.Errorf("could not write USB register (0x%x, 0x%x): %w", addr, v, err) case n != len(p): - return xerrors.Errorf("could not write USB register (0x%x, 0x%x): %w", addr, v, io.ErrShortWrite) + return fmt.Errorf("could not write USB register (0x%x, 0x%x): %w", addr, v, io.ErrShortWrite) } return nil } @@ -186,19 +186,19 @@ func (dev *device) difCptReset() error { const addr = 0x03 v, err := dev.usbRegRead(addr) if err != nil { - return xerrors.Errorf("could not read register 0x%x", addr) + return fmt.Errorf("could not read register 0x%x", addr) } v |= 0x2000 err = dev.usbRegWrite(addr, v) if err != nil { - return xerrors.Errorf("could not write to register 0x%x", addr) + return fmt.Errorf("could not write to register 0x%x", addr) } v &= 0xffffdfff err = dev.usbRegWrite(addr, v) if err != nil { - return xerrors.Errorf("could not write to register 0x%x", addr) + return fmt.Errorf("could not write to register 0x%x", addr) } return nil diff --git a/dif/device_test.go b/dif/device_test.go index b6237a87e2305b4ba9e94e70e758be0c1619ff43..87d9cf317be3b1b9f825fddc9755b29a1867817c 100644 --- a/dif/device_test.go +++ b/dif/device_test.go @@ -5,10 +5,9 @@ package dif import ( + "fmt" "io" "testing" - - "golang.org/x/xerrors" ) func TestFTDIOpen(t *testing.T) { @@ -72,7 +71,7 @@ func TestDevice(t *testing.T) { _, err := dev.usbRegRead(0x1234) return err }, - want: xerrors.Errorf("could not write USB addr 0x%x: %w", 0x1234, io.EOF), + want: fmt.Errorf("could not write USB addr 0x%x: %w", 0x1234, io.EOF), }, { name: "usbRegRead-short-write", @@ -81,7 +80,7 @@ func TestDevice(t *testing.T) { _, err := dev.usbRegRead(0x1234) return err }, - want: xerrors.Errorf("could not write USB addr 0x%x: %w", 0x1234, io.ErrShortWrite), + want: fmt.Errorf("could not write USB addr 0x%x: %w", 0x1234, io.ErrShortWrite), }, { name: "usbRegRead-err-read", @@ -91,7 +90,7 @@ func TestDevice(t *testing.T) { _, err := dev.usbRegRead(0x1234) return err }, - want: xerrors.Errorf("could not read register 0x%x: %w", 0x1234, io.ErrUnexpectedEOF), + want: fmt.Errorf("could not read register 0x%x: %w", 0x1234, io.ErrUnexpectedEOF), }, { name: "usbCmdWrite-eof", @@ -99,7 +98,7 @@ func TestDevice(t *testing.T) { rw.ws = append(rw.ws, ierr{0, io.EOF}) return dev.usbCmdWrite(0x1234) }, - want: xerrors.Errorf("could not write USB command 0x%x: %w", 0x1234, io.EOF), + want: fmt.Errorf("could not write USB command 0x%x: %w", 0x1234, io.EOF), }, { name: "usbCmdWrite-short-write", @@ -107,7 +106,7 @@ func TestDevice(t *testing.T) { rw.ws = append(rw.ws, ierr{1, nil}) return dev.usbCmdWrite(0x1234) }, - want: xerrors.Errorf("could not write USB command 0x%x: %w", 0x1234, io.ErrShortWrite), + want: fmt.Errorf("could not write USB command 0x%x: %w", 0x1234, io.ErrShortWrite), }, { name: "usbRegWrite-eof", @@ -115,7 +114,7 @@ func TestDevice(t *testing.T) { rw.ws = append(rw.ws, ierr{0, io.EOF}) return dev.usbRegWrite(0x1234, 0x255) }, - want: xerrors.Errorf("could not write USB register (0x%x, 0x%x): %w", 0x1234, 0x255, io.EOF), + want: fmt.Errorf("could not write USB register (0x%x, 0x%x): %w", 0x1234, 0x255, io.EOF), }, { name: "usbRegWrite-short-write", @@ -123,7 +122,7 @@ func TestDevice(t *testing.T) { rw.ws = append(rw.ws, ierr{1, nil}) return dev.usbRegWrite(0x1234, 0x255) }, - want: xerrors.Errorf("could not write USB register (0x%x, 0x%x): %w", 0x1234, 0x255, io.ErrShortWrite), + want: fmt.Errorf("could not write USB register (0x%x, 0x%x): %w", 0x1234, 0x255, io.ErrShortWrite), }, } { t.Run(tc.name, func(t *testing.T) { diff --git a/dif/encoder.go b/dif/encoder.go index b5ad3c62973abd3fb6389cae088d2d9fb49e9ef9..aee71fda72c6561d85b3a19c09ec0b5cb6827d7c 100644 --- a/dif/encoder.go +++ b/dif/encoder.go @@ -6,10 +6,10 @@ package dif import ( "encoding/binary" + "fmt" "io" "github.com/go-lpc/mim/internal/crc16" - "golang.org/x/xerrors" ) // Encoder writes DIF data to an output stream. @@ -50,7 +50,7 @@ func (enc *Encoder) Encode(dif *DIF) error { enc.writeU8(gbHeader) if enc.err != nil { - return xerrors.Errorf("dif: could not write global header marker: %w", enc.err) + return fmt.Errorf("dif: could not write global header marker: %w", enc.err) } enc.writeU8(dif.Header.ID) diff --git a/dif/readout.go b/dif/readout.go index 7e89d35b28c245668e104beaaeaad747d1cfbde2..6089c978076ccb947a7d385a88475e361c698754 100644 --- a/dif/readout.go +++ b/dif/readout.go @@ -11,7 +11,6 @@ import ( "github.com/go-daq/tdaq/log" "github.com/go-lpc/mim/internal/crc16" - "golang.org/x/xerrors" ) type asicKind uint32 @@ -45,7 +44,7 @@ type Readout struct { func NewReadout(name string, prodID uint32, msg log.MsgStream) (*Readout, error) { dev, err := newDevice(0x0403, uint16(prodID)) if err != nil { - return nil, xerrors.Errorf("could not find DIF driver (%s, 0x%x): %w", name, prodID, err) + return nil, fmt.Errorf("could not find DIF driver (%s, 0x%x): %w", name, prodID, err) } rdo := &Readout{ @@ -64,7 +63,7 @@ func NewReadout(name string, prodID uint32, msg log.MsgStream) (*Readout, error) _, err = fmt.Sscanf(name, "FT101%03d", &rdo.difID) if err != nil { _ = dev.close() - return nil, xerrors.Errorf("could not find DIF-id from %q: %w", name, err) + return nil, fmt.Errorf("could not find DIF-id from %q: %w", name, err) } return rdo, nil @@ -73,7 +72,7 @@ func NewReadout(name string, prodID uint32, msg log.MsgStream) (*Readout, error) func (rdo *Readout) close() error { err := rdo.dev.close() if err != nil { - return xerrors.Errorf("could not close DIF driver: %w", err) + return fmt.Errorf("could not close DIF driver: %w", err) } return nil } @@ -87,17 +86,17 @@ func (rdo *Readout) stop() error { err = rdo.dev.hardrocFlushDigitalFIFO() if err != nil { - return xerrors.Errorf("could not flush digital FIFO: %w", err) + return fmt.Errorf("could not flush digital FIFO: %w", err) } err = rdo.dev.hardrocStopDigitalAcquisitionCommand() if err != nil { - return xerrors.Errorf("could not stop digital acquisition: %w", err) + return fmt.Errorf("could not stop digital acquisition: %w", err) } err = rdo.dev.hardrocFlushDigitalFIFO() if err != nil { - return xerrors.Errorf("could not flush digital FIFO: %w", err) + return fmt.Errorf("could not flush digital FIFO: %w", err) } return nil @@ -107,38 +106,38 @@ func (rdo *Readout) configureRegisters() error { var err error err = rdo.dev.setDIFID(rdo.difID) if err != nil { - return xerrors.Errorf("could not set DIF ID to 0x%x: %w", rdo.difID, err) + return fmt.Errorf("could not set DIF ID to 0x%x: %w", rdo.difID, err) } err = rdo.doRefreshNumASICs() if err != nil { - return xerrors.Errorf("could not refresh #ASICs: %w", err) + return fmt.Errorf("could not refresh #ASICs: %w", err) } err = rdo.dev.setEventsBetweenTemperatureReadout(5) if err != nil { - return xerrors.Errorf("could not set #events Temp readout: %w", err) + return fmt.Errorf("could not set #events Temp readout: %w", err) } err = rdo.dev.setAnalogConfigureRegister(0xc0054000) if err != nil { - return xerrors.Errorf("could not configure analog register: %w", err) + return fmt.Errorf("could not configure analog register: %w", err) } err = rdo.dev.hardrocFlushDigitalFIFO() if err != nil { - return xerrors.Errorf("could not flush digital FIFO: %w", err) + return fmt.Errorf("could not flush digital FIFO: %w", err) } fw, err := rdo.dev.usbFwVersion() if err != nil { - return xerrors.Errorf("could not get firmware version: %w", err) + return fmt.Errorf("could not get firmware version: %w", err) } rdo.msg.Infof("dif %s fw: 0x%x", rdo.name, fw) err = rdo.dev.difCptReset() if err != nil { - return xerrors.Errorf("could not reset DIF cpt: %w", err) + return fmt.Errorf("could not reset DIF cpt: %w", err) } err = rdo.dev.setChipTypeRegister(map[asicKind]uint32{ @@ -146,43 +145,43 @@ func (rdo *Readout) configureRegisters() error { microrocASIC: 0x1000, }[rdo.asic]) if err != nil { - return xerrors.Errorf("could not set chip type: %w", err) + return fmt.Errorf("could not set chip type: %w", err) } err = rdo.dev.setControlRegister(rdo.ctlreg) if err != nil { - return xerrors.Errorf("could not set control register: %w", err) + return fmt.Errorf("could not set control register: %w", err) } ctlreg, err := rdo.dev.getControlRegister() if err != nil { - return xerrors.Errorf("could not get control register: %w", err) + return fmt.Errorf("could not get control register: %w", err) } rdo.msg.Infof("ctl reg: 0x%x", ctlreg) err = rdo.dev.setPwr2PwrARegister(rdo.reg.p2pa) if err != nil { - return xerrors.Errorf("could not set pwr to A register: %w", err) + return fmt.Errorf("could not set pwr to A register: %w", err) } err = rdo.dev.setPwrA2PwrDRegister(rdo.reg.pa2pd) if err != nil { - return xerrors.Errorf("could not set A to D register: %w", err) + return fmt.Errorf("could not set A to D register: %w", err) } err = rdo.dev.setPwrD2DAQRegister(rdo.reg.pd2daq) if err != nil { - return xerrors.Errorf("could not set D to DAQ register: %w", err) + return fmt.Errorf("could not set D to DAQ register: %w", err) } err = rdo.dev.setDAQ2PwrDRegister(rdo.reg.daq2pd) if err != nil { - return xerrors.Errorf("could not set DAQ to D register: %w", err) + return fmt.Errorf("could not set DAQ to D register: %w", err) } err = rdo.dev.setPwrD2PwrARegister(rdo.reg.pd2pa) if err != nil { - return xerrors.Errorf("could not set D to A register: %w", err) + return fmt.Errorf("could not set D to A register: %w", err) } return err @@ -196,13 +195,13 @@ func (rdo *Readout) configureChips(scFrame [][]byte) (uint32, error) { case microrocASIC: frame = make([]byte, microrocSLCFrameSize) default: - return 0, xerrors.Errorf("unknown ASIC kind %v", rdo.asic) + return 0, fmt.Errorf("unknown ASIC kind %v", rdo.asic) } crc := crc16.New(nil) err := rdo.dev.hardrocCmdSLCWrite() if err != nil { - return 0, xerrors.Errorf("%s could not send start SLC command to DIF: %w", + return 0, fmt.Errorf("%s could not send start SLC command to DIF: %w", rdo.name, err, ) } @@ -211,12 +210,12 @@ func (rdo *Readout) configureChips(scFrame [][]byte) (uint32, error) { copy(frame, scFrame[i-1]) _, err = crc.Write(frame) if err != nil { - return 0, xerrors.Errorf("%s could not update CRC-16: %w", rdo.name, err) + return 0, fmt.Errorf("%s could not update CRC-16: %w", rdo.name, err) } err = rdo.dev.cmdSLCWriteSingleSLCFrame(frame) if err != nil { - return 0, xerrors.Errorf("%s could not send SLC frame to DIF: %w", + return 0, fmt.Errorf("%s could not send SLC frame to DIF: %w", rdo.name, err, ) } @@ -225,7 +224,7 @@ func (rdo *Readout) configureChips(scFrame [][]byte) (uint32, error) { crc16 := crc.Sum16() err = rdo.dev.hardrocCmdSLCWriteCRC(crc16) if err != nil { - return 0, xerrors.Errorf("%s could not send CRC 0x%x to SLC: %w", + return 0, fmt.Errorf("%s could not send CRC 0x%x to SLC: %w", rdo.name, crc16, err, ) } @@ -234,7 +233,7 @@ func (rdo *Readout) configureChips(scFrame [][]byte) (uint32, error) { st, err := rdo.doReadSLCStatus() if err != nil { - return 0, xerrors.Errorf("%s could not read SLC status: %w", + return 0, fmt.Errorf("%s could not read SLC status: %w", rdo.name, err, ) } @@ -251,7 +250,7 @@ func (rdo *Readout) Readout(p []byte) (int, error) { ) err := dec.Decode(&dif) if err != nil { - return w.c, xerrors.Errorf("%s could not decode DIF data: %w", + return w.c, fmt.Errorf("%s could not decode DIF data: %w", rdo.name, err, ) } @@ -281,7 +280,7 @@ func (rdo *Readout) doRefreshNumASICs() error { err := rdo.dev.usbRegWrite(0x05, v) if err != nil { - return xerrors.Errorf("could not refresh num-asics: %w", err) + return fmt.Errorf("could not refresh num-asics: %w", err) } return nil @@ -290,7 +289,7 @@ func (rdo *Readout) doRefreshNumASICs() error { func (rdo *Readout) doReadSLCStatus() (uint32, error) { st, err := rdo.dev.hardrocSLCStatusRead() if err != nil { - return 0, xerrors.Errorf("could not read SLC status: %w", err) + return 0, fmt.Errorf("could not read SLC status: %w", err) } rdo.curSC = st return st, nil diff --git a/dif/readout_test.go b/dif/readout_test.go index bc6f9c2e5ecea57666478bfe513ed26e6ef73635..f70c6cd9db131321816b921f1b466ea27b85b15b 100644 --- a/dif/readout_test.go +++ b/dif/readout_test.go @@ -6,6 +6,8 @@ package dif import ( "bytes" + "errors" + "fmt" "io" "os" "strings" @@ -13,7 +15,6 @@ import ( "github.com/go-daq/tdaq/log" "github.com/ziutek/ftdi" - "golang.org/x/xerrors" ) func ftdiOpenTest(vid, pid uint16) (ftdiDevice, error) { @@ -33,11 +34,11 @@ func TestReadout(t *testing.T) { }{ { name: "FT101xxx", - err: xerrors.Errorf("could not find DIF-id from %q: %s", "FT101xxx", xerrors.New("expected integer")), + err: fmt.Errorf("could not find DIF-id from %q: %s", "FT101xxx", errors.New("expected integer")), }, { name: "FT101", - err: xerrors.Errorf("could not find DIF-id from %q: %s", "FT101", io.EOF), + err: fmt.Errorf("could not find DIF-id from %q: %s", "FT101", io.EOF), }, { name: "FT10142", @@ -155,7 +156,7 @@ func TestReadout(t *testing.T) { } func TestInvalidReadout(t *testing.T) { - want := xerrors.Errorf("no such device") + want := fmt.Errorf("no such device") ftdiOpen = func(vid, pid uint16) (ftdiDevice, error) { return nil, want } defer func() { ftdiOpen = ftdiOpenImpl diff --git a/dif/rw_test.go b/dif/rw_test.go index d82ee4daed078b2862b6efd902d442721bae9cb7..dbe69a64b1a04d0041dbab044ae5f6a2acdcfbe5 100644 --- a/dif/rw_test.go +++ b/dif/rw_test.go @@ -6,11 +6,10 @@ package dif import ( "bytes" + "fmt" "io" "reflect" "testing" - - "golang.org/x/xerrors" ) func TestCodec(t *testing.T) { @@ -98,7 +97,7 @@ func TestEncoder(t *testing.T) { { buf := failingWriter{n: 0} enc := NewEncoder(&buf) - if got, want := enc.Encode(&DIF{}), xerrors.Errorf("dif: could not write global header marker: %w", io.ErrUnexpectedEOF); got.Error() != want.Error() { + if got, want := enc.Encode(&DIF{}), fmt.Errorf("dif: could not write global header marker: %w", io.ErrUnexpectedEOF); got.Error() != want.Error() { t.Fatalf("invalid error:\ngot= %+v\nwant=%+v", got, want) } } @@ -132,7 +131,7 @@ func TestDecoder(t *testing.T) { name: "no data", n: 1, raw: nil, - want: xerrors.Errorf("dif: could not read global header marker: %w", io.EOF), + want: fmt.Errorf("dif: could not read global header marker: %w", io.EOF), }, { name: "normal-global-header", @@ -248,7 +247,7 @@ func TestDecoder(t *testing.T) { raw: []byte{ gbHeader + 1, }, - want: xerrors.Errorf("dif: could not read global header marker (got=0x%x)", gbHeader+1), + want: fmt.Errorf("dif: could not read global header marker (got=0x%x)", gbHeader+1), }, { name: "invalid-dif-header-eof", @@ -256,7 +255,7 @@ func TestDecoder(t *testing.T) { raw: []byte{ gbHeader, }, - want: xerrors.Errorf("dif: could not read DIF header: %w", io.EOF), + want: fmt.Errorf("dif: could not read DIF header: %w", io.EOF), }, { name: "invalid-dif-header-unexpected-eof", @@ -264,7 +263,7 @@ func TestDecoder(t *testing.T) { raw: []byte{ gbHeader, 1, 2, }, - want: xerrors.Errorf("dif: could not read DIF header: %w", io.ErrUnexpectedEOF), + want: fmt.Errorf("dif: could not read DIF header: %w", io.ErrUnexpectedEOF), }, { name: "invalid-dif-id", @@ -276,7 +275,7 @@ func TestDecoder(t *testing.T) { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // hdr-1 0, 1, // hdr-2 }, - want: xerrors.Errorf("dif: invalid DIF ID (got=0x%x, want=0x%x)", difID+1, difID), + want: fmt.Errorf("dif: invalid DIF ID (got=0x%x, want=0x%x)", difID+1, difID), }, { name: "short-frame-header", @@ -288,7 +287,7 @@ func TestDecoder(t *testing.T) { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // hdr-1 0, 1, // hdr-2 }, - want: xerrors.Errorf("dif: DIF 0x%x could not read frame header/global trailer: %w", difID, io.EOF), + want: fmt.Errorf("dif: DIF 0x%x could not read frame header/global trailer: %w", difID, io.EOF), }, { name: "analog-frame-header", @@ -302,7 +301,7 @@ func TestDecoder(t *testing.T) { anHeader, // analog frame header }, - want: xerrors.Errorf("dif: DIF 0x%x contains an analog frame", difID), + want: fmt.Errorf("dif: DIF 0x%x contains an analog frame", difID), }, { name: "invalid-frame-header", @@ -321,7 +320,7 @@ func TestDecoder(t *testing.T) { 30, 31, 32, 33, 34, 35, 36, 37, // data-2 frTrailer, }, - want: xerrors.Errorf("dif: DIF 0x%x invalid frame/global marker (got=0x%x)", difID, frHeader+1), + want: fmt.Errorf("dif: DIF 0x%x invalid frame/global marker (got=0x%x)", difID, frHeader+1), }, { name: "missing-hardroc-header", @@ -335,7 +334,7 @@ func TestDecoder(t *testing.T) { frHeader, }, - want: xerrors.Errorf("dif: DIF 0x%x could not read frame trailer/hardroc header: %w", difID, io.ErrUnexpectedEOF), + want: fmt.Errorf("dif: DIF 0x%x could not read frame trailer/hardroc header: %w", difID, io.ErrUnexpectedEOF), }, { name: "short-frame-header", @@ -351,7 +350,7 @@ func TestDecoder(t *testing.T) { 1, // hardroc header frTrailer, }, - want: xerrors.Errorf("dif: DIF 0x%x could not read hardroc frame: %w", difID, io.ErrUnexpectedEOF), + want: fmt.Errorf("dif: DIF 0x%x could not read hardroc frame: %w", difID, io.ErrUnexpectedEOF), }, { name: "incomplete-frame", @@ -370,7 +369,7 @@ func TestDecoder(t *testing.T) { 30, 31, 32, 33, 34, 35, 36, 37, // data-2 frTrailer, }, - want: xerrors.Errorf("dif: DIF 0x%x received an incomplete frame", difID), + want: fmt.Errorf("dif: DIF 0x%x received an incomplete frame", difID), }, { name: "missing-global-trailer", @@ -396,7 +395,7 @@ func TestDecoder(t *testing.T) { 30, 31, 32, 33, 34, 35, 36, 37, // data-2 frTrailer, }, - want: xerrors.Errorf("dif: DIF 0x%x could not read frame header/global trailer: %w", difID, io.EOF), + want: fmt.Errorf("dif: DIF 0x%x could not read frame header/global trailer: %w", difID, io.EOF), }, { name: "invalid-global-trailer", @@ -424,7 +423,7 @@ func TestDecoder(t *testing.T) { gbTrailer + 1, }, - want: xerrors.Errorf("dif: DIF 0x%x invalid frame/global marker (got=0x%x)", difID, gbTrailer+1), + want: fmt.Errorf("dif: DIF 0x%x invalid frame/global marker (got=0x%x)", difID, gbTrailer+1), }, { name: "missing-crc-16", @@ -452,7 +451,7 @@ func TestDecoder(t *testing.T) { gbTrailer, }, - want: xerrors.Errorf("dif: DIF 0x%x could not receive CRC-16: %w", difID, io.EOF), + want: fmt.Errorf("dif: DIF 0x%x could not receive CRC-16: %w", difID, io.EOF), }, { name: "short-crc-16", @@ -481,7 +480,7 @@ func TestDecoder(t *testing.T) { gbTrailer, 0xb5, // CRC-16 }, - want: xerrors.Errorf("dif: DIF 0x%x could not receive CRC-16: %w", difID, io.ErrUnexpectedEOF), + want: fmt.Errorf("dif: DIF 0x%x could not receive CRC-16: %w", difID, io.ErrUnexpectedEOF), }, { name: "invalid-crc-16", @@ -510,7 +509,7 @@ func TestDecoder(t *testing.T) { gbTrailer, 0xb5, 0xff, // CRC-16 }, - want: xerrors.Errorf("dif: DIF 0x%x inconsistent CRC: recv=0xb5ff comp=0x26a2", difID), + want: fmt.Errorf("dif: DIF 0x%x inconsistent CRC: recv=0xb5ff comp=0x26a2", difID), }, } { t.Run(tc.name, func(t *testing.T) { diff --git a/go.mod b/go.mod index 0cf2e8f43f85ecb6c35fd02e45e7b337d45be5a8..9623110c435d25d5bb280439dbfc938d206cea47 100644 --- a/go.mod +++ b/go.mod @@ -8,5 +8,4 @@ require ( github.com/ziutek/ftdi v0.0.0-20181130113013-aef9e445a2fa golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect - golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 )