@@ -17,15 +17,14 @@ limitations under the License.
17
17
package cmd
18
18
19
19
import (
20
+ "bufio"
21
+ "bytes"
22
+ "encoding/hex"
20
23
"errors"
21
24
"fmt"
22
25
"io"
23
26
"os"
24
27
25
- "bufio"
26
- "bytes"
27
- "encoding/hex"
28
-
29
28
"github.com/etcd-io/auger/pkg/encoding"
30
29
"github.com/etcd-io/auger/pkg/scheme"
31
30
"github.com/spf13/cobra"
@@ -122,17 +121,17 @@ func runInBatchMode(metaOnly bool, outMediaType string, out io.Writer) (err erro
122
121
lineNum := 0
123
122
for {
124
123
input , err := inputReader .ReadBytes (byte ('\n' ))
125
- if err == io .EOF {
124
+ if errors . Is ( err , io .EOF ) {
126
125
return nil
127
126
}
128
127
if err != nil {
129
- return fmt .Errorf ("error reading --batch-process input: %v " , err )
128
+ return fmt .Errorf ("error reading --batch-process input: %w " , err )
130
129
}
131
130
132
131
input = stripNewline (input )
133
132
decodedinput , err := hex .DecodeString (string (input ))
134
133
if err != nil {
135
- return fmt .Errorf ("error decoding input on line %d of --batch-process input: %v " , lineNum , err )
134
+ return fmt .Errorf ("error decoding input on line %d of --batch-process input: %w " , lineNum , err )
136
135
}
137
136
inMediaType , decodedinput , err := encoding .DetectAndExtract (decodedinput )
138
137
if err != nil {
@@ -144,7 +143,6 @@ func runInBatchMode(metaOnly bool, outMediaType string, out io.Writer) (err erro
144
143
buf := bytes .NewBufferString ("" )
145
144
err = encoding .DecodeSummary (inMediaType , decodedinput , buf )
146
145
if err != nil {
147
-
148
146
fmt .Fprintf (out , "ERROR:%v|\n " , err )
149
147
} else {
150
148
fmt .Fprintf (out , "OK|%s\n " , buf .String ())
@@ -188,23 +186,23 @@ func readInput(inputFilename string) ([]byte, error) {
188
186
if inputFilename != "" {
189
187
data , err := os .ReadFile (inputFilename )
190
188
if err != nil {
191
- return nil , fmt .Errorf ("error reading input file %s: %v " , inputFilename , err )
189
+ return nil , fmt .Errorf ("error reading input file %s: %w " , inputFilename , err )
192
190
}
193
191
data = stripNewline (data )
194
192
return data , nil
195
193
}
196
194
197
195
stat , err := os .Stdin .Stat ()
198
196
if err != nil {
199
- return nil , fmt .Errorf ("stdin error: %s " , err )
197
+ return nil , fmt .Errorf ("stdin error: %w " , err )
200
198
}
201
199
if (stat .Mode () & os .ModeCharDevice ) != 0 {
202
200
fmt .Fprintln (os .Stderr , "warn: waiting on stdin from tty" )
203
201
}
204
202
205
203
stdin , err := io .ReadAll (os .Stdin )
206
204
if err != nil {
207
- return nil , fmt .Errorf ("unable to read data from stdin: %v " , err )
205
+ return nil , fmt .Errorf ("unable to read data from stdin: %w " , err )
208
206
}
209
207
// Etcd --print-value-only includes an extranous newline even for binary values.
210
208
// We can safely strip it off since none of the valid inputs this code processes
0 commit comments