fix(db): centralize DB_AHEAD marker as shared const (Sourcery on PR #64)#65
Conversation
Sourcery flagged that `lib.rs::setup` was using
`e.strip_prefix("Failed to init SQLite: DB_AHEAD::")` — fragile
because any future change to the upstream wrapping in
`setup_result` would silently break the detection and the
STARTUP_BLOCKED.txt notice would never be written for the very
case the hardening was meant to catch.
Fix:
- Extract the marker as `pub const db::DB_AHEAD_MARKER`. Single
source of truth on both sides — producer in `init_pool` and
consumer in `lib.rs` reference the same constant.
- Consumer now uses `e.find(db::DB_AHEAD_MARKER)` instead of
`strip_prefix("Failed to init SQLite: DB_AHEAD::")`. Robust to
any wrapping; the marker contains `::` so false positives in
plain-French error messages are not realistic.
- New `db_ahead_marker_is_findable_even_when_wrapped` test
exercises 4 distinct wrappings (current, alternative, none,
multi-layer) to lock the contract.
Also clarified the comment in lib.rs about path semantics: the
notice file lives in `dirs::data_dir().join("getpostcraft")`
NEXT TO `app.db`, not in the log dir (which uses the bundle
identifier `app.getpostcraft` on Windows — a Tauri/Windows
quirk).
Tests: Rust 205/205 (was 204/204), clippy + fmt clean.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Guide du réviseurCentralise le marqueur Diagramme de séquence pour la production et la gestion de l’erreur
|
| Changement | Détails | Fichiers |
|---|---|---|
Centraliser le marqueur DB_AHEAD et mettre à jour la construction de l’erreur dans init_pool pour l’utiliser. |
|
src-tauri/src/db/mod.rs |
Rendre le consommateur dans lib.rs robuste face à l’empaquetage amont des erreurs en recherchant le marqueur partagé et en extrayant dynamiquement la charge utile. |
|
src-tauri/src/lib.rs |
Ajouter un test de régression vérifiant que le marqueur DB_AHEAD reste détectable sous plusieurs schémas d’empaquetage. |
|
src-tauri/src/db/mod.rs |
Conseils et commandes
Interagir avec Sourcery
- Déclencher une nouvelle revue : Commentez
@sourcery-ai reviewsur la pull request. - Poursuivre les discussions : Répondez directement aux commentaires de revue de Sourcery.
- Générer une issue GitHub à partir d’un commentaire de revue : Demandez à Sourcery de créer une issue à partir d’un commentaire de revue en y répondant. Vous pouvez aussi répondre à un commentaire de revue avec
@sourcery-ai issuepour créer une issue à partir de celui-ci. - Générer un titre de pull request : Écrivez
@sourcery-ain’importe où dans le titre de la pull request pour générer un titre à tout moment. Vous pouvez aussi commenter@sourcery-ai titlesur la pull request pour (re)générer le titre à tout moment. - Générer un résumé de pull request : Écrivez
@sourcery-ai summaryn’importe où dans le corps de la pull request pour générer un résumé de PR exactement à l’endroit souhaité. Vous pouvez aussi commenter@sourcery-ai summarysur la pull request pour (re)générer le résumé à tout moment. - Générer un guide du réviseur : Commentez
@sourcery-ai guidesur la pull request pour (re)générer le guide du réviseur à tout moment. - Résoudre tous les commentaires Sourcery : Commentez
@sourcery-ai resolvesur la pull request pour résoudre tous les commentaires Sourcery. Utile si vous avez déjà traité tous les commentaires et ne souhaitez plus les voir. - Rejeter toutes les revues Sourcery : Commentez
@sourcery-ai dismisssur la pull request pour rejeter toutes les revues Sourcery existantes. Particulièrement utile si vous voulez repartir de zéro avec une nouvelle revue — n’oubliez pas de commenter@sourcery-ai reviewpour déclencher une nouvelle revue !
Personnaliser votre expérience
Accédez à votre tableau de bord pour :
- Activer ou désactiver des fonctionnalités de revue telles que le résumé de pull request généré par Sourcery, le guide du réviseur, et d’autres.
- Changer la langue de la revue.
- Ajouter, supprimer ou modifier des instructions de revue personnalisées.
- Ajuster d’autres paramètres de revue.
Obtenir de l’aide
- Contactez notre équipe support pour toute question ou tout retour.
- Consultez notre documentation pour des guides détaillés et plus d’informations.
- Restez en contact avec l’équipe Sourcery en nous suivant sur X/Twitter, LinkedIn ou GitHub.
Original review guide in English
Reviewer's Guide
Centralizes the DB_AHEAD marker into a shared constant, updates producer/consumer error handling to use it via substring search instead of a hard-coded prefix, clarifies startup-block notice comments, and adds a regression test ensuring the marker remains detectable under various error wrappings.
Sequence diagram for DB_AHEAD_MARKER error production and handling
sequenceDiagram
actor User
participant Run as lib_run
participant DB as db_init_pool
participant Checker as check_db_is_not_ahead_of_binary
participant Notice as write_startup_blocked_notice
User->>Run: run()
Run->>DB: init_pool()
DB->>Checker: check_db_is_not_ahead_of_binary(pool)
Checker-->>DB: Err(e)
DB-->>Run: Err(DB_AHEAD_MARKER + e)
Run->>Run: find(db::DB_AHEAD_MARKER)
alt marker_found
Run->>Notice: write_startup_blocked_notice(payload)
Run-->>User: Err(e)
else marker_not_found
Run-->>User: Err(e)
end
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Centralize DB_AHEAD marker and update init_pool error construction to use it. |
|
src-tauri/src/db/mod.rs |
| Make lib.rs consumer robust to upstream error wrapping by searching for the shared marker and extracting the payload dynamically. |
|
src-tauri/src/lib.rs |
| Add regression test asserting the DB_AHEAD marker remains discoverable under multiple wrapping patterns. |
|
src-tauri/src/db/mod.rs |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull
request title to generate a title at any time. You can also comment
@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in
the pull request body to generate a PR summary at any time exactly where you
want it. You can also comment@sourcery-ai summaryon the pull request to
(re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull
request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the
pull request to resolve all Sourcery comments. Useful if you've already
addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull
request to dismiss all existing Sourcery reviews. Especially useful if you
want to start fresh with a new review - don't forget to comment
@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request
summary, the reviewer's guide, and others. - Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
There was a problem hiding this comment.
Hey - j’ai laissé quelques retours d’ensemble :
- Envisagez d’extraire la logique de
find/découpage du payload dans un petit helper (par ex.db::extract_db_ahead_payload(&str) -> Option<&str>) afin quelib.rset le test de régression partagent une seule implémentation pour localiser et retirerDB_AHEAD_MARKER.
Invite pour les agents IA
Veuillez traiter les commentaires de cette revue de code :
## Commentaires généraux
- Envisagez d’extraire la logique de `find`/découpage du payload dans un petit helper (par ex. `db::extract_db_ahead_payload(&str) -> Option<&str>`) afin que `lib.rs` et le test de régression partagent une seule implémentation pour localiser et retirer `DB_AHEAD_MARKER`.Sourcery est gratuit pour l’open source — si vous aimez nos revues, pensez à les partager ✨
Original comment in English
Hey - I've left some high level feedback:
- Consider extracting the
find/payload-slicing logic into a small helper (e.g.db::extract_db_ahead_payload(&str) -> Option<&str>) so bothlib.rsand the regression test share a single implementation for locating and strippingDB_AHEAD_MARKER.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the `find`/payload-slicing logic into a small helper (e.g. `db::extract_db_ahead_payload(&str) -> Option<&str>`) so both `lib.rs` and the regression test share a single implementation for locating and stripping `DB_AHEAD_MARKER`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
PR #65 follow-up. Sourcery flagged the find-and-slice for the DB_AHEAD payload as duplicated logic between lib.rs and the regression test. One implementation is better. - New `pub fn extract_db_ahead_payload(err: &str) -> Option<&str>` in `db/mod.rs`. Returns `Some(payload)` when the marker is in the string, `None` otherwise. lib.rs and the test now both consume this helper. - Negative-case test added: unrelated errors (sidecar timeout, out-of-disk-space, window builder errors, empty string) must return None — otherwise STARTUP_BLOCKED.txt would get written for unrelated failures and dilute its signal. Tests: Rust 207/207 (was 205), clippy + fmt clean. Five db_ahead* tests now cover the helper end-to-end: - passes on fresh install - passes when DB matches binary - blocks when DB has future migration - extracts even when wrapped - returns None when marker absent Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sourcery feedback on the freshly-merged PR #64
Fix
pub const db::DB_AHEAD_MARKER = "DB_AHEAD::"— single source of truth.init_pool(producer) uses the constant via interpolation.lib.rs::setup(consumer) usese.find(db::DB_AHEAD_MARKER)instead ofstrip_prefix("Failed to init SQLite: DB_AHEAD::"). Robust to any future change in upstream wrapping — only the marker itself needs to stay stable, and that's now a single named symbol the compiler tracks.dirs::data_dir().join("getpostcraft")next toapp.db, NOT in the log dir which Tauri puts under the bundle identifier (app.getpostcraft) on Windows.Tests
+1 regression guard
db_ahead_marker_is_findable_even_when_wrappedexercises 4 distinct wrappings:"Failed to init SQLite: {marker}payload"(current production wrap)"Some new wrapping: {marker}payload"(any future refactor)"{marker}payload"(no wrap at all)"Layer A → Layer B: {marker}payload"(multi-layer wrap)Asserts the payload is extracted cleanly in every case. The 3 existing tests (
db_ahead_check_passes_on_fresh_install,db_ahead_check_passes_when_db_matches_binary,db_ahead_check_blocks_when_db_has_future_migration) continue to validate the functional pre-flight check.Rust 205/205 (was 204/204), clippy + fmt clean.
After merge
Tag v0.3.10 → workflow Release builds the 3-OS matrix → users on v0.3.9 auto-update.
🤖 Generated with Claude Code
Summary by Sourcery
Centraliser le marqueur d’erreur « DB-ahead-of-binary » et rendre sa détection robuste face aux futurs changements dans l’empaquetage (wrapping) des erreurs.
Corrections de bugs :
Améliorations :
DB_AHEAD_MARKER, utilisée à la fois par la couche base de données et par la logique de démarrage de l’application pour identifier les erreurs « DB-ahead-of-binary ».STARTUP_BLOCKEDpar rapport à la base de données de l’application.Tests :
DB_AHEAD_MARKERpeut être localisé et que sa charge utile peut être correctement extraite sous plusieurs schémas d’empaquetage d’erreurs.Original summary in English
Summary by Sourcery
Centralize the DB-ahead-of-binary error marker and make its detection robust to future changes in error wrapping.
Bug Fixes:
Enhancements:
Tests: