fix(go-sdk): surface json.Marshal errors in memory backend requests#679
Open
ardittirana wants to merge 1 commit into
Open
fix(go-sdk): surface json.Marshal errors in memory backend requests#679ardittirana wants to merge 1 commit into
ardittirana wants to merge 1 commit into
Conversation
mustJSONReader discarded the json.Marshal error and returned a reader over a nil byte slice. When a value could not be serialized (unsupported type, cyclic struct, channel, func), the control-plane POST was sent with an empty body — silently storing nothing or overwriting with an empty value — and the real error never reached the caller. Replace it with jsonReader(v any) (io.Reader, error) and propagate the error at each call site (Set, Get, Delete, SetVector, SearchVector), all of which already return an error. Adds a test asserting an unserializable value yields an error instead of an empty reader. Fixes Agent-Field#434.
Member
|
Thanks @ardittirana, this looks good. CLA is still pending. Can you sign it here? https://cla-assistant.io/Agent-Field/agentfield?pullRequest=679 Once that clears, we can continue. |
Author
|
Signed 🫡 |
santoshkumarradha
approved these changes
Jun 22, 2026
Contributor
Performance
✓ No regressions detected |
Contributor
📊 Coverage gateThresholds from
✅ Gate passedNo surface regressed past the allowed threshold and the aggregate stayed above the floor. |
Contributor
📐 Patch coverage gateThreshold: 80% on lines this PR touches vs
❌ Patch gate failed
How to fix
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #434.
Problem
mustJSONReaderdiscarded thejson.Marshalerror:When a value can't be serialized (unsupported type, cyclic struct, channel, func),
json.Marshalreturnsnil, err, the error is dropped, and the function returns a reader over a nil slice. The downstream control-planePOSTis then sent with an empty body — silently storing nothing or overwriting with an empty value — and the real error never reaches the caller, making data-loss bugs in the memory backend very hard to debug.Fix
Replace it with
jsonReader(v any) (io.Reader, error)that returns the marshal error, and propagate that error at each of the five call sites (Set,Get,Delete,SetVector,SearchVector) — all of which already return anerror. No behavior change on the success path. Stdlib only.Test
Updates the existing helper test and adds a case asserting that an unserializable value (a channel) returns an error and a nil reader instead of silently yielding an empty body.
go test ./agent/passes (all existing backend tests included);gofmt/go vetclean.