examples/vertexai/imagegenerator: save_image_locally returns a nil error when image data is missing
- Dominant language
- Go
- Stars
- 8.8k
- Forks
- 1k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 88
Description
## Required Information
**Describe the Bug:**
The `save_image_locally` tool detects when a loaded artifact does not contain usable inline image data, but returns the previous `err` value:
```go
resp, err := ctx.Artifacts().Load(ctx, filename)
if err != nil {
return saveImageResult{}, err
}
if resp.Part.InlineData == nil || len(resp.Part.InlineData.Data) == 0 {
log.Printf("Artifact '%s' has no inline data", filename)
return saveImageResult{}, err
}
```
Reaching the second condition means the artifact load succeeded, so `err` must be nil. The handler therefore returns an empty result with a nil error even though no image was written.
**Steps to Reproduce:**
1. Have the artifact service successfully load an artifact without inline image data, such as a text artifact:
```go
&artifact.LoadResponse{
Part: genai.NewPartFromText("not image data"),
}, nil
```
2. Invoke `saveImage` with that artifact's filename.
3. Observe the following log:
```text
Artifact '' has no inline data
```
4. The function returns `saveImageResult{}` with a nil error, and no output file is created.
**Expected Behavior:**
`saveImage` should return a descriptive non-nil error when the loaded artifact has no inline data or contains an empty inline-data payload.
**Observed Behavior:**
The missing-data condition returns the stale nil error from the successful artifact load. As a result, the tool invocation may be treated as successful even though no image was saved.
**Environment Details:**
- ADK Library Version: `main` at `a611472`
- OS: macOS arm64
- Go Version: `go1.26.6`
**Model Information:**
N/A. The behavior can be reproduced with a constructed artifact response without making a model request.
## Optional Information
**Regression:**
Unknown. The current implementation returns the error value from the preceding successful artifact load.
**Logs:**
```text
Artifact '' has no inline data
```
**Screenshots / Video:**
N/A.
**Additional Context:**
This is separate from #1477. That issue covers validation of image-generation API responses before saving an artifact. This issue concerns `save_image_locally` loading an existing artifact that does not contain usable image bytes.
The failure path should return a newly constructed error. Unit tests should cover both a nil `InlineData` field and an empty `InlineData.Data` payload.
**How often has this issue occurred?:**
Always when artifact loading succeeds but the loaded artifact contains no usable inline image data.
Contributor guide
Research direction
Start at save_image_locally in examples/vertexai/imagegenerator and inspect the branch handling a nil InlineData field or empty Data payload. Add unit coverage for both missing-data cases and run the relevant package tests. Done means the function returns a descriptive non-nil error and does not report success when no image is saved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- ai
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100