
Security News
RubyGems Adds Cooldown Feature to Bundler for Newly Published Gems
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.
error-alias
Advanced tools
Install with NPM.
$ npm i error-alias
The Error Alias package allows library designers to provide downstream developers with cleaner stack traces. It adda a new option, {depth} to the second parameter of Error types. Tbhis allows you to remove internal layers from the top of your traces.
This allows your traces to point directly to the line your external function was called on, rather than to a point deep within your library.
import ErrorAlias from 'error-alias';
function canThrow(x) {
if (typeof x !== 'string') {
throw new ErrorAlias(`canThrow param.0 must be a string, got ${typeof x}`);
}
}
canThrow(321);
AliasedError: canThrow param.0 must be a string, got number
at file:///home/sean/projects/errorAlias/scratch.mjs:9:1
at ModuleJob.run (node:internal/modules/esm/module_job:195:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:336:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:106:12)
You can also provide the depth option if you're throwing the error from deeper in the code:
import ErrorAlias from 'error-alias';
function internalFunc(x) {
if (typeof x !== 'string') {
throw new ErrorAlias(`canThrow param.0 must be a string, got ${typeof x}`, {depth: 2});
}
}
function canThrow(x) {
internalFunc(x);
}
canThrow(321);
If you, or a downstream developer need to see more detail, they can disable the stacktrace alteration by setting globalThis.preventErrorAliasing to true.
globalThis.preventErrorAliasing = true;
The Error Alias package provides aliases for standard Error objects and seven built-in subtypes:
Aliases Error():
import { ErrorAlias } from 'error-alias';
// throw new Error();
throw new ErrorAlias();
Aliases AggregateError():
import { AggregateErrorAlias } from 'error-alias';
// throw new AggregateError();
throw new AggregateErrorAlias();
Aliases EvalError():
import { EvalErrorAlias } from 'error-alias';
// throw new EvalError();
throw new EvalErrorAlias();
Aliases RangeError():
import { RangeErrorAlias } from 'error-alias';
// throw new RangeError();
throw new RangeErrorAlias();
Aliases SyntaxError():
import { SyntaxErrorAlias } from 'error-alias';
// throw new SyntaxError();
throw new SyntaxErrorAlias();
Aliases TypeError():
import { TypeErrorAlias } from 'error-alias';
// throw new TypeError();
throw new TypeErrorAlias();
Aliases URIError():
import { URIErrorAlias } from 'error-alias';
// throw new URIError();
throw new URIErrorAlias();
You can import the function aliasErrorType and pass it a class to create an Alias type.
import { aliasErrorType } from 'error-alias';
class MyErrorType extends Error { /* Custom implementation here */ };
const MyErrorAlias = aliasErrorType(MyErrorType);
// throw new MyError();
throw new MyErrorAlias();
© 2024 Sean Morris
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
Clean up your stack traces.
We found that error-alias demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
RubyGems and Bundler 4.0.13 introduced an opt-in cooldown feature that delays newly published gems during dependency resolution.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.