
Research
/Security News
60 Malicious Ruby Gems Used in Targeted Credential Theft Campaign
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
The nice-try npm package is a utility module that provides a simple way to attempt executing a function that might or might not throw an error without having to use try-catch blocks explicitly. It is designed to be a minimalistic and straightforward tool for safe function execution.
Safe Function Execution
This feature allows you to execute a function and if it throws an error, nice-try will catch it and return undefined instead of letting the error propagate. This is useful when you want to attempt an operation but don't want to handle the error explicitly.
const niceTry = require('nice-try');
const result = niceTry(() => {
// Potentially risky operation
return 'Operation successful';
});
console.log(result); // Outputs: 'Operation successful' or undefined if an error occurred
The try-catch package provides a similar functionality to nice-try by allowing you to wrap synchronous code in a try-catch block without having to write the try-catch explicitly. It differs in that it returns an array with the error (if any) and the result, allowing you to handle both.
Just-try is a minimalistic package that allows you to try a function and catch any thrown errors. It is very similar to nice-try in its simplicity and straightforward approach but does not seem to offer additional features or improvements over nice-try.
A function that tries to execute a function and discards any error that occurs.
npm install nice-try
import niceTry from 'nice-try'
niceTry(() => JSON.parse('true')) // true
niceTry(() => JSON.parse('error')) // undefined
niceTry() // undefined
niceTry(true) // undefined
import niceTry from 'nice-try/promises'
await niceTry(async () => JSON.parse('true')) // true
await niceTry(async () => JSON.parse('error')) // undefined
nice-try
fn
{Function}
The function to execute.{*}
The return value of the function, or undefined
if an error occurred.nice-try/promises
fn
{Function}
An asynchronous function to execute.{Promise<*>}
The result of the function if it resolves successfully, otherwise undefined if an error is thrown.This module is a controversial thing and people like to get mad about it. I decided to give those people a voice. Here's what they're saying.
fundamentally inane
— frou_dh
the worst Javascript library […] in several categories
— kuzux
how is this a thing
— uint8_t
This is blowing my mind
— mr_jim_lahey
a shit-tastic try-catch alias
— Dropping_fruits
I assumed every commit was a joke, but after researching the maintainer a bit I'm not sure it is...
— MrPineappleHat
[4.0.1] - 2025-07-07
FAQs
Tries to execute a function and discards any error that occurs
The npm package nice-try receives a total of 10,021,592 weekly downloads. As such, nice-try popularity was classified as popular.
We found that nice-try demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.