Skip to content

Commit eff7707

Browse files
committed
fix(pr-review): restored the try/catch in _doSingle, remove EXIT_DIAG debug logging
1 parent 23464f3 commit eff7707

2 files changed

Lines changed: 40 additions & 20 deletions

File tree

assets/apps_script/Code.gs

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ function _doSingle(req) {
161161
return _json({ e: "bad url" });
162162
}
163163

164+
// ── Optional cache path ────────────────────────────────
165+
// Only entered when CACHE_SPREADSHEET_ID is configured and
166+
// the request qualifies as a public, cachable GET.
164167
if (_canUseCache(req)) {
165168
var cached = _getFromCache(req.u, req.h);
166169
if (cached) {
@@ -181,25 +184,41 @@ function _doSingle(req) {
181184
cached: false,
182185
});
183186
}
184-
// _fetchAndCache returned null → fall through to normal relay
185-
}
186-
187-
var opts = _buildOpts(req);
188-
var resp = UrlFetchApp.fetch(req.u, opts);
187+
// If _fetchAndCache returns null (spreadsheet unavailable),
188+
// fall through to the normal relay path below.
189+
}
190+
191+
// ── Normal relay (cache disabled or unavailable) ────────
192+
// Wrap the fetch + body encode in try/catch so any failure surfaces as
193+
// a JSON error envelope the Rust client can parse. Without this, throws
194+
// from UrlFetchApp.fetch (URL too long, payload too large, quota
195+
// exhausted, 6-minute execution timeout) or from base64Encode (response
196+
// body near Apps Script's ~50 MB ceiling can blow the V8 heap during
197+
// encode) propagate unhandled, and Apps Script serves its default
198+
// `<title>Web App</title>` HTML error page — which the client then
199+
// reports as "Relay failed: bad response: no json in: <title>Web App>..."
200+
// and the user has no signal as to the actual cause. Mirrors the
201+
// per-item try/catch in _doBatch below.
202+
try {
203+
var opts = _buildOpts(req);
204+
var resp = UrlFetchApp.fetch(req.u, opts);
205+
206+
// Raw-return mode for exit-node path.
207+
// r:true = return destination body verbatim so Rust gets {s,h,b} unwrapped.
208+
if (req.r === true) {
209+
return ContentService
210+
.createTextOutput(resp.getContentText())
211+
.setMimeType(ContentService.MimeType.JSON);
212+
}
189213

190-
// Raw-return mode for exit-node path.
191-
// r:true = return destination body verbatim so Rust gets {s,h,b} unwrapped.
192-
if (req.r === true) {
193-
return ContentService
194-
.createTextOutput(resp.getContentText())
195-
.setMimeType(ContentService.MimeType.JSON);
214+
return _json({
215+
s: resp.getResponseCode(),
216+
h: _respHeaders(resp),
217+
b: Utilities.base64Encode(resp.getContent()),
218+
});
219+
} catch (err) {
220+
return _json({ e: "fetch failed: " + String(err) });
196221
}
197-
198-
return _json({
199-
s: resp.getResponseCode(),
200-
h: _respHeaders(resp),
201-
b: Utilities.base64Encode(resp.getContent()),
202-
});
203222
}
204223

205224
// ── Batch Request ──────────────────────────────────────────

src/domain_fronter.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,14 +2686,15 @@ impl DomainFronter {
26862686
.send_prebuilt_payload_through_relay(outer_payload)
26872687
.await?;
26882688

2689-
tracing::warn!(
2689+
// temporary diagnostics for exit-node response debugging.
2690+
// Logs the raw app_body before parse_exit_node_response() is called.
2691+
tracing::debug!(
26902692
"EXIT_DIAG app_body len={} first_200={:?}",
26912693
app_body.len(),
26922694
String::from_utf8_lossy(&app_body[..app_body.len().min(200)])
26932695
);
26942696

26952697
let result = parse_exit_node_response(&app_body);
2696-
tracing::warn!("EXIT_DIAG parse_result ok={}", result.is_ok());
26972698
result
26982699
}
26992700

@@ -3969,7 +3970,7 @@ fn unix_to_ymd_utc(secs: u64) -> (i64, u32, u32) {
39693970
fn parse_exit_node_response(body: &[u8]) -> Result<Vec<u8>, FronterError> {
39703971
let json_start = body
39713972
.windows(4)
3972-
.position(|w| w == b"\r\n\r\n")
3973+
.position(|w| w == b"\r\n\r\n")
39733974
.map(|i| i + 4)
39743975
.unwrap_or(0);
39753976
let json_bytes = &body[json_start..];

0 commit comments

Comments
 (0)