UNPKG

2.77 kBJavaScriptView Raw
1'use strict';
2Object.defineProperty(exports, '__esModule', { value: true });
3exports.getErrorMessage = exports.SOURCE_MAP_INFO_URL = exports.AppError = void 0;
4const helpers_1 = require('./helpers');
5class AppError extends Error {
6 constructor(errorContext, error) {
7 super();
8 Object.setPrototypeOf(this, AppError.prototype);
9 const message = getErrorMessage(errorContext);
10 this.message = error ? `${message}: ${error.message}` : message;
11 this.code = errorContext.code;
12 Error.captureStackTrace(this, AppError);
13 }
14}
15exports.AppError = AppError;
16exports.SOURCE_MAP_INFO_URL =
17 'https://github.com/danvk/source-map-explorer/blob/master/README.md#generating-source-maps';
18function getErrorMessage(context) {
19 switch (context.code) {
20 case 'NoBundles':
21 return 'No file(s) provided';
22 case 'NoSourceMap':
23 return `Unable to find a source map.
24See ${exports.SOURCE_MAP_INFO_URL}`;
25 case 'OneSourceSourceMap': {
26 return `Your source map only contains one source (${context.filename}).
27This can happen if you use browserify+uglifyjs, for example, and don't set the --in-source-map flag to uglify.
28See ${exports.SOURCE_MAP_INFO_URL}`;
29 }
30 case 'UnmappedBytes': {
31 const { unmappedBytes, totalBytes } = context;
32 const bytesString = helpers_1.formatPercent(unmappedBytes, totalBytes, 2);
33 return `Unable to map ${unmappedBytes}/${totalBytes} bytes (${bytesString}%)`;
34 }
35 case 'InvalidMappingLine': {
36 const { generatedLine, maxLine } = context;
37 return `Your source map refers to generated line ${generatedLine}, but the source only contains ${maxLine} line(s).
38Check that you are using the correct source map.`;
39 }
40 case 'InvalidMappingColumn': {
41 const { generatedLine, generatedColumn, maxColumn } = context;
42 return `Your source map refers to generated column ${
43 generatedColumn + 1
44 } on line ${generatedLine}, but the source only contains ${maxColumn} column(s) on that line.
45Check that you are using the correct source map.`;
46 }
47 case 'CannotSaveFile':
48 return 'Unable to save HTML to file';
49 case 'CannotCreateTempFile':
50 return 'Unable to create a temporary HTML file';
51 case 'CannotOpenTempFile': {
52 const { error, tempFile } = context;
53 return `Unable to open web browser. ${error.toString().trim()}
54Either run with --html, --json, --tsv, --file, or view HTML for the visualization at:
55${tempFile}`;
56 }
57 case 'CannotOpenCoverageFile': {
58 return 'Unable to open/parse coverage file';
59 }
60 case 'NoCoverageMatches': {
61 return 'No matched bundles found for coverages';
62 }
63 default:
64 return 'Unknown error';
65 }
66}
67exports.getErrorMessage = getErrorMessage;
68//# sourceMappingURL=app-error.js.map