mongo icon indicating copy to clipboard operation
mongo copied to clipboard

Avoid console.error (throw if needed)

Open jtoppine opened this issue 2 years ago • 1 comments

Library outputting to the console is undesireable in most cases.

In cluster.ts, the close function looks like this:

close() {
    for (const conn of this.#connections) {
      try {
        conn.close();
      } catch (error) {
        console.error(`Error closing connection: ${error}`);
      }
    }
  }

The error should be thrown if it's important for users to be able to handle the situation. Or ignored as this looks like something that is safe to ignore.

Most likely this is just from attempting to close an already closed connection, and just a no-op might be correct way to handle it (?).

In any case logging to the console is bad. For example, I'm running the code in a subprocess which only outputs JSON to be consumed elsewhere - random console outputs messes up the parsing in the receiving end.

jtoppine avatar Oct 04 '23 12:10 jtoppine

@jtoppine Thanks for reporting this, could you open a PR to resolve this issue?

erfanium avatar Oct 05 '23 05:10 erfanium