| 
									
										
										
										
											2016-01-04 04:42:56 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 02:27:43 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { cleanUp } = require("./ErrorHelpers"); | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | const WebpackError = require("./WebpackError"); | 
					
						
							| 
									
										
										
										
											2018-10-25 16:47:52 +08:00
										 |  |  | const makeSerializable = require("./util/makeSerializable"); | 
					
						
							| 
									
										
										
										
											2017-03-22 20:00:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-25 05:17:47 +08:00
										 |  |  | class ModuleError extends WebpackError { | 
					
						
							| 
									
										
										
										
											2018-11-07 21:03:25 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Error} err error thrown | 
					
						
							| 
									
										
										
										
											2020-08-03 02:09:36 +08:00
										 |  |  | 	 * @param {{from?: string|null}} info additional info | 
					
						
							| 
									
										
										
										
											2018-11-07 21:03:25 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-10-30 05:18:08 +08:00
										 |  |  | 	constructor(err, { from = null } = {}) { | 
					
						
							| 
									
										
										
										
											2018-06-05 16:23:00 +08:00
										 |  |  | 		let message = "Module Error"; | 
					
						
							| 
									
										
										
										
											2018-10-25 16:47:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 17:56:34 +08:00
										 |  |  | 		if (from) { | 
					
						
							| 
									
										
										
										
											2018-06-05 16:43:10 +08:00
										 |  |  | 			message += ` (from ${from}):\n`; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			message += ": "; | 
					
						
							| 
									
										
										
										
											2018-02-22 01:00:03 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-10-25 16:47:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-02 17:56:34 +08:00
										 |  |  | 		if (err && typeof err === "object" && err.message) { | 
					
						
							| 
									
										
										
										
											2018-06-05 16:43:10 +08:00
										 |  |  | 			message += err.message; | 
					
						
							| 
									
										
										
										
											2018-03-02 17:56:34 +08:00
										 |  |  | 		} else if (err) { | 
					
						
							| 
									
										
										
										
											2018-06-05 16:43:10 +08:00
										 |  |  | 			message += err; | 
					
						
							| 
									
										
										
										
											2018-02-22 20:57:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-10-25 16:47:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-05 16:23:00 +08:00
										 |  |  | 		super(message); | 
					
						
							| 
									
										
										
										
											2018-10-25 16:47:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 02:27:43 +08:00
										 |  |  | 		this.name = "ModuleError"; | 
					
						
							|  |  |  | 		this.error = err; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		this.details = | 
					
						
							|  |  |  | 			err && typeof err === "object" && err.stack | 
					
						
							|  |  |  | 				? cleanUp(err.stack, this.message) | 
					
						
							|  |  |  | 				: undefined; | 
					
						
							| 
									
										
										
										
											2017-01-04 02:27:43 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-10-25 16:47:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	serialize(context) { | 
					
						
							|  |  |  | 		const { write } = context; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		write(this.error); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		super.serialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	deserialize(context) { | 
					
						
							|  |  |  | 		const { read } = context; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.error = read(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		super.deserialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-04 04:42:56 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-25 16:47:52 +08:00
										 |  |  | makeSerializable(ModuleError, "webpack/lib/ModuleError"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 02:27:43 +08:00
										 |  |  | module.exports = ModuleError; |