Skip to content

fix(sqlite): reject promise on getAll query failure (#180)#353

Open
JacobiusMakes wants to merge 1 commit intolinagora:devfrom
JacobiusMakes:fix/180-sqlite-getall-error
Open

fix(sqlite): reject promise on getAll query failure (#180)#353
JacobiusMakes wants to merge 1 commit intolinagora:devfrom
JacobiusMakes:fix/180-sqlite-getall-error

Conversation

@JacobiusMakes
Copy link
Copy Markdown

@JacobiusMakes JacobiusMakes commented Mar 29, 2026

What

Add proper error handling for db.prepare() failures in SQLite _get() and _getMinMax() methods. When a SQL statement fails to prepare, the promise now rejects instead of hanging forever.

Why

When db.prepare(query) fails silently, stmt.all() callback is never called, leaving the promise unresolved indefinitely. This causes the application to hang with no error output, making debugging extremely difficult.

Fixes #180

How

Changed db.prepare(query) to use the error callback so preparation errors trigger a proper rejection. Added try-catch wrapper as safety net. Applied to both the shared db package and the identity server db.

When a SQLite query fails during statement preparation (e.g., invalid
table name or malformed SQL), the promise returned by _get() and
_getMinMax() would hang indefinitely because db.prepare() could fail
without calling the stmt.all() callback.

This change uses the prepare() callback to catch preparation errors and
properly reject the promise. A try-catch wrapper is also added as a
safety net for synchronous throws.

Fixes: linagora#180

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3f0ece5a-907b-4894-be48-2ba7ff3a3de6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pm-McFly pm-McFly changed the base branch from master to dev March 30, 2026 08:27
@pm-McFly
Copy link
Copy Markdown
Collaborator

@JacobiusMakes thank you again for that changes suggestion!

A note for the future though..
We are happy to receive your contribution, we encourage you to open PRs manually thus engaging in a deeper discussion showing us why this change matters to you as well as a telling of your point of view regarding the "How" you fixed it.

We provide a PR template that aims to help you write about this:

## What

<!-- A concise description of what this PR changes. One paragraph is enough. -->

## Why

<!-- Why is this change needed? Link the issue it addresses. -->

<!-- If any related issues -->
Closes #

## How

<!-- Non-obvious implementation decisions, trade-offs, or anything a reviewer should know before reading the diff. Skip if the why + diff are self-explanatory. -->

I wish you a happy contribution!

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 30, 2026

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 3882cd0

Command Status Duration Result
nx affected -t check ❌ Failed 5s View ↗
nx affected -t test ✅ Succeeded 3m 10s View ↗
nx affected -t build ✅ Succeeded 17s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-30 15:44:02 UTC

Copy link
Copy Markdown
Collaborator

@pm-McFly pm-McFly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- please rebase dev on your branch and check the conflicts to proceed forward with more test runs :)


Worth noting (side notes to self):

A few issues exist in the surrounding code (double-rejection risk, stmt reference timing, silent finalize errors after resolve) but these all predate this PR and are out of scope here. This change is a net improvement: surfacing prepare() failures was a real gap and the added error handling is solid.

The broader issues are worth addressing properly as part of a larger DB module overhaul rather than piecemeal...

@pm-McFly pm-McFly added bug Something does not behave as expected. package::federation-server package::identity-server package::tom-server javascript Pull requests that update javascript code labels Mar 31, 2026
@pm-McFly pm-McFly force-pushed the dev branch 2 times, most recently from 5950f13 to fbcc854 Compare April 8, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something does not behave as expected. javascript Pull requests that update javascript code package::federation-server package::identity-server package::tom-server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[matrix-identity-server] No errors when getAll request fail - SQLite

2 participants