
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
error-shortener
Advanced tools
This module is written on
typescript, and contains the.d.tsfile.
If you write ontypescript: just use it in your project and definitions will be automatically uploaded.
npm i -S error-shortener
Once I tired of reading the error-stack on several screens.
So I wrote the module to clean the stack: it removes the elements that are out of your repository (based on process.cwd()), and the elements from the node_modules folder.
Note: before cleaning the error will be checked to the expected format. If it is different, the stack cleaning will not be fulfilled.
const API = require('error-shortner')
// performs reduction of the stack, normalized error-stack indents, replacement message and name to the actual
// alias to API.fmtShortError
API.fmtError(arg: API.IErrorLike): string
// normalized error-stack indents, replacement message and name to the actual
API.fmtLongErrorf(arg: API.IErrorLike): string
// compliance argument with the interface
API.isIErrorLike(arg: any): arg is API.IErrorLike
when formatting:
SomeError to the new NewError name.process.cwd() part of the file paths.import { fmtError } from 'error-shortener'
const likeBluebirdError = {
name: `NewError`,
message: `Text added from some place!\
\n\t SomeMeta: foo=bar; other=abc\
\n\t OriginalError: something happened!`,
stack: `SomeError: something happened!
at error (/home/nskazki/node.js/example/index.js:12:28)
From previous event:
at error (/home/nskazki/node.js/example/index.js:12:27)
at /home/nskazki/node.js/example/index.js:19:15
at Timer.listOnTimeout (timers.js:92:15)
From previous event:
at Object.<anonymous> (/home/nskazki/node.js/example/index.js:19:4)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:141:18)
at node.js:933:3`
}
console.error(fmtError(likeBluebirdError))
/*
NewError: Text added from some place!
SomeMeta: foo=bar; other=abc
OriginalError: something happened!
at error (index.js:12:28)
From previous event:
at error (index.js:12:27)
at index.js:19:15`
From previous event:
at Object.<anonymous> (index.js:19:4)
*/
when formatting:
Error nameimport { fmtError } from 'error-shortener'
const likePhantomError = {
message: 'JSON.stringify cannot serialize cyclic structures.',
stack: `stringify@[native code]
wrapper
global code
evaluateJavaScript@[native code]
evaluate
file:///home/nskazki/node.js/work-projects/dmca-ip-search-service/phantom-farm/worker/node_modules/node-phantom-simple/bridge.js:121:61`
}
console.error(fmtError(likePhantomError))
/*
Error: JSON.stringify cannot serialize cyclic structures.
Stack:
stringify@[native code]
wrapper
global code
evaluateJavaScript@[native code]
evaluate
file:///home/nskazki/node.js/work-projects/dmca-ip-search-service/phantom-farm/worker/node_modules/node-phantom-simple/bridge.js:121:61`
*/
FAQs
generates a string containing a message and trimmed stack from error
We found that error-shortener 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.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.