Improve Apps Script relay and example configs#129
Conversation
|
Thanks for this. The Apps Script changes here are solid and I'd like to land them. Before merging, I'd like to trim the config-example pieces, because most of the new fields they introduce aren't read by Keep as-is:
Please drop from this PR (move to #131 alongside the code that reads them):
Could you include a small follow-up in this PR: update line 326 to match the new placeholder, and replace the three Re: deadline removal in Happy to merge as soon as the example-config diff is trimmed. Thanks again. |
|
Updated this PR based on your feedback:
Verification: |
…eam failure (#149) v1.7.0 Code.gs added a try/catch around UrlFetchApp.fetch that, on exception or non-200 from the VPS, swallowed the failure and returned the error as plain text with HTTP 200. The GooseRelay client trusts 200 to mean "the body is a base64 batch" — its non-batch sniffer (isLikelyNonBatchRelayPayload) only recognises HTML quota pages, JSON status, and raw HTTP/. So the new error strings fell through to DecodeBatch, which tried to base64-decode them and failed at the first non-alphabet byte. The user-visible symptom in #149 ("batch: base64 decode: illegal base64 data at input byte 9") is the literal length of "Exception" before the colon — "Exception:" was the most common shape, emitted by Code.gs's catch block whenever the VPS was transiently unreachable from Google's UrlFetchApp egress. This was misattributed in the v1.7.0 release notes to #130 (the EncodeBatch → AppendMarshal migration). The marshaler is fine; the break was in #129 (Code.gs rewrite). Fixes both sides: Code.gs: - All terminal-failure paths now `throw` instead of returning 200 with diagnostic text. Apps Script then surfaces its native HTML error page with HTTP 500, which the client's existing non-200 code path already handles cleanly (mark endpoint failure, rotate to next deployment, no log noise). - Success path unchanged: still 200 with the upstream's base64 batch verbatim. - The per-RELAY_URLS failover loop is preserved — we only throw after every URL has failed. Carrier (defense-in-depth for users who upgrade the client but forget to redeploy Code.gs): - isLikelyNonBatchRelayPayload now sniffs "Exception:", "relay_loop_detected:", "upstream status ", and "upstream fetch error:" prefixes. - classifyRelayErrorBody maps each sentinel to an actionable log message: relay_loop_detected → hard (config error), the rest → soft (transient VPS reachability or non-200 from server). - Four sniffer test cases added. Net effect for affected users: the "illegal base64 data at input byte 9" log line goes away. Transient VPS-unreachable conditions now show up as one clear line per occurrence ("Code.gs could not reach your VPS — check VPS is up, the server_port…") and the carrier rotates to a healthy endpoint instead of retrying-then-dropping.
Summary
This PR improves the Apps Script forwarder and example configs without changing the tunnel protocol.
Changes:
RELAY_URLSsupport for multiple VPS tunnel endpoints.Verification
go test -count=1 ./...go vet ./...Compatibility
The wire protocol is unchanged. Existing client/server deployments continue to work after redeploying
Code.gs.