Skip to content

Watch/subscribe commands output pretty-printed JSON errors instead of NDJSON #680

@localrivet

Description

@localrivet

Problem

The gmail +watch and events +subscribe commands output NDJSON for normal events, but when an error occurs (e.g., 401 auth failure), the error JSON is pretty-printed across multiple lines:

{
  "error": {
    "code": 401,
    "message": "Failed to get Pub/Sub token: Failed to get token",
    "reason": "authError"
  }
}

Consumers that parse stdout line-by-line (the expected NDJSON protocol) get individual lines like {, "error": {, "code": 401, — none of which are valid JSON.

Expected

Errors should be emitted as single-line NDJSON, matching the protocol used for normal events:

{"error":{"code":401,"message":"Failed to get Pub/Sub token: Failed to get token","reason":"authError"}}

Impact

This breaks any automation that consumes the NDJSON stream — the parser sees malformed lines and discards the error. The consumer has no idea the watch process is failing.

Version

gws 0.22.5

Reproduction

# Expire or revoke OAuth tokens, then:
gws gmail +watch --project my-project
# Error output is pretty-printed, not NDJSON

Suggested Fix

Use compact JSON serialization (serde_json::to_string instead of serde_json::to_string_pretty, or the equivalent) for all stdout output in watch/subscribe commands — both events and errors.

Alternatively, errors could go to stderr (where they arguably belong), but that would be a protocol change. The minimal fix is just compact JSON on stdout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions