Skip to content

Commit 1e23e66

Browse files
Better error messages, and separate out error messages from different conditions to prevent confusion in case of error
1 parent a0f60b5 commit 1e23e66

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

search-replace.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func fixLineWithSerializedData(linePart []byte, replacements []*Replacement) (*S
233233

234234
// this algorithm SHOULD work, but in cases where the original byte count does not match
235235
// the actual byte count, it'll error out. We'll add this safeguard here.
236-
return nil, fmt.Errorf("faulty data, byte count does not match data size")
236+
return nil, fmt.Errorf("faulty serialized data: out-of-bound index access detected")
237237
}
238238
char := linePart[currentContentIndex]
239239
secondChar := linePart[currentContentIndex+1]
@@ -261,7 +261,7 @@ func fixLineWithSerializedData(linePart []byte, replacements []*Replacement) (*S
261261
}
262262

263263
if contentByteCount > originalByteSize {
264-
return nil, fmt.Errorf("faulty data, byte count does not match data size")
264+
return nil, fmt.Errorf("faulty serialized data: calculated byte count does not match given data size")
265265
}
266266

267267
contentByteCount++
@@ -278,7 +278,7 @@ func fixLineWithSerializedData(linePart []byte, replacements []*Replacement) (*S
278278
rebuiltSerializedString := "s:" + strconv.Itoa(contentLength) + ":\\\"" + string(content) + "\\\";"
279279

280280
if nextSliceFound == false {
281-
return nil, fmt.Errorf("end of serialized string not found")
281+
return nil, fmt.Errorf("faulty serialized data: end of serialized data not found")
282282
}
283283

284284
result := SerializedReplaceResult{

0 commit comments

Comments
 (0)