chenhg5/cc-connect · error

googlechat: upload: empty resourceName in response

Error message

googlechat: upload: empty resourceName in response

What it means

Returned by uploadAttachment when the Chat upload response decodes successfully but attachmentDataRef.resourceName is empty — the server acknowledged the upload but did not return the attachment reference needed to send the message. This indicates an unexpected/empty API response for the upload. It surfaces via postAttachment from SendImage/SendFile.

Solutions

  1. Log the full decoded response to see what fields the server actually returned.
  2. Verify the OAuth scopes cover media upload with send permission.
  3. Retry the upload — transient server-side issues can yield empty refs.
  4. Check the Google Workspace API release notes / issue tracker for Chat upload response schema changes and update the library.
Defensive patterns

Strategy: retry

Validate before calling

// avoid zero-byte uploads which can produce empty refs
fi, err := os.Stat(path)
if err != nil || fi.Size() == 0 {
    return fmt.Errorf("refusing to upload empty or missing file %q", path)
}

Try / catch

name, err := p.SendFile(ctx, target, path)
if err != nil && strings.Contains(err.Error(), "empty resourceName") {
    time.Sleep(2 * time.Second)
    return p.SendFile(ctx, target, path)
}

Prevention

When it happens

Trigger: Calling SendImage()/SendFile(); the upload endpoint responds with JSON lacking attachmentDataRef.resourceName — e.g. the API changed its response shape or an edge response omitted the ref.

Common situations: Google Chat API behavior changes; uploading with a scope the API accepts only partially (auth issues); zero-byte or unusual payloads causing the server to skip the attachment ref.

Understand the failure class

Background: "empty response", "returned no data", "empty embeddings": what HTTP 200-with-empty-body errors mean across libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/0cd7d58d49860ff2. Report an issue: GitHub.

Appendix: source

Thrown at platform/googlechat/googlechat.go:504

		return "", err
	}
	defer func() {
		if err := resp.Body.Close(); err != nil {
			slog.Warn("googlechat: close upload response body", "error", err)
		}
	}()

	var result struct {
		AttachmentDataRef struct {
			ResourceName string `json:"resourceName"`
		} `json:"attachmentDataRef"`
	}
	defer func() { _, _ = io.Copy(io.Discard, resp.Body) }()
	if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
		return "", fmt.Errorf("googlechat: upload: decode response: %w", err)
	}
	if result.AttachmentDataRef.ResourceName == "" {
		return "", fmt.Errorf("googlechat: upload: empty resourceName in response")
	}
	return result.AttachmentDataRef.ResourceName, nil
}

// buildAttachmentRequest builds the Chat REST API URL and JSON body to post a
// message that references an already-uploaded attachment (by resource name).
// Threading behaviour mirrors buildSendRequest.
func buildAttachmentRequest(rc replyContext, resourceName string) (string, []byte, error) {
	body := map[string]any{
		"attachment": []map[string]any{
			{"attachmentDataRef": map[string]any{"resourceName": resourceName}},
		},
	}
	applyThread(body, rc)
	b, err := json.Marshal(body)
	if err != nil {
		return "", nil, fmt.Errorf("googlechat: marshal attachment body: %w", err)
	}

View on GitHub (pinned to 4000b2338a)