-
-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error messages used by esm-resolver (#1373)
* Improve error messages used by esm-resolver * fix eof
- Loading branch information
1 parent
6266ae2
commit 5643ad6
Showing
1 changed file
with
21 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
exports.codes = { | ||
ERR_INPUT_TYPE_NOT_ALLOWED: createErrorCtor('ERR_INPUT_TYPE_NOT_ALLOWED'), | ||
ERR_INVALID_ARG_VALUE: createErrorCtor('ERR_INVALID_ARG_VALUE'), | ||
ERR_INVALID_MODULE_SPECIFIER: createErrorCtor('ERR_INVALID_MODULE_SPECIFIER'), | ||
ERR_INVALID_PACKAGE_CONFIG: createErrorCtor('ERR_INVALID_PACKAGE_CONFIG'), | ||
ERR_INVALID_PACKAGE_TARGET: createErrorCtor('ERR_INVALID_PACKAGE_TARGET'), | ||
ERR_MANIFEST_DEPENDENCY_MISSING: createErrorCtor('ERR_MANIFEST_DEPENDENCY_MISSING'), | ||
ERR_MODULE_NOT_FOUND: createErrorCtor('ERR_MODULE_NOT_FOUND'), | ||
ERR_PACKAGE_IMPORT_NOT_DEFINED: createErrorCtor('ERR_PACKAGE_IMPORT_NOT_DEFINED'), | ||
ERR_PACKAGE_PATH_NOT_EXPORTED: createErrorCtor('ERR_PACKAGE_PATH_NOT_EXPORTED'), | ||
ERR_UNSUPPORTED_DIR_IMPORT: createErrorCtor('ERR_UNSUPPORTED_DIR_IMPORT'), | ||
ERR_UNSUPPORTED_ESM_URL_SCHEME: createErrorCtor('ERR_UNSUPPORTED_ESM_URL_SCHEME'), | ||
ERR_INPUT_TYPE_NOT_ALLOWED: createErrorCtor(joinArgs('ERR_INPUT_TYPE_NOT_ALLOWED')), | ||
ERR_INVALID_ARG_VALUE: createErrorCtor(joinArgs('ERR_INVALID_ARG_VALUE')), | ||
ERR_INVALID_MODULE_SPECIFIER: createErrorCtor(joinArgs('ERR_INVALID_MODULE_SPECIFIER')), | ||
ERR_INVALID_PACKAGE_CONFIG: createErrorCtor(joinArgs('ERR_INVALID_PACKAGE_CONFIG')), | ||
ERR_INVALID_PACKAGE_TARGET: createErrorCtor(joinArgs('ERR_INVALID_PACKAGE_TARGET')), | ||
ERR_MANIFEST_DEPENDENCY_MISSING: createErrorCtor(joinArgs('ERR_MANIFEST_DEPENDENCY_MISSING')), | ||
ERR_MODULE_NOT_FOUND: createErrorCtor((path, base, type = 'package') => { | ||
return `Cannot find ${type} '${path}' imported from ${base}` | ||
}), | ||
ERR_PACKAGE_IMPORT_NOT_DEFINED: createErrorCtor(joinArgs('ERR_PACKAGE_IMPORT_NOT_DEFINED')), | ||
ERR_PACKAGE_PATH_NOT_EXPORTED: createErrorCtor(joinArgs('ERR_PACKAGE_PATH_NOT_EXPORTED')), | ||
ERR_UNSUPPORTED_DIR_IMPORT: createErrorCtor(joinArgs('ERR_UNSUPPORTED_DIR_IMPORT')), | ||
ERR_UNSUPPORTED_ESM_URL_SCHEME: createErrorCtor(joinArgs('ERR_UNSUPPORTED_ESM_URL_SCHEME')), | ||
} | ||
|
||
function createErrorCtor(name) { | ||
function joinArgs(name) { | ||
return (...args) => { | ||
return [name, ...args].join(' ') | ||
} | ||
} | ||
|
||
function createErrorCtor(errorMessageCreator) { | ||
return class CustomError extends Error { | ||
constructor(...args) { | ||
super([name, ...args].join(' ')) | ||
super(errorMessageCreator(...args)) | ||
} | ||
} | ||
} |