Skip to content

Harden Noswhere translation response handling and add failure diagnostics#36

Merged
danieldaquino merged 3 commits into
masterfrom
copilot/fix-noswhere-translation-api-issue
May 20, 2026
Merged

Harden Noswhere translation response handling and add failure diagnostics#36
danieldaquino merged 3 commits into
masterfrom
copilot/fix-noswhere-translation-api-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

Malformed or empty responses from the Noswhere translation API could surface as unhandled JSON parse failures during language bootstrap and destabilize the server. This change hardens that path and adds enough response context to make production failures diagnosable.

  • Guard Noswhere JSON parsing

    • Parse /langs and /translate responses from raw text instead of assuming valid JSON.
    • Convert malformed/empty bodies into provider errors with the Noswhere request id attached.
    • Prevent async language-loading failures from escaping the translator constructor.
  • Improve production diagnostics

    • Log response parse failures with:
      • operation (getting translation langs / translating)
      • HTTP status and ok
      • x-noswhere-request
      • a bounded response body snippet
    • Keep the higher-level error surface concise while preserving enough detail in logs for troubleshooting.
  • Add focused regression coverage

    • Cover malformed /langs responses to ensure bootstrap failures are contained and logged.
    • Cover malformed /translate responses to ensure request ids and body snippets are surfaced.
async #parseResponse(resp, action) {
    const requestId = this.#getRequestId(resp)
    const body = await resp.text()
    try {
        return JSON.parse(body)
    } catch (err) {
        console.error(
            "noswhere %s response parse error: status=%s ok=%s request=%s body=%o",
            action,
            resp.status,
            resp.ok,
            requestId,
            this.#getBodySnippet(body)
        )
        throw new Error(`error ${action}: invalid JSON response from Noswhere (request: ${requestId})`)
    }
}

Copilot AI and others added 2 commits May 20, 2026 18:23
Agent-Logs-Url: https://github.com/damus-io/api/sessions/30936094-ca55-465a-9ffa-c7f7bd2d4a58

Co-authored-by: danieldaquino <24692108+danieldaquino@users.noreply.github.com>
Agent-Logs-Url: https://github.com/damus-io/api/sessions/30936094-ca55-465a-9ffa-c7f7bd2d4a58

Co-authored-by: danieldaquino <24692108+danieldaquino@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issues with Noswhere translation API causing server crashes Harden Noswhere translation response handling and add failure diagnostics May 20, 2026
Copilot AI requested a review from danieldaquino May 20, 2026 18:26
@danieldaquino danieldaquino marked this pull request as ready for review May 20, 2026 18:31
@danieldaquino danieldaquino merged commit b5704e8 into master May 20, 2026
1 check passed
@danieldaquino danieldaquino deleted the copilot/fix-noswhere-translation-api-issue branch May 20, 2026 18:37
@danieldaquino
Copy link
Copy Markdown
Collaborator

@copilot I still see this other issue:

May 20 11:47:53 purple damus-api[3841967]: node:internal/process/promises:288
May 20 11:47:53 purple damus-api[3841967]:             triggerUncaughtException(err, true /* fromPromise */);
May 20 11:47:53 purple damus-api[3841967]:             ^
May 20 11:47:53 purple damus-api[3841967]: [UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "undefined".] {
May 20 11:47:53 purple damus-api[3841967]:   code: 'ERR_UNHANDLED_REJECTION'
May 20 11:47:53 purple damus-api[3841967]: }
May 20 11:47:53 purple damus-api[3841967]: Node.js v18.19.0

Please create a new PR to address that

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.

Issues with Noswhere translation API bringing down the server

2 participants