@@ -70,7 +70,7 @@ func (fs FS) MDStat() ([]MDStat, error) {
70
70
}
71
71
mdstat , err := parseMDStat (data )
72
72
if err != nil {
73
- return nil , fmt .Errorf ("error parsing mdstat %q : %w" , fs .proc .Path ("mdstat" ), err )
73
+ return nil , fmt .Errorf ("%s: Cannot parse %v : %w" , ErrFileParse , fs .proc .Path ("mdstat" ), err )
74
74
}
75
75
return mdstat , nil
76
76
}
@@ -90,13 +90,13 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
90
90
91
91
deviceFields := strings .Fields (line )
92
92
if len (deviceFields ) < 3 {
93
- return nil , fmt .Errorf ("not enough fields in mdline (expected at least 3): %s" , line )
93
+ return nil , fmt .Errorf ("%s: Expected 3+ lines, got %q" , ErrFileParse , line )
94
94
}
95
95
mdName := deviceFields [0 ] // mdx
96
96
state := deviceFields [2 ] // active or inactive
97
97
98
98
if len (lines ) <= i + 3 {
99
- return nil , fmt .Errorf ("error parsing %q: too few lines for md device" , mdName )
99
+ return nil , fmt .Errorf ("%w: Too few lines for md device: %q" , ErrFileParse , mdName )
100
100
}
101
101
102
102
// Failed disks have the suffix (F) & Spare disks have the suffix (S).
@@ -105,7 +105,7 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
105
105
active , total , down , size , err := evalStatusLine (lines [i ], lines [i + 1 ])
106
106
107
107
if err != nil {
108
- return nil , fmt .Errorf ("error parsing md device lines: %w" , err )
108
+ return nil , fmt .Errorf ("%s: Cannot parse md device lines: %v: %w" , ErrFileParse , active , err )
109
109
}
110
110
111
111
syncLineIdx := i + 2
@@ -140,7 +140,7 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
140
140
} else {
141
141
syncedBlocks , pct , finish , speed , err = evalRecoveryLine (lines [syncLineIdx ])
142
142
if err != nil {
143
- return nil , fmt .Errorf ("error parsing sync line in md device %q: %w" , mdName , err )
143
+ return nil , fmt .Errorf ("%s: Cannot parse sync line in md device: %q: %w" , ErrFileParse , mdName , err )
144
144
}
145
145
}
146
146
}
@@ -168,13 +168,13 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) {
168
168
func evalStatusLine (deviceLine , statusLine string ) (active , total , down , size int64 , err error ) {
169
169
statusFields := strings .Fields (statusLine )
170
170
if len (statusFields ) < 1 {
171
- return 0 , 0 , 0 , 0 , fmt .Errorf ("unexpected statusLine %q " , statusLine )
171
+ return 0 , 0 , 0 , 0 , fmt .Errorf ("%s: Unexpected statusline %q: %w " , ErrFileParse , statusLine , err )
172
172
}
173
173
174
174
sizeStr := statusFields [0 ]
175
175
size , err = strconv .ParseInt (sizeStr , 10 , 64 )
176
176
if err != nil {
177
- return 0 , 0 , 0 , 0 , fmt .Errorf ("unexpected statusLine %q: %w" , statusLine , err )
177
+ return 0 , 0 , 0 , 0 , fmt .Errorf ("%s: Unexpected statusline %q: %w" , ErrFileParse , statusLine , err )
178
178
}
179
179
180
180
if strings .Contains (deviceLine , "raid0" ) || strings .Contains (deviceLine , "linear" ) {
@@ -189,17 +189,17 @@ func evalStatusLine(deviceLine, statusLine string) (active, total, down, size in
189
189
190
190
matches := statusLineRE .FindStringSubmatch (statusLine )
191
191
if len (matches ) != 5 {
192
- return 0 , 0 , 0 , 0 , fmt .Errorf ("couldn't find all the substring matches: %s" , statusLine )
192
+ return 0 , 0 , 0 , 0 , fmt .Errorf ("%s: Could not fild all substring matches %s: %w " , ErrFileParse , statusLine , err )
193
193
}
194
194
195
195
total , err = strconv .ParseInt (matches [2 ], 10 , 64 )
196
196
if err != nil {
197
- return 0 , 0 , 0 , 0 , fmt .Errorf ("unexpected statusLine %q: %w" , statusLine , err )
197
+ return 0 , 0 , 0 , 0 , fmt .Errorf ("%s: Unexpected statusline %q: %w" , ErrFileParse , statusLine , err )
198
198
}
199
199
200
200
active , err = strconv .ParseInt (matches [3 ], 10 , 64 )
201
201
if err != nil {
202
- return 0 , 0 , 0 , 0 , fmt .Errorf ("unexpected statusLine %q : %w" , statusLine , err )
202
+ return 0 , 0 , 0 , 0 , fmt .Errorf ("%s: Unexpected active %d : %w" , ErrFileParse , active , err )
203
203
}
204
204
down = int64 (strings .Count (matches [4 ], "_" ))
205
205
@@ -209,42 +209,42 @@ func evalStatusLine(deviceLine, statusLine string) (active, total, down, size in
209
209
func evalRecoveryLine (recoveryLine string ) (syncedBlocks int64 , pct float64 , finish float64 , speed float64 , err error ) {
210
210
matches := recoveryLineBlocksRE .FindStringSubmatch (recoveryLine )
211
211
if len (matches ) != 2 {
212
- return 0 , 0 , 0 , 0 , fmt .Errorf ("unexpected recoveryLine: %s" , recoveryLine )
212
+ return 0 , 0 , 0 , 0 , fmt .Errorf ("%s: Unexpected recoveryLine %s: %w " , ErrFileParse , recoveryLine , err )
213
213
}
214
214
215
215
syncedBlocks , err = strconv .ParseInt (matches [1 ], 10 , 64 )
216
216
if err != nil {
217
- return 0 , 0 , 0 , 0 , fmt .Errorf ("error parsing int from recoveryLine %q: %w" , recoveryLine , err )
217
+ return 0 , 0 , 0 , 0 , fmt .Errorf ("%s: Unexpected parsing of recoveryLine %q: %w" , ErrFileParse , recoveryLine , err )
218
218
}
219
219
220
220
// Get percentage complete
221
221
matches = recoveryLinePctRE .FindStringSubmatch (recoveryLine )
222
222
if len (matches ) != 2 {
223
- return syncedBlocks , 0 , 0 , 0 , fmt .Errorf ("unexpected recoveryLine matching percentage: %s" , recoveryLine )
223
+ return syncedBlocks , 0 , 0 , 0 , fmt .Errorf ("%w: Unexpected recoveryLine matching percentage %s" , ErrFileParse , recoveryLine )
224
224
}
225
225
pct , err = strconv .ParseFloat (strings .TrimSpace (matches [1 ]), 64 )
226
226
if err != nil {
227
- return syncedBlocks , 0 , 0 , 0 , fmt .Errorf ("error parsing float from recoveryLine %q: %w " , recoveryLine , err )
227
+ return syncedBlocks , 0 , 0 , 0 , fmt .Errorf ("%w: Error parsing float from recoveryLine %q" , ErrFileParse , recoveryLine )
228
228
}
229
229
230
230
// Get time expected left to complete
231
231
matches = recoveryLineFinishRE .FindStringSubmatch (recoveryLine )
232
232
if len (matches ) != 2 {
233
- return syncedBlocks , pct , 0 , 0 , fmt .Errorf ("unexpected recoveryLine matching est. finish time: %s" , recoveryLine )
233
+ return syncedBlocks , pct , 0 , 0 , fmt .Errorf ("%w: Unexpected recoveryLine matching est. finish time: %s" , ErrFileParse , recoveryLine )
234
234
}
235
235
finish , err = strconv .ParseFloat (matches [1 ], 64 )
236
236
if err != nil {
237
- return syncedBlocks , pct , 0 , 0 , fmt .Errorf ("error parsing float from recoveryLine %q : %w " , recoveryLine , err )
237
+ return syncedBlocks , pct , 0 , 0 , fmt .Errorf ("%w: Unable to parse float from recoveryLine: %q " , ErrFileParse , recoveryLine )
238
238
}
239
239
240
240
// Get recovery speed
241
241
matches = recoveryLineSpeedRE .FindStringSubmatch (recoveryLine )
242
242
if len (matches ) != 2 {
243
- return syncedBlocks , pct , finish , 0 , fmt .Errorf ("unexpected recoveryLine matching speed : %s" , recoveryLine )
243
+ return syncedBlocks , pct , finish , 0 , fmt .Errorf ("%w: Unexpected recoveryLine value : %s" , ErrFileParse , recoveryLine )
244
244
}
245
245
speed , err = strconv .ParseFloat (matches [1 ], 64 )
246
246
if err != nil {
247
- return syncedBlocks , pct , finish , 0 , fmt .Errorf ("error parsing float from recoveryLine %q: %w" , recoveryLine , err )
247
+ return syncedBlocks , pct , finish , 0 , fmt .Errorf ("%s: Error parsing float from recoveryLine: %q: %w" , ErrFileParse , recoveryLine , err )
248
248
}
249
249
250
250
return syncedBlocks , pct , finish , speed , nil
0 commit comments