fix(examples): return an error for missing image data - #1509
Merged
Merged
Conversation
Return a descriptive error when save_image_locally loads an artifact without usable inline data instead of returning the stale nil load error. Add tests for nil and empty inline data, and verify that artifact load errors remain unchanged. Fixes google#1508
8 of 9 tasks
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
save_image_locallydetected artifacts without usable inline data but returnedthe stale error value from the preceding successful artifact load. Because that
error was nil, the tool invocation could be treated as successful even though
no image was written.
Solution:
Return a descriptive error when the loaded artifact has no
InlineDataor itsinline payload is empty.
Add tests using the in-memory artifact service for both missing-data shapes and
verify that artifact load errors continue to be returned unchanged.
Behavior change
Calling
save_image_locallywith an artifact that has no usable inline data nowreturns a non-nil error instead of an empty result with a nil error.
Testing Plan
Unit Tests:
With the source change reverted,
TestSaveImageRejectsMissingInlineDatafailsfor both
nil inline dataandempty inline databecausesaveImagereturns anil error.
Commands completed successfully:
go test -race -count=1 ./examples/vertexai/imagegeneratorgo build -mod=readonly workgo test -race -mod=readonly -count=1 -shuffle=on workgo vet ./examples/...golangci-lint runwith the CI-pinned v2.3.1 in both modulesgo mod tidy -diffin both modulesgolangci-lint fmt -dwith the CI-pinned v2.3.1 in both modulesManual End-to-End (E2E) Tests:
Not run. This failure path does not require a live model or API request and is
covered offline using the real in-memory artifact service.
Checklist
CONTRIBUTING.mddocument.Additional context
This is separate from #1477, which covers validation of image-generation API
responses before saving an artifact. This change concerns loading an existing
artifact in
save_image_locally.