When calling functions on a closed database, confusing "out of memory" error is reported
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 13.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
I realize that calling methods on a database that's been closed is not a good idea. However, when calling a method like each on the closed database, the error reported is out of memory. The underlying db is nulled out on close (which makes sense). But then, in the handleError method:
Database.prototype.handleError = function(returnCode) {
var errmsg;
if (returnCode === SQLite.OK) {
return null;
} else {
errmsg = sqlite3_errmsg(this.db);
throw new Error(errmsg);
}
};
We're passing null into the sqlite3_errmsg. That in turn causes it to report it as a memory allocation error.
Ideally, the error reported would be something more intuitive. I bring this up because I am now closing databases that we are no longer using in an effort to fix a real memory allocation error. However, in the process of doing so, I accidentally closed a database I shouldn't have and continued to get what looked like memory errors. It wasn't until later that I realized this message was inaccurate.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Database.prototype.handleError in the issue's JavaScript snippet and reproduce calling each on a closed database. Check how the null database reaches sqlite3_errmsg; done means the closed-database case reports an intuitive error instead of "out of memory."
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, sqlite
- Domain
- database
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100