mirror of https://bitbucket.org/ausocean/av.git
Changed all %v's to %w's where appropriate
This commit is contained in:
parent
94380ef17e
commit
e116e197ae
|
@ -100,13 +100,13 @@ func (e *Extractor) Extract(dst io.Writer, src io.Reader, delay time.Duration) e
|
|||
case io.EOF:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("source read error: %v\n", err)
|
||||
return fmt.Errorf("source read error: %w\n", err)
|
||||
}
|
||||
|
||||
// Get payload from RTP packet.
|
||||
payload, err := rtp.Payload(buf[:n])
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get RTP payload, failed with err: %v\n", err)
|
||||
return fmt.Errorf("could not get RTP payload, failed with err: %w\n", err)
|
||||
}
|
||||
|
||||
nalType := payload[0] & 0x1f
|
||||
|
|
|
@ -227,7 +227,7 @@ func subMbTypeBinString(v, slice int) ([]int, error) {
|
|||
func codedBlockPatternBinString(luma, chroma, arrayType int) ([]int, error) {
|
||||
p, err := fixedLenBinString(luma, 15)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fixed length binarization failed with error: %v", err)
|
||||
return nil, fmt.Errorf("fixed length binarization failed with error: %w", err)
|
||||
}
|
||||
|
||||
if arrayType == 0 || arrayType == 3 {
|
||||
|
@ -236,7 +236,7 @@ func codedBlockPatternBinString(luma, chroma, arrayType int) ([]int, error) {
|
|||
|
||||
s, err := truncUnaryBinString(chroma, 2)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("truncated unary binarization failed with error: %v", err)
|
||||
return nil, fmt.Errorf("truncated unary binarization failed with error: %w", err)
|
||||
}
|
||||
|
||||
return append(p, s...), nil
|
||||
|
|
|
@ -90,12 +90,12 @@ func formCoeffTokenMap(lines [][]string) ([nColumns]tokenMap, error) {
|
|||
for _, line := range lines {
|
||||
trailingOnes, err := strconv.Atoi(line[0])
|
||||
if err != nil {
|
||||
return maps, fmt.Errorf("could not convert trailingOnes string to int, failed with error: %v", err)
|
||||
return maps, fmt.Errorf("could not convert trailingOnes string to int, failed with error: %w", err)
|
||||
}
|
||||
|
||||
totalCoeff, err := strconv.Atoi(line[1])
|
||||
if err != nil {
|
||||
return maps, fmt.Errorf("could not convert totalCoeff string to int, failed with error: %v", err)
|
||||
return maps, fmt.Errorf("could not convert totalCoeff string to int, failed with error: %w", err)
|
||||
}
|
||||
|
||||
// For each column in this row, therefore each nC category, load the
|
||||
|
@ -120,7 +120,7 @@ func formCoeffTokenMap(lines [][]string) ([nColumns]tokenMap, error) {
|
|||
// This will be the value of the coeff_token (without leading zeros).
|
||||
val, err := binToInt(v[nZeros:])
|
||||
if err != nil {
|
||||
return maps, fmt.Errorf("could not get value of remaining binary, failed with error: %v", err)
|
||||
return maps, fmt.Errorf("could not get value of remaining binary, failed with error: %w", err)
|
||||
}
|
||||
|
||||
// Add the TrailingOnes(coeff_token) and TotalCoeff(coeff_token) values
|
||||
|
@ -217,7 +217,7 @@ func parseTotalCoeffAndTrailingOnes(br *bits.BitReader, vid *VideoStream, ctx *S
|
|||
|
||||
trailingOnes, totalCoeff, _, err = readCoeffToken(br, nC)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("could not get trailingOnes and totalCoeff vars, failed with error: %v", err)
|
||||
err = fmt.Errorf("could not get trailingOnes and totalCoeff vars, failed with error: %w", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
@ -239,7 +239,7 @@ func readCoeffToken(br *bits.BitReader, nC int) (trailingOnes, totalCoeff, coeff
|
|||
for ; b == 0; nZeros++ {
|
||||
b, err = br.ReadBits(1)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("could not read coeff_token leading zeros, failed with error: %v", err)
|
||||
err = fmt.Errorf("could not read coeff_token leading zeros, failed with error: %w", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -284,7 +284,7 @@ func readCoeffToken(br *bits.BitReader, nC int) (trailingOnes, totalCoeff, coeff
|
|||
|
||||
b, err = br.ReadBits(1)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("could not read next bit of coeff_token, failed with error: %v", err)
|
||||
err = fmt.Errorf("could not read next bit of coeff_token, failed with error: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ func parseLevelPrefix(br *bits.BitReader) (int, error) {
|
|||
for b := 0; b != 1; zeros++ {
|
||||
_b, err := br.ReadBits(1)
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("could not read bit, failed with error: %v", err)
|
||||
return -1, fmt.Errorf("could not read bit, failed with error: %w", err)
|
||||
}
|
||||
b = int(_b)
|
||||
}
|
||||
|
@ -331,7 +331,7 @@ func parseLevelInformation(br *bits.BitReader, totalCoeff, trailingOnes int) ([]
|
|||
for ; i < trailingOnes; i++ {
|
||||
b, err := br.ReadBits(1)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not read trailing_ones_sign_flag, failed with error: %v", err)
|
||||
return nil, fmt.Errorf("could not read trailing_ones_sign_flag, failed with error: %w", err)
|
||||
}
|
||||
levelVal = append(levelVal, 1-int(b)*2)
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ func parseLevelInformation(br *bits.BitReader, totalCoeff, trailingOnes int) ([]
|
|||
for j := 0; j < totalCoeff-trailingOnes; j++ {
|
||||
levelPrefix, err := parseLevelPrefix(br)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse level prefix, failed with error: %v", err)
|
||||
return nil, fmt.Errorf("could not parse level prefix, failed with error: %w", err)
|
||||
}
|
||||
|
||||
var levelSuffixSize int
|
||||
|
@ -366,7 +366,7 @@ func parseLevelInformation(br *bits.BitReader, totalCoeff, trailingOnes int) ([]
|
|||
if levelSuffixSize > 0 {
|
||||
b, err := br.ReadBits(levelSuffixSize)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not parse levelSuffix, failed with error: %v", err)
|
||||
return nil, fmt.Errorf("could not parse levelSuffix, failed with error: %w", err)
|
||||
}
|
||||
levelSuffix = int(b)
|
||||
} else {
|
||||
|
|
|
@ -34,7 +34,7 @@ func decode(vid *VideoStream, ctx *SliceContext) error {
|
|||
var err error
|
||||
vid.topFieldOrderCnt, vid.bottomFieldOrderCnt, err = decodePicOrderCnt(vid, ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not derive topFieldOrderCnt and bottomFieldOrderCnt, failed with error: %v", err)
|
||||
return fmt.Errorf("could not derive topFieldOrderCnt and bottomFieldOrderCnt, failed with error: %w", err)
|
||||
}
|
||||
|
||||
// According to 8.2.1 after decoding picture.
|
||||
|
|
|
@ -79,13 +79,13 @@ func (l *Lexer) Lex(dst io.Writer, src io.Reader, delay time.Duration) error {
|
|||
case io.EOF:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("source read error: %v\n", err)
|
||||
return fmt.Errorf("source read error: %w\n", err)
|
||||
}
|
||||
|
||||
// Get payload from RTP packet.
|
||||
payload, err := rtp.Payload(buf[:n])
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get rtp payload, failed with err: %v\n", err)
|
||||
return fmt.Errorf("could not get rtp payload, failed with err: %w\n", err)
|
||||
}
|
||||
nalType := (payload[0] >> 1) & 0x3f
|
||||
|
||||
|
@ -109,7 +109,7 @@ func (l *Lexer) Lex(dst io.Writer, src io.Reader, delay time.Duration) error {
|
|||
|
||||
markerIsSet, err := rtp.Marker(buf[:n])
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not get marker bit, failed with err: %v\n", err)
|
||||
return fmt.Errorf("could not get marker bit, failed with err: %w\n", err)
|
||||
}
|
||||
|
||||
if markerIsSet {
|
||||
|
|
|
@ -219,7 +219,7 @@ func NewEncoder(dst io.WriteCloser, rate float64, mediaType int, options ...func
|
|||
for _, option := range options {
|
||||
err := option(e)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("option failed with error: %v", err)
|
||||
return nil, fmt.Errorf("option failed with error: %w", err)
|
||||
}
|
||||
}
|
||||
return e, nil
|
||||
|
@ -243,7 +243,7 @@ func (e *Encoder) Write(data []byte) (int, error) {
|
|||
if e.nalBasedPSI {
|
||||
nalType, err := h264.NALType(data)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("could not get type from NAL unit, failed with error: %v", err)
|
||||
return 0, fmt.Errorf("could not get type from NAL unit, failed with error: %w", err)
|
||||
}
|
||||
|
||||
if nalType == h264dec.NALTypeSPS {
|
||||
|
|
|
@ -74,7 +74,7 @@ func Set(host string, options ...Option) error {
|
|||
// Create a client with a cookie jar.
|
||||
jar, err := cookiejar.New(nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create cookie jar, failed with error: %v", err)
|
||||
return fmt.Errorf("could not create cookie jar, failed with error: %w", err)
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
|
@ -85,13 +85,13 @@ func Set(host string, options ...Option) error {
|
|||
// Get the request body required for log-in.
|
||||
body, err := getLogin(client, id, host)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not generate log-in request data: %v", err)
|
||||
return fmt.Errorf("could not generate log-in request data: %w", err)
|
||||
}
|
||||
|
||||
// Log in using generated log-in request body.
|
||||
err = login(client, id, host, body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not login: %v", err)
|
||||
return fmt.Errorf("could not login: %w", err)
|
||||
}
|
||||
|
||||
// Apply the options to the settings specified by the user.
|
||||
|
@ -99,14 +99,14 @@ func Set(host string, options ...Option) error {
|
|||
for _, op := range options {
|
||||
s, err = op(s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not action Option: %v", err)
|
||||
return fmt.Errorf("could not action Option: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Submit the settings to the server.
|
||||
err = submitSettings(client, id, host, s)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not submit settings: %v", err)
|
||||
return fmt.Errorf("could not submit settings: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ const (
|
|||
func getLogin(c *http.Client, id, host string) (string, error) {
|
||||
req, err := http.NewRequest("GET", "http://"+host+loginSubDir, nil)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("can't create GET request for log-in page: %v", err)
|
||||
return "", fmt.Errorf("can't create GET request for log-in page: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Connection", "keep-alive")
|
||||
|
@ -68,13 +68,13 @@ func getLogin(c *http.Client, id, host string) (string, error) {
|
|||
|
||||
resp, err := c.Do(req)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not do GET request for log-in page: %v", err)
|
||||
return "", fmt.Errorf("could not do GET request for log-in page: %w", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("could not read response of GET request for log-in page: %v", err)
|
||||
return "", fmt.Errorf("could not read response of GET request for log-in page: %w", err)
|
||||
}
|
||||
|
||||
// Find the CC values in the source of the response.
|
||||
|
@ -104,7 +104,7 @@ func getLogin(c *http.Client, id, host string) (string, error) {
|
|||
func login(c *http.Client, id, host, b string) error {
|
||||
req, err := http.NewRequest("POST", "http://"+host+loggedInSubDir, bytes.NewBuffer([]byte(b)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create log-in request: %v", err)
|
||||
return fmt.Errorf("could not create log-in request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Connection", "keep-alive")
|
||||
|
@ -122,7 +122,7 @@ func login(c *http.Client, id, host, b string) error {
|
|||
|
||||
_, err = c.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not do log-in request: %v", err)
|
||||
return fmt.Errorf("could not do log-in request: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -134,7 +134,7 @@ func submitSettings(c *http.Client, id, host string, s settings) error {
|
|||
fBytes := []byte(populateForm(s).Encode())
|
||||
req, err := http.NewRequest("POST", "http://"+host+settingsSubDir, bytes.NewReader(fBytes))
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create settings submit request: %v", err)
|
||||
return fmt.Errorf("could not create settings submit request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Connection", "keep-alive")
|
||||
|
|
|
@ -243,7 +243,7 @@ func (c *Client) parse(buf []byte) {
|
|||
c.markReceivedTime()
|
||||
t, err := ParseTimestamp(buf)
|
||||
if err != nil {
|
||||
c.err <- fmt.Errorf("could not get timestamp from sender report, failed with error: %v", err)
|
||||
c.err <- fmt.Errorf("could not get timestamp from sender report, failed with error: %w", err)
|
||||
}
|
||||
c.setSenderTs(t)
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ func TestReceive(t *testing.T) {
|
|||
var err error
|
||||
c, err = NewClient(clientAddr)
|
||||
if err != nil {
|
||||
testErr <- fmt.Errorf("could not create client, failed with error: %v\n", err)
|
||||
testErr <- fmt.Errorf("could not create client, failed with error: %w\n", err)
|
||||
}
|
||||
close(clientReady)
|
||||
|
||||
|
@ -70,7 +70,7 @@ func TestReceive(t *testing.T) {
|
|||
case io.EOF:
|
||||
continue
|
||||
default:
|
||||
testErr <- fmt.Errorf("unexpected error from c.Read: %v\n", err)
|
||||
testErr <- fmt.Errorf("unexpected error from c.Read: %w\n", err)
|
||||
}
|
||||
|
||||
// Create expected data and apply operation if there is one.
|
||||
|
@ -91,12 +91,12 @@ func TestReceive(t *testing.T) {
|
|||
<-clientReady
|
||||
cAddr, err := net.ResolveUDPAddr("udp", clientAddr)
|
||||
if err != nil {
|
||||
serverErr <- fmt.Errorf("could not resolve server address, failed with err: %v\n", err)
|
||||
serverErr <- fmt.Errorf("could not resolve server address, failed with err: %w\n", err)
|
||||
}
|
||||
|
||||
conn, err := net.DialUDP("udp", nil, cAddr)
|
||||
if err != nil {
|
||||
serverErr <- fmt.Errorf("could not dial udp, failed with err: %v\n", err)
|
||||
serverErr <- fmt.Errorf("could not dial udp, failed with err: %w\n", err)
|
||||
}
|
||||
|
||||
// Send packets to the client.
|
||||
|
@ -104,7 +104,7 @@ func TestReceive(t *testing.T) {
|
|||
p := (&Packet{V: rtpVer, Payload: []byte{byte(i)}}).Bytes(nil)
|
||||
_, err := conn.Write(p)
|
||||
if err != nil {
|
||||
serverErr <- fmt.Errorf("could not write packet to conn, failed with err: %v\n", err)
|
||||
serverErr <- fmt.Errorf("could not write packet to conn, failed with err: %w\n", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
|
@ -142,7 +142,7 @@ func ReadResponse(r io.Reader) (*Response, error) {
|
|||
|
||||
n, err := fmt.Sscanf(s[5:], "%d.%d %d", &resp.ProtoMajor, &resp.ProtoMinor, &resp.StatusCode)
|
||||
if err != nil || n != 3 {
|
||||
return nil, fmt.Errorf("could not Sscanf response, error: %v", err)
|
||||
return nil, fmt.Errorf("could not Sscanf response, error: %w", err)
|
||||
}
|
||||
|
||||
// Read headers.
|
||||
|
|
|
@ -132,7 +132,7 @@ func New(c config.Config, ns *netsender.Sender) (*Revid, error) {
|
|||
r := Revid{ns: ns, err: make(chan error)}
|
||||
err := r.setConfig(c)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not set config, failed with error: %v", err)
|
||||
return nil, fmt.Errorf("could not set config, failed with error: %w", err)
|
||||
}
|
||||
r.cfg.Logger.SetLevel(c.LogLevel)
|
||||
go r.handleErrors()
|
||||
|
|
Loading…
Reference in New Issue