Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@smallwins/err
Advanced tools
@smallwins/err
Slightly better custom Error
s
extends
with clean name
and stack
propertiestoObject
returns a plain object representationcode
propertynpm i @smallwins/err --save
err.Err
a base Error
type intended for extendingerr.InternalError
has a code
property of 500
err.DatabaseError
has a code
property of 500
err.NotFoundError
has a code
property of 404
err.NotAuthorizedError
has a code
property of 403
Example usage:
var err = require('@smallwins/err')
let notFound = new err.NotFoundError('missing record')
console.log(err.code) // logs 404
Subclass to add additional properties such as code
:
var err = require('@smallwins/err')
class CoffeeError extends err.Err {
constructor(params) {
super(params)
this.code = 500
}
}
let e = new CoffeeError('lactose intolerant')
console.log(e.code) // logs 500
Get a clean representation:
console.log(e.toObject())
// logs {name, code, message, stack}
Extend by require
ing error directly:
var Err = require('@smallwins/err/err')
class TerribleError extends Err {
constructor(msg) {
super(msg)
this.extra = 'extra info'
}
}
var e = new TerribleError('wut')
console.log(e.extra)
Work oldschool without new
:
var err = require('@smallwins/err/oldschool')
console.log(err.Err('basic') instanceof Error)
// logs true
console.log(err.NotFound('not found err').toString())
// logs NotFound: not found err
@smallwins/err/oldschool
APIFactory functions which return real Error
instances:
err.Err
returns an Err
instanceerr.Internal
returns an InternalError
instanceerr.Database
returns a DatabaseError
instanceerr.NotFound
returns a NotFoundError
instanceerr.NotAuthorized
returns a NotAuthorizedError
instanceRuntime type checking fully supported. Check the tests.
FAQs
Slightly better custom Error
We found that @smallwins/err demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.