Skip to content

sqlite: exhausted iterators incorrectly receive return() #66518

Description

@trivikr

Version

main

Platform

All

Subsystem

sqlite

What steps will reproduce the bug?

import { Database } from 'node:sqlite';
const db = new Database(':memory:');

db.createModule('empty', {
  columns: [{ name: 'value', type: 'INTEGER' }],
  rows() {
    return {
      [Symbol.iterator]() { return this; },
      next() { return { value: [], done: true }; }, // empty: exhausted immediately
      return() { throw new Error('cleanup boom'); },
    };
  },
});

console.log(db.prepare('SELECT value FROM empty').all());

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

Once next() reports done: true, the iterator is finished and return() must be skipped, matching for...of semantics where return() is only called on abrupt termination; the query should return [].

What do you see instead?

throws Error: cleanup boom from the custom iterator's return() even though the iterable is empty and was exhausted normally.

Additional information

No response

Activity

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

Metadata

Metadata

Assignees

Labels

sqliteIssues and PRs related to the SQLite subsystem.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions