Skip to content

refactor: dedupe busy/locked error detection into isBusyOrLockedError#1860

Closed
carlos-alm wants to merge 1 commit into
fix/issue-1748-connection-halstead-effortfrom
fix/issue-1749-connection-busytimeout-regex-dedupe
Closed

refactor: dedupe busy/locked error detection into isBusyOrLockedError#1860
carlos-alm wants to merge 1 commit into
fix/issue-1748-connection-halstead-effortfrom
fix/issue-1749-connection-busytimeout-regex-dedupe

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

Closes #1749

Test plan

  • npm test — full suite green (3490 passed, 0 failed)
  • npm run lint — clean
  • codegraph diff-impact --staged -T — 3 functions changed, 27 callers affected, consistent with a non-behavioral helper extraction

For #1763's benefit: confirmed crates/codegraph-core/src/db/connection.rs has the identical hardcoded busy_timeout = 5000 literal duplicated at two call sites (open_read_write, open_readonly). No Rust equivalent of the busy/locked regex exists — rusqlite surfaces SQLITE_BUSY/SQLITE_LOCKED as typed error variants, not string matching.

Stacked on #1859 (base branch fix/issue-1748-connection-halstead-effort) — only the connection.ts diff is this issue's change.

Extracts the /\b(busy|locked|SQLITE_BUSY|SQLITE_LOCKED)\b/i regex check
into a single isBusyOrLockedError(msg) helper, replacing the identical
inline check duplicated between openRepo's native path (tryOpenRepoNative)
and openReadonlyWithNative's native path. No change to matching behavior
or the busy_timeout value.

DEFAULTS.db.busyTimeoutMs (this issue's other flagged cleanup) was
already added and wired into openDb/openReadonlyOrFail by an earlier
commit in this stack (8f23020); this commit covers the remaining
regex duplication only.

docs check acknowledged: internal dedup-only refactor, no CLI surface,
language support, or documented architecture/design decision changed.

Fixes #1749

Impact: 3 functions changed, 27 affected
@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extracts the repeated inline regex /\b(busy|locked|SQLITE_BUSY|SQLITE_LOCKED)\b/i from two native-path catch blocks in connection.ts into a single module-private isBusyOrLockedError(msg) helper, preventing the two call sites from drifting. No behavioral change is introduced — the regex, its flags, and the surrounding error-handling logic are all preserved exactly.

  • isBusyOrLockedError is added as a non-exported helper with a JSDoc explaining its purpose and the two consumers; both tryOpenRepoNative and openReadonlyWithNative are updated to call it.
  • The two call sites intentionally differ in their response (re-throw vs. log-and-swallow), which is correct and unchanged — tryOpenRepoNative has no fallback when busy, while openReadonlyWithNative already has an open better-sqlite3 handle.

Confidence Score: 5/5

Safe to merge — the change is a pure extraction refactor with no logic alterations.

The only change is lifting an identical inline regex into a named helper. The regex pattern, word-boundary anchors, and case-insensitive flag are all preserved verbatim. Both call sites convert the thrown error to a string before passing it to the helper, matching the previous inline usage exactly. The intentional behavioral difference between the two call sites (re-throw vs. swallow) is unaffected.

No files require special attention.

Important Files Changed

Filename Overview
src/db/connection.ts Extracts the inline busy/locked regex into a shared isBusyOrLockedError helper — pattern and behavior are identical at both call sites; no logic changed.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[tryOpenRepoNative catch] -->|toErrorMessage| B[isBusyOrLockedError]
    C[openReadonlyWithNative catch] -->|toErrorMessage| B
    B -->|true| D{caller}
    B -->|false| E{caller}
    D -->|tryOpenRepoNative| F[throw DbError — busy]
    D -->|openReadonlyWithNative| G[debug log, skip native DB]
    E -->|tryOpenRepoNative| H[debug log, fall back to better-sqlite3]
    E -->|openReadonlyWithNative| I[debug log, skip native DB]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[tryOpenRepoNative catch] -->|toErrorMessage| B[isBusyOrLockedError]
    C[openReadonlyWithNative catch] -->|toErrorMessage| B
    B -->|true| D{caller}
    B -->|false| E{caller}
    D -->|tryOpenRepoNative| F[throw DbError — busy]
    D -->|openReadonlyWithNative| G[debug log, skip native DB]
    E -->|tryOpenRepoNative| H[debug log, fall back to better-sqlite3]
    E -->|openReadonlyWithNative| I[debug log, skip native DB]
Loading

Reviews (1): Last reviewed commit: "refactor: dedupe busy/locked error detec..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

3 functions changed27 callers affected across 21 files

  • isBusyOrLockedError in src/db/connection.ts:447 (13 transitive callers)
  • tryOpenRepoNative in src/db/connection.ts:467 (17 transitive callers)
  • openReadonlyWithNative in src/db/connection.ts:540 (8 transitive callers)

@carlos-alm carlos-alm deleted the branch fix/issue-1748-connection-halstead-effort July 6, 2026 16:14
@carlos-alm carlos-alm closed this Jul 6, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 6, 2026
@carlos-alm

Copy link
Copy Markdown
Contributor Author

Recreated as #1899 — this PR was inadvertently closed when its stacked base branch was deleted after #1859 merged. Continuing there.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant