🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

set-error-message

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

set-error-message - npm Package Compare versions

Comparing version

to
2.0.0

build/src/main.d.ts

13

build/src/args.js
export const normalizeArgs=function(
export const normalizeArgs=(
error,
newMessage,
currentMessage=error.message)
currentMessage=error.message)=>
{
if(typeof newMessage!=="string"){
throw new TypeError(`newMessage must be a string: ${newMessage}`);
throw new TypeError(`newMessage must be a string: ${newMessage}`)
}
if(typeof currentMessage!=="string"){
throw new TypeError(`currentMessage must be a string: ${currentMessage}`);
throw new TypeError(`currentMessage must be a string: ${currentMessage}`)
}
return currentMessage;
};
//# sourceMappingURL=args.js.map
return currentMessage
};

@@ -7,3 +7,3 @@ import normalizeException from"normalize-exception";

export default function setErrorMessage(error,newMessage,currentMessage){
const setErrorMessage=(error,newMessage,currentMessage)=>{
const errorA=normalizeException(error);

@@ -13,20 +13,22 @@ const currentMessageA=normalizeArgs(errorA,newMessage,currentMessage);

updateStack(errorA,newMessage,currentMessageA);
return errorA;
}
return errorA
};
export default setErrorMessage;
const updateStack=function(error,newMessage,currentMessage){
const updateStack=(error,newMessage,currentMessage)=>{
if(newMessage===currentMessage||!stackIncludesMessage()){
return;
return
}
const stack=getStack(error,newMessage,currentMessage);
setNonEnumProp(error,"stack",stack);
setNonEnumProp(error,"stack",stack)
};
const stackIncludesMessage=function(){
const stackIncludesMessage=()=>{
const{stack}=new Error(EXAMPLE_MESSAGE);
return typeof stack==="string"&&stack.includes(EXAMPLE_MESSAGE);
return typeof stack==="string"&&stack.includes(EXAMPLE_MESSAGE)
};

@@ -36,3 +38,3 @@

const setNonEnumProp=function(error,propName,value){
const setNonEnumProp=(error,propName,value)=>{

@@ -43,5 +45,4 @@ Object.defineProperty(error,propName,{

writable:true,
configurable:true});
};
//# sourceMappingURL=main.js.map
configurable:true
})
};

@@ -8,14 +8,13 @@

export const getStack=function({name,stack},newMessage,currentMessage){
return currentMessage!==""&&stack.includes(currentMessage)?
export const getStack=({name,stack},newMessage,currentMessage)=>
currentMessage!==""&&stack.includes(currentMessage)?
replaceMessage({name,stack,newMessage,currentMessage}):
insertMessage(name,stack,newMessage);
};
const replaceMessage=function({name,stack,newMessage,currentMessage}){
const replaceMessage=({name,stack,newMessage,currentMessage})=>{
const replacers=getReplacers(name,newMessage,currentMessage);
const[fromA,to]=replacers.find(([from])=>stack.includes(from));
return stack.replace(fromA,to);
return stack.replace(fromA,to)
};

@@ -25,4 +24,3 @@

const getReplacers=function(name,newMessage,currentMessage){
return[
const getReplacers=(name,newMessage,currentMessage)=>[
[`${name}: ${currentMessage}`,`${name}: ${newMessage}`],

@@ -34,5 +32,4 @@ [`: ${currentMessage}`,`: ${newMessage}`],

};
const insertMessage=function(name,stack,newMessage){
const insertMessage=(name,stack,newMessage)=>{
const nameAndColon=`${name}: `;

@@ -42,3 +39,3 @@ const newMessageA=newMessage.trimEnd();

if(stack===name||stack.startsWith(`${name}\n`)){
return stack.replace(name,`${nameAndColon}${newMessageA}`);
return stack.replace(name,`${nameAndColon}${newMessageA}`)
}

@@ -48,4 +45,3 @@

stack.replace(nameAndColon,`${nameAndColon}${newMessageA}\n`):
`${nameAndColon}${newMessageA}\n${stack}`;
};
//# sourceMappingURL=stack.js.map
`${nameAndColon}${newMessageA}\n${stack}`
};
{
"name": "set-error-message",
"version": "1.6.0",
"version": "2.0.0",
"type": "module",
"exports": {
"types": "./build/types/main.d.ts",
"types": "./build/src/main.d.ts",
"default": "./build/src/main.js"
},
"main": "./build/src/main.js",
"types": "./build/types/main.d.ts",
"types": "./build/src/main.d.ts",
"files": [
"build/src/**/*.{js,json}",
"build/types/**/*.d.ts"
"build/src/**/*.{js,json,d.ts}",
"!build/src/**/*.test.js",
"!build/src/{helpers,fixtures}"
],

@@ -50,4 +51,3 @@ "sideEffects": false,

"directories": {
"lib": "src",
"test": "test"
"lib": "src"
},

@@ -58,8 +58,8 @@ "dependencies": {

"devDependencies": {
"@ehmicky/dev-tasks": "^1.0.102",
"test-each": "^5.6.0"
"@ehmicky/dev-tasks": "^2.0.80",
"test-each": "^6.0.0"
},
"engines": {
"node": ">=14.18.0"
"node": ">=16.17.0"
}
}
[![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js&colorA=404040&logoColor=66cc33)](https://www.npmjs.com/package/set-error-message)
[![Browsers](https://img.shields.io/badge/-Browsers-808080?logo=firefox&colorA=404040)](https://unpkg.com/set-error-message?module)
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/types/main.d.ts)
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/src/main.d.ts)
[![Codecov](https://img.shields.io/badge/-Tested%20100%25-808080?logo=codecov&colorA=404040)](https://codecov.io/gh/ehmicky/set-error-message)

@@ -55,7 +55,10 @@ [![Minified size](https://img.shields.io/bundlephobia/minzip/set-error-message?label&colorA=404040&colorB=808080&logo=webpack)](https://bundlephobia.com/package/set-error-message)

This package works in both Node.js >=14.18.0 and
[browsers](https://raw.githubusercontent.com/ehmicky/dev-tasks/main/src/tasks/build/browserslist).
It is an ES module and must be loaded using
This package works in both Node.js >=16.17.0 and
[browsers](https://raw.githubusercontent.com/ehmicky/dev-tasks/main/src/browserslist).
This is an ES module. It must be loaded using
[an `import` or `import()` statement](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c),
not `require()`.
not `require()`. If TypeScript is used, it must be configured to
[output ES modules](https://www.typescriptlang.org/docs/handbook/esm-node.html),
not CommonJS.

@@ -76,4 +79,4 @@ # API

- [`modern-errors`](https://github.com/ehmicky/modern-errors): Handle errors
like it's 2022 🔮
- [`modern-errors`](https://github.com/ehmicky/modern-errors): Handle errors in
a simple, stable, consistent way
- [`error-custom-class`](https://github.com/ehmicky/error-custom-class): Create

@@ -93,2 +96,4 @@ one error class

update an error's class
- [`wrap-error-message`](https://github.com/ehmicky/wrap-error-message):
Properly wrap an error's message
- [`set-error-props`](https://github.com/ehmicky/set-error-props): Properly

@@ -104,2 +109,6 @@ update an error's properties

some ❤ to Node.js process errors
- [`error-http-response`](https://github.com/ehmicky/error-http-response):
Create HTTP error responses
- [`winston-error-format`](https://github.com/ehmicky/winston-error-format): Log
errors with Winston

@@ -106,0 +115,0 @@ # Support