googleworkspace/cli · error · GwsError
Failed to fetch message: {e}
Error message
Failed to fetch message: {e} What it means
The transport-level failure branch of `fetch_original_message`: `crate::client::send_with_retry` (which already retries transient errors) ultimately failed while GETting `https://gmail.googleapis.com/gmail/v1/users/me/messages/{id}?format=full`. This is a reqwest error after retries were exhausted — HTTP status errors are handled separately via `build_api_error`.
Source
Thrown at crates/google-workspace-cli/src/helpers/gmail/mod.rs:384
pub(super) async fn fetch_message_metadata(
client: &reqwest::Client,
token: &str,
message_id: &str,
) -> Result<OriginalMessage, GwsError> {
let url = format!(
"https://gmail.googleapis.com/gmail/v1/users/me/messages/{}",
crate::validate::encode_path_segment(message_id)
);
let resp = crate::client::send_with_retry(|| {
client
.get(&url)
.bearer_auth(token)
.query(&[("format", "full")])
})
.await
.map_err(|e| GwsError::Other(anyhow::anyhow!("Failed to fetch message: {e}")))?;
if !resp.status().is_success() {
let status = resp.status().as_u16();
let body = resp
.text()
.await
.unwrap_or_else(|_| "(error body unreadable)".to_string());
return Err(build_api_error(
status,
&body,
&format!("Failed to fetch message {message_id}"),
));
}
let msg: Value = resp
.json()
.await
.map_err(|e| GwsError::Other(anyhow::anyhow!("Failed to parse message: {e}")))?;View on GitHub (pinned to a3768d0e82)
Solutions
- Confirm reachability: `curl -sS -o /dev/null -w '%{http_code}' https://gmail.googleapis.com/`.
- Check proxy env vars (HTTPS_PROXY/ALL_PROXY) — reqwest honors them; exempt or fix googleapis.com.
- Retry the command once the network is stable; the helper is stateless and safe to re-run.
- If it persists, enable logging (`GOOGLE_WORKSPACE_CLI_LOG=gws=debug`) to see the underlying reqwest cause.
Defensive patterns
Strategy: retry
Validate before calling
// Cheap connectivity check before a reply/forward flow that must fetch the message
if std::net::TcpStream::connect("gmail.googleapis.com:443").is_err() {
eprintln!("gmail.googleapis.com unreachable — check network before replying");
} Try / catch
// Distinguish transport failure (retry) from API errors (surface):
match fetch_original_message(client, token, id).await {
Err(GwsError::Other(e)) if e.to_string().starts_with("Failed to fetch message") => retry_with_backoff(id).await,
Err(e) => return Err(e),
Ok(m) => m,
} Prevention
- send_with_retry already retries — wrap caller-side retries with backoff so you do not hammer a dead network.
- Keep googleapis.com domains reachable (proxy allowlist) in CI and corporate environments.
- Treat this error as environmental (network), not auth — auth failures come back as GwsError::Api.
When it happens
Trigger: No network / DNS failure to gmail.googleapis.com; TLS interception proxy rejecting the request; token present but connection dropped mid-body repeatedly so all retry attempts fail; extremely large message bodies timing out on every attempt.
Common situations: Running `gws gmail +reply`/`+forward` offline or behind a corporate proxy; flaky tethered connections; CI runners with blocked egress to googleapis.com.
Related errors
- Failed to fetch sendAs settings: {e}
- People API request failed: {e}
- Failed to fetch attachment: {e}
- Failed to fetch user profile: {e}
- Pub/Sub pull failed: {e}
AI-assisted analysis of googleworkspace/cli@a3768d0e82 (2026-08-16).
Data as JSON: /api/errors/0f902436a3912666.
Report an issue: GitHub.