Skip to content

fix: initIndex exception handling and error-message typos#364

Closed
andreinknv wants to merge 2 commits into
yoshoku:mainfrom
andreinknv:fix/initindex-exception-type
Closed

fix: initIndex exception handling and error-message typos#364
andreinknv wants to merge 2 commits into
yoshoku:mainfrom
andreinknv:fix/initindex-exception-type

Conversation

@andreinknv

Copy link
Copy Markdown

Problem

Two issues in initIndex:

  1. Process abort on OOM. initIndex (both classes) catches only
    std::bad_alloc around the index constructor, but hnswlib signals
    allocation failure with std::runtime_error ("Not enough memory").
    An out-of-memory initIndex therefore lets a C++ exception escape the
    N-API method and abort the process.
  2. Misspelled identifiers in error messages. The named-argument
    validator reports allowRepalceDeleted (the real argument is
    allowReplaceDeleted), and the positional validator says "sencond"
    instead of "second".

Fix

Widen the initIndex handlers to std::exception so an hnswlib
allocation failure surfaces as a thrown JavaScript Error, and correct
the two misspellings. Neither error string is asserted by the test
suite.

Verification

npm test — 100/100 passing; native addon builds clean.

🤖 Generated with Claude Code

andreinknv and others added 2 commits May 17, 2026 21:14
initIndex (both classes) caught only std::bad_alloc around the index
constructor, but hnswlib signals allocation failure with
std::runtime_error ("Not enough memory"). An out-of-memory initIndex
therefore let a C++ exception escape the N-API method and abort the
process. Widen the handler to std::exception so it surfaces as a
thrown JavaScript Error.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two argument-validation error strings were misspelled: the named
argument is reported as `allowRepalceDeleted` (the real name is
`allowReplaceDeleted`) and the positional check says "sencond"
instead of "second". Neither string is asserted by the test suite.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@andreinknv andreinknv closed this by deleting the head repository May 28, 2026
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