-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Watch/subscribe commands output pretty-printed JSON errors instead of NDJSON #680
Description
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 NDJSONSuggested 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.