Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug that cause UnhandledPromiseRejectionWarning on error #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ The IMAP client has several events you can attach to by setting a listener
### Handling fatal error event

The invocation of `onerror` indicates an irrecoverable error. When `onerror` is fired, the connection is already closed, hence there's no need for further cleanup.
if no `onerror` callback is set, it will throw the error.

## Get your hands dirty

Expand Down
24 changes: 22 additions & 2 deletions dist/client.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/command-parser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/compression.js

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions dist/imap.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/logger.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion res/compression.worker.blob

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export default class Client {
clearTimeout(this._idleTimeout)

// propagate the error upwards
this.onerror && this.onerror(err)
if (!this.onerror) {
throw err
}
this.onerror(err)
}

//
Expand Down
9 changes: 8 additions & 1 deletion src/imap.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ export default class Imap {
* @returns {Promise} Resolves when the socket is closed
*/
close (error) {
if (this._enteredClosingState) {
return Promise.resolve()
}
this._enteredClosingState = true
return new Promise((resolve) => {
var tearDown = () => {
// fulfill pending promises
Expand Down Expand Up @@ -257,7 +261,10 @@ export default class Imap {
var tag = 'W' + (++this._tagCounter)
request.tag = tag

return new Promise((resolve, reject) => {
return new Promise(resolve => {
var reject = error => {
return resolve(this.close(error))
}
var data = {
tag: tag,
request: request,
Expand Down