Skip to content

fix: resolve QueryFailedError in api - #3182

Open
oneuptime-test[bot] wants to merge 1 commit into
masterfrom
oneuptime-fix-exception-dc2b5c0f
Open

fix: resolve QueryFailedError in api#3182
oneuptime-test[bot] wants to merge 1 commit into
masterfrom
oneuptime-fix-exception-dc2b5c0f

Conversation

@oneuptime-test

Copy link
Copy Markdown

Exception Fix

This pull request was automatically generated by OneUptime AI Agent to fix an exception.

Exception Details

Service: api
Type: QueryFailedError
Message (dynamic values and secrets redacted): index row size 2792 exceeds btree version 4 maximum 2704 for index ""

Stack Trace

QueryFailedError: index row size 2792 exceeds btree version 4 maximum 2704 for index "<ID>"
    at PostgresQueryRunner.query (/usr/src/Common/node_modules/typeorm/src/driver/postgres/PostgresQueryRunner.ts:325:19)
    at processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async UpdateQueryBuilder.execute (/usr/src/Common/node_modules/src/query-builder/UpdateQueryBuilder.ts:145:33)
    at async Service._updateBy (/usr/src/Common/Server/Services/DatabaseService.ts:2266:46)
    at async Service.updateOneBy (/usr/src/Common/Server/Services/DatabaseService.ts:2398:12)
    at async Service.updateOneById (/usr/src/Common/Server/Services/DatabaseService.ts:2446:12)
    at async StatusPageAPI.updateItem (/usr/src/Common/Server/API/BaseAPI.ts:450:42)
    at async /usr/src/Common/Server/API/BaseAPI.ts:131:11

Summary of Changes

Summary

Root Cause: The error index row size 2792 exceeds btree version 4 maximum 2704 for index "<ID>" is a PostgreSQL error (SQLSTATE 54000 - INDEX_TOO_BIG) that occurs when a value being stored in an indexed column exceeds PostgreSQL's btree index maximum row size (~2704 bytes). This error was not being translated by the PostgresErrorTranslator, so it bubbled up as a raw QueryFailedError resulting in a generic 500 "Server Error" response.

Fix: Added handling for the PostgreSQL 54000 (INDEX_TOO_BIG) error code in Common/Server/Utils/Database/PostgresErrorTranslator.ts:

  1. Added INDEX_TOO_BIG: string = "54000" constant alongside existing error codes
  2. Added message?: string | undefined to the PostgresDriverError interface to access the error message content
  3. Added a check for INDEX_TOO_BIG in the translate() method
  4. Added translateIndexTooBig() private method that:
    • Verifies the error is specifically a btree index-too-big error by checking for "exceeds btree version" in the message
    • Returns a user-friendly BadDataException with the message: "The value you are trying to save is too long. Please shorten the value and try again."
    • Tags the exception with the PostgreSQL error code for downstream consumers
    • Falls through to the original error for other 54000 variants (e.g., "program too large")

This follows the existing code patterns and conventions, keeping the fix minimal and focused on the specific error case.


Review before merging. The fix is AI-authored: verify it actually addresses the exception before approving. Nothing is merged automatically.

This PR was automatically generated by OneUptime AI Agent

ℹ️ Verification

Not verified — the repository has no setup/build/test commands configured. Configure them on the code repository to have fixes verified before the pull request opens.

This commit fixes an exception detected by OneUptime.

Exception Type: QueryFailedError
Exception ID: 64f39b1c-9f15-4f62-b64d-6a098d2c7889

Automatically generated by OneUptime AI Agent.
@simlarsen

Copy link
Copy Markdown
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

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