Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
normalize-exception
Advanced tools
Normalize exceptions/errors.
In JavaScript, one can throw
any value including strings, objects (like
{ message: "..." }
) or even undefined
. This normalizes any exception
to an Error
instance.
It also fixes any missing or invalid error properties:
name
, message
, stack
, cause
, errors
.
import normalizeException from 'normalize-exception'
try {
throw null
} catch (error) {
const normalizedError = normalizeException(error)
console.log(normalizedError) // Error: null
// Without `normalizeException()`, this would throw
console.log(normalizedError.name)
}
console.log(normalizeException('message')) // Error: message
console.log(normalizeException({ name: 'TypeError', message: 'message' })) // TypeError: message
const error = new TypeError('message')
console.log(error.stack) // TypeError: message
// `error.stack` is cached, so it does not update
error.message += ' otherMessage'
console.log(error.stack) // TypeError: message
const normalizedError = normalizeException(error)
console.log(normalizedError.stack) // TypeError: message otherMessage
const error = new Error('message', { cause: 'innerError' })
console.log(error.cause instanceof Error) // false
const normalizedError = normalizeException(error)
console.log(normalizedError.cause instanceof Error) // true
console.log(normalizedError.cause) // Error: innerError
npm install normalize-exception
This package is an ES module and must be loaded using
an import
or import()
statement,
not require()
.
error
any
Return value: Error
normalizeException()
never throws.
If error
is an Error
instance, it is returned. Any missing or invalid error
property is directly modified.
If it is not an Error
instance, a new one is created and returned.
For any question, don't hesitate to submit an issue on GitHub.
Everyone is welcome regardless of personal background. We enforce a Code of conduct in order to promote a positive and inclusive environment.
This project was made with ❤️. The simplest way to give back is by starring and sharing it online.
If the documentation is unclear or has a typo, please click on the page's Edit
button (pencil icon) and suggest a correction.
If you would like to help us fix a bug or add a new feature, please check our guidelines. Pull requests are welcome!
FAQs
Normalize exceptions/errors
We found that normalize-exception 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
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.