Remove optional offset and fallback, guarantee offset by construction
ParserError.Offset is now a plain exported int field, always set: - The parser sets it via setErrOffset() when capturing parse errors - strict.go sets it from the key's Raw range at construction - wrapDecodeError computes it inline from cap(document) - cap(highlight) This eliminates: - The SetOffset/Offset() accessor methods and offsetValid flag - The subsliceOffset fallback function in errors.go - Any conditional logic around whether the offset is present The offset is guaranteed by construction at every path that creates or consumes a ParserError. Co-authored-by: Thomas Pelletier <thomas@pelletier.dev>
This commit is contained in:
@@ -766,7 +766,7 @@ func TestErrorHighlightPositions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParserError_CachedOffset(t *testing.T) {
|
||||
func TestParserError_Offset(t *testing.T) {
|
||||
examples := []struct {
|
||||
desc string
|
||||
input string
|
||||
@@ -803,12 +803,8 @@ func TestParserError_CachedOffset(t *testing.T) {
|
||||
if !errors.As(err, &perr) {
|
||||
t.Fatalf("expected ParserError, got %T", err)
|
||||
}
|
||||
offset, ok := perr.Offset()
|
||||
if !ok {
|
||||
t.Fatal("expected offset to be set")
|
||||
}
|
||||
if offset != e.wantOffset {
|
||||
t.Errorf("cached offset: got %d, want %d", offset, e.wantOffset)
|
||||
if perr.Offset != e.wantOffset {
|
||||
t.Errorf("offset: got %d, want %d", perr.Offset, e.wantOffset)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user