Skip to content

Commit 5e52f42

Browse files
committed
fix WebpackError handling in Cache
1 parent 856235d commit 5e52f42

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

lib/Cache.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"use strict";
77

88
const { AsyncParallelHook, AsyncSeriesBailHook, SyncHook } = require("tapable");
9-
const { makeWebpackError } = require("./HookWebpackError");
9+
const {
10+
makeWebpackError,
11+
makeWebpackErrorCallback
12+
} = require("./HookWebpackError");
1013

1114
/** @typedef {import("./WebpackError")} WebpackError */
1215

@@ -93,7 +96,12 @@ class Cache {
9396
* @returns {void}
9497
*/
9598
store(identifier, etag, data, callback) {
96-
this.hooks.store.callAsync(identifier, etag, data, callback);
99+
this.hooks.store.callAsync(
100+
identifier,
101+
etag,
102+
data,
103+
makeWebpackErrorCallback(callback, "Cache.hooks.store")
104+
);
97105
}
98106

99107
/**
@@ -121,15 +129,19 @@ class Cache {
121129
* @returns {void}
122130
*/
123131
endIdle(callback) {
124-
this.hooks.endIdle.callAsync(callback);
132+
this.hooks.endIdle.callAsync(
133+
makeWebpackErrorCallback(callback, "Cache.hooks.endIdle")
134+
);
125135
}
126136

127137
/**
128138
* @param {Callback<void>} callback signals when the call finishes
129139
* @returns {void}
130140
*/
131141
shutdown(callback) {
132-
this.hooks.shutdown.callAsync(callback);
142+
this.hooks.shutdown.callAsync(
143+
makeWebpackErrorCallback(callback, "Cache.hooks.shutdown")
144+
);
133145
}
134146
}
135147

lib/HookWebpackError.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ const WebpackError = require("./WebpackError");
99

1010
/** @typedef {import("./Module")} Module */
1111

12+
/**
13+
* @template T
14+
* @callback Callback
15+
* @param {Error=} err
16+
* @param {T=} stats
17+
* @returns {void}
18+
*/
19+
1220
class HookWebpackError extends WebpackError {
1321
/**
1422
* Creates an instance of HookWebpackError.
@@ -46,7 +54,7 @@ module.exports.makeWebpackError = makeWebpackError;
4654
* @template T
4755
* @param {function(WebpackError=, T=): void} callback webpack error callback
4856
* @param {string} hook name of hook
49-
* @returns {function(Error=, T=): void} generic callback
57+
* @returns {Callback<T>} generic callback
5058
*/
5159
const makeWebpackErrorCallback = (callback, hook) => {
5260
return (err, result) => {

0 commit comments

Comments
 (0)