xmppjs / xmpp.js

XMPP for JavaScript
ISC License
2.18k stars 372 forks source link

client_instance.stop() throws unmeaningful error if start() has not been called #870

Closed mull closed 3 years ago

mull commented 3 years ago

Improvements may be:

  1. Throwing a meaningful error ("Can't stop client that has not been started")
  2. Do nothing and return a resolved promise, since there is nothing to do
const {client, xml} = require('@xmpp/client')
const debug = require('@xmpp/debug')

const xmpp = new client({});

xmpp.stop();
(node:87669) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'once' of null
    at /Users/emil/code/xmppjsbug/node_modules/@xmpp/events/lib/promise.js:26:8
    at new Promise (<anonymous>)
    at promise (/Users/emil/code/xmppjsbug/node_modules/@xmpp/events/lib/promise.js:7:10)
    at Client.close (/Users/emil/code/xmppjsbug/node_modules/@xmpp/connection/index.js:293:7)
    at Client._end (/Users/emil/code/xmppjsbug/node_modules/@xmpp/connection/index.js:195:23)
    at Client.stop (/Users/emil/code/xmppjsbug/node_modules/@xmpp/connection/index.js:281:27)
    at Object.<anonymous> (/Users/emil/code/xmppjsbug/index.js:6:6)
    at Module._compile (internal/modules/cjs/loader.js:1236:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1257:10)
    at Module.load (internal/modules/cjs/loader.js:1085:32)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:87669) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:87669) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.