refactor(go): refactor go error processing #3069
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why?
The Go serializer interface methods previously returned
errorvalues, requiring error checking at every call site. This pattern was inconsistent with the C++ implementation and led to verbose, repetitive error handling code throughout the codebase.What does this PR do?
Refactors Go error handling to use a centralized delayed error pattern, similar to the C++ implementation:
Interface Changes
error:Write(ctx *WriteContext, refMode RefMode, writeType bool, value reflect.Value)WriteData(ctx *WriteContext, value reflect.Value)Read(ctx *ReadContext, refMode RefMode, readType bool, value reflect.Value)ReadData(ctx *ReadContext, type_ reflect.Type, value reflect.Value)ReadWithTypeInfo(ctx *ReadContext, refMode RefMode, typeInfo *TypeInfo, value reflect.Value)Error Handling Pattern
ctx.SetError(FromError(err))orctx.SetError(DeserializationErrorf(...))if ctx.HasError() { return }ctx.CheckError()orctx.TakeError()Files Modified
Benefits
Related issues
#2982 #3012
Closes #3026
Does this PR introduce any user-facing change?
Serializerinterface method signatures have changed (no longer returnerror)Fory.Serialize()andFory.Deserialize()APIs remain unchangedBenchmark
No performance regression expected - this is a refactoring of error handling flow, not serialization logic.