Skip to content

Report errors instead of swallowing them - #4

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784999794-error-handling
Open

Report errors instead of swallowing them#4
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784999794-error-handling

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Every one of the 88 try/catch blocks in JS/GF-1.js only logged when run_console was true — the default is false, so in production every thrown error disappeared with no trace and the function silently returned undefined. AJAX failures were worse: only 400/404 reached the caller's callback, so 500, 403, redirects, DNS/connection errors and timeouts left the callback never invoked at all.

All catches now go through one reporter that always surfaces the error and can be routed to the host app:

catch (e) { if (run_console) { _writeLog("_getById -> " + e); } }   // before
catch (e) { _reportError("_getById", e); }                          // after

function _reportError(c, e) {  // always console.error, _writeLog only when run_console
    if (_isFunction(_onError)) { try { _onError(e, c); } catch (x) { console.error(x); } }
    ...
}
_setErrorHandler(function (error, source) { myLogger.send(source + " -> " + error); });

XHR (_requestGET/_requestPUT/_requestPOST/_requestDELETE/_loadDoc) now propagates every failure exactly once, guarded by a per-request _settled flag so the callback can't fire twice:

// before: only 400/404, and checked before readyState 4
if (this.status == 400 || this.status == 404) { fu(this.status); return false; }
// after
if (this.readyState == 4 && (this.status < 200 || this.status > 299)) { _reportError(name, "Request failed with status " + this.status); fu(this.status); return false; }
x.onerror   = ... _reportError(name, "Network error...")   ; fu(0);
x.ontimeout = ... _reportError(name, "Request timed out")  ; fu(0);

Also fixed / tightened:

  • _requestDELETE declared const ___rp inside try, so its own catch threw ReferenceError: ___rp is not defined while reporting an error — now var.
  • A 203 ("request denied") response used to be dropped silently; it is reported and forwarded to the callback.
  • _getLocation's geolocation error handler (permission denied, timeout, ...) did nothing unless run_console was on.
  • _import had no scr.onerror: a script that failed to load never called back — now reports and calls fu(false).
  • _checkInternet(st) threw on a missing argument (st.url) and reported disconnection through _writeLog; guards st and reports through _reportError.

README.md documents _setErrorHandler and the AJAX failure contract.

Testing

No test suite in the repo. Verified with node --check and a jsdom harness: DOM/cookie/storage/validation helpers behave as before, a forced throw reaches both console.error and a custom handler, and against a local HTTP server _requestGET now yields 500 and 0 (connection refused) to the callback where it previously yielded nothing.

Link to Devin session: https://app.devin.ai/sessions/1cf7098921c149a780cc76a11ec7ba1c
Requested by: @lamhotsimamora

Errors were only logged when run_console was enabled and AJAX failures other than 400/404 were dropped.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@lamhotsimamora lamhotsimamora self-assigned this Jul 25, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant