SKY-Q405 · Quality, structure and performance
Async Promise executor
new Promise(async (resolve, reject) => { ... }). The function passed to the Promise constructor (the executor) is async, so it returns a promise of its own that the constructor ignores.
- Languages
- TypeScript, JavaScript
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- defect
Why it matters
When anything inside the executor throws, such as a missing file or bad JSON, the error rejects the ignored inner promise instead of the one the caller holds. The caller's promise never settles: await loadConfig() hangs forever, and the error shows up only as an unhandled rejection.
What Skylos flags
import { readFile } from "node:fs/promises"; export function loadConfig(path: string): Promise<Record<string, unknown>> { return new Promise(async (resolve) => { const text = await readFile(path, "utf8"); resolve(JSON.parse(text)); });}What Skylos leaves alone
import { readFile } from "node:fs"; export function loadConfig(path: string): Promise<Record<string, unknown>> { return new Promise((resolve, reject) => { readFile(path, "utf8", (err, text) => { if (err) { reject(err); return; } resolve(JSON.parse(text)); }); });}Why Skylos leaves it alone
The executor is an ordinary function that wraps a callback API, which is what the Promise constructor is for. Errors reach reject.
More languages
JavaScript
Flagged
export function waitForReady(db) { return new Promise(async (resolve) => { await db.connect(); resolve(db); });}Not flagged
export function waitForReady(db) { return new Promise((resolve, reject) => { db.connect().then(() => resolve(db), reject); });}Why Skylos leaves it alone
The executor is not async; the connection's failure is passed to reject, so the caller sees it.
How Skylos decides
- Runs with
--qualityon.ts,.tsx,.js,.jsx,.mts,.cts,.mjsand.cjsfiles. Generated and minified files, and files that do not parse, are skipped. - Finds
new Promise(...)whose first argument is anasyncarrow function or function expression (type assertions and parentheses around it are looked through). Promisemust be the built-in: Skylos skips the call when the file declares or reassigns its ownPromise, anywhere a write could reach that call.- Reports HIGH on the line of the
newexpression. The executor's body is not inspected.
How to fix it
Drop the constructor and write an async function. Errors then reject the returned promise as expected.
import { readFile } from "node:fs/promises"; Removed: export function loadConfig(path: string): Promise<Record<string, unknown>> {Removed: return new Promise(async (resolve) => {Removed: const text = await readFile(path, "utf8");Removed: resolve(JSON.parse(text));Removed: });Added: export async function loadConfig(path: string): Promise<Record<string, unknown>> {Added: const text = await readFile(path, "utf8");Added: return JSON.parse(text);}When it can be wrong
- An async executor that wraps all of its body in
try/catchand callsrejectis still reported, although it does settle. The plainasyncfunction is simpler there too.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put the marker on the line of
new Promise.TypeScript return new Promise(async (resolve, reject) => { // skylos: ignore[SKY-Q405][tool.skylos] ignore = ["SKY-Q405"]turns the rule off for the project.