Skip to content
Merged
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
fix(rspack): prevents an unhandled promise rejection when throwing in…
… the async loader
  • Loading branch information
elbywan committed Aug 20, 2025
commit 03f1ef3f3a5ea6af9ab52c1cbb00a88627841f59
38 changes: 24 additions & 14 deletions src/rspack/loaders/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,29 @@ export default async function load(this: LoaderContext, source: string, map: any

const context = createContext(this)
const { handler } = normalizeObjectHook('load', plugin.load)
const res = await handler.call(
Object.assign(
{},
this._compilation && createBuildContext(this._compiler, this._compilation, this),
context,
),
normalizeAbsolutePath(id),
)
try {
const res = await handler.call(
Object.assign(
{},
this._compilation && createBuildContext(this._compiler, this._compilation, this),
context,
),
normalizeAbsolutePath(id),
)

if (res == null)
callback(null, source, map)
else if (typeof res !== 'string')
callback(null, res.code, res.map ?? map)
else
callback(null, res, map)
if (res == null)
callback(null, source, map)
else if (typeof res !== 'string')
callback(null, res.code, res.map ?? map)
else
callback(null, res, map)
}
catch (error) {
if (error instanceof Error) {
callback(error)
}
else {
callback(new Error(String(error)))
}
}
}