
Security News
npm v12 Ships With Install Scripts Off by Default, Begins Deprecating 2FA-Bypass Tokens
npm v12 is generally available, turning install scripts off by default and beginning the deprecation of 2FA-bypass publishing tokens.
safe-errors
Advanced tools
In my opinion its simpler to handle errors just like I handle everything else. Normally, errors are handled on a separate codepath. This module helps normalize the codepath for the return values (including errors) from asynchronous functions.
In my opinion its simpler to handle errors just like I handle everything else. Normally, errors are handled on a separate codepath. This module helps normalize the codepath for the return values (including errors) from asynchronous functions.
npm i --save safe-errors
let user
try {
user = await getUser('http://www.example.com/api/v1/users/123')
} catch (e) {
log(e)
// handle error in some way
}
user.name = 'New Name'
let postResponse
try {
postResponse = await saveUser('http://www.example.com/api/v1/users/123')
} catch (e) {
log(e)
// handle error in some way
}
const { safep } = require('safe-errors')
let getResult = await safep(getUser)('http://www.example.com/api/v1/users/123')
if (getResult.success === false) {
log(getResult.error)
// handle error in some way
}
let user = getResult.payload
user.name = 'New Name'
let saveResult = await safep(saveUser)('http://www.example.com/api/v1/users/123', user)
if (saveResult.success === false) {
log(saveResult.error)
// handle error in some way
}
const { pipeP, merge } = require('ramda')
const { safep } = require('safe-errors')
const getUserP = () => safep(getUser)('http://www.example.com/api/v1/users/123')
const updateUser = (user) => {
return merge(user, {
name: 'New name'
})
}
const saveUserP = (user) => safep(saveUser)('http://www.example.com/api/v1/users/123', user)
const handleError = (result) => {
if (result.success === false) {
log(result.success === false)
// maybe return a default
return {}
}
return result.payload
}
// Easier to pipe when errors are predictable
let updateAndSaveUser = pipeP(getUserP, handleError, updateUser, saveUser, handleError)
let updateResult = await updateAndSaveUser()
if (updateResult.success === false) {
log(updateResult.error)
}
const { readFile } = require('fs')
fs.readFile('file.txt', (err, data) => {
if (err) {
log(err)
// handle error in some way
}
console.log(data)
})
const { readFile } = require('fs')
const { safecb } = require('safe-errors')
let result = await safecb(readFile)('file.txt')
if (result.error) {
log(result.error)
// handle error in some way
}
console.log(result.payload) // contents of file
console.log(result.args) // array of arguments passed into done callback
FAQs
In my opinion its simpler to handle errors just like I handle everything else. Normally, errors are handled on a separate codepath. This module helps normalize the codepath for the return values (including errors) from asynchronous functions.
The npm package safe-errors receives a total of 10 weekly downloads. As such, safe-errors popularity was classified as not popular.
We found that safe-errors 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
npm v12 is generally available, turning install scripts off by default and beginning the deprecation of 2FA-bypass publishing tokens.

Research
/Security News
Socket tracks the activity as Operation “Muck and Load”: a threat actor uses commit-farming workflows, public dead drops, and protected archives to stage Windows RAT and infostealer malware.

Security News
pnpm 11.10 hardens registry auth to block token redirection, tightens pack-app and deploy, and makes the Rust port (v12) installable.