From 1deda07306d0d3f5ca89d9c80b6bcda7b16ee09b Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Wed, 12 Feb 2025 11:06:30 -0800 Subject: [PATCH] Refactor error variables to improve pkgsite clarity (#160) Use individual var declarations instead of a block declaration. --- jsontext/state.go | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/jsontext/state.go b/jsontext/state.go index 6c373b0..d6b2f02 100644 --- a/jsontext/state.go +++ b/jsontext/state.go @@ -15,30 +15,30 @@ import ( "github.com/go-json-experiment/json/internal/jsonwire" ) -var ( - // ErrDuplicateName indicates that a JSON token could not be - // encoded or decoded because it results in a duplicate JSON object name. - // This error is directly wrapped within a [SyntacticError] when produced. - // - // The name of a duplicate JSON object member can be extracted as: - // - // err := ... - // var serr jsontext.SyntacticError - // if errors.As(err, &serr) && serr.Err == jsontext.ErrDuplicateName { - // ptr := serr.JSONPointer // JSON pointer to duplicate name - // name := ptr.LastToken() // duplicate name itself - // ... - // } - // - // This error is only returned if [AllowDuplicateNames] is false. - ErrDuplicateName = errors.New("duplicate object member name") - - // ErrNonStringName indicates that a JSON token could not be - // encoded or decoded because it is not a string, - // as required for JSON object names according to RFC 8259, section 4. - // This error is directly wrapped within a [SyntacticError] when produced. - ErrNonStringName = errors.New("object member name must be a string") +// ErrDuplicateName indicates that a JSON token could not be +// encoded or decoded because it results in a duplicate JSON object name. +// This error is directly wrapped within a [SyntacticError] when produced. +// +// The name of a duplicate JSON object member can be extracted as: +// +// err := ... +// var serr jsontext.SyntacticError +// if errors.As(err, &serr) && serr.Err == jsontext.ErrDuplicateName { +// ptr := serr.JSONPointer // JSON pointer to duplicate name +// name := ptr.LastToken() // duplicate name itself +// ... +// } +// +// This error is only returned if [AllowDuplicateNames] is false. +var ErrDuplicateName = errors.New("duplicate object member name") + +// ErrNonStringName indicates that a JSON token could not be +// encoded or decoded because it is not a string, +// as required for JSON object names according to RFC 8259, section 4. +// This error is directly wrapped within a [SyntacticError] when produced. +var ErrNonStringName = errors.New("object member name must be a string") +var ( errMissingValue = errors.New("missing value after object name") errMismatchDelim = errors.New("mismatching structural token for object or array") errMaxDepth = errors.New("exceeded max depth")