Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the
void
operator20 }
21}
22
23main();
Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the
void
operator299 return;
300 }
301
302 sendToNuke(setupCodeSnippet(knobFile));303 }
304
305 /**
Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the
void
operator246 ? syncKnobChangedSnippet(knobFile)
247 : syncKnobCodeSnippet(knobFile);
248
249 sendToNuke(codeSnippet);250 }
251
252 /**
Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the
void
operator226 vscode.window.showErrorMessage(`Failed to rename ${file} to ${newName}: ${error}`);
227 }
228
229 sleep(1000);230 }
231
232 this.refresh();
Description
Usage of Promise-like
values in statements without handling their errors appropriately is dangerous.
Unhandled promises can cause several issues, such as improperly sequenced operations, ignored Promise rejections and more.
Valid ways of handling a Promise-valued statement include awaiting
, returning
, and either calling .then()
with two arguments or .catch()
with one argument.
If you'd like to ignore unhandled promises at their call site, consider using the void
operator:
void returnsPromise();
Bad Practice
const promise = new Promise((resolve, reject) => resolve('value'));
promise;
async function returnsPromise() {
return 'value';
}
returnsPromise().then(() => {});
Promise.reject('value').catch();
Promise.reject('value').finally();
Recommended
const promise = new Promise((resolve, reject) => resolve('value'));
await promise;
async function returnsPromise() {
return 'value';
}
returnsPromise().then(
() => {},
() => {},
);
Promise.reject('value').catch(() => {});
Promise.reject('value').finally(() => {});