
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@andreasnicolaou/safe
Advanced tools
A simple utility for handling synchronous and asynchronous errors without relying on try-catch blocks.
try...catch everywhere?Let @andreasnicolaou/safe handle it for you. This tiny, library automatically wraps your functions and promises in a safe execution environment.
# npm
npm install @andreasnicolaou/safe
# yarn
yarn add @andreasnicolaou/safe
# pnpm
pnpm add @andreasnicolaou/safe
For direct browser usage without a build step:
<!-- unpkg CDN (latest version, unminified) -->
<script src="https://unpkg.com/@andreasnicolaou/safe/dist/index.umd.js"></script>
<!-- unpkg CDN (latest version, minified) -->
<script src="https://unpkg.com/@andreasnicolaou/safe/dist/index.umd.min.js"></script>
<!-- jsDelivr CDN (unminified) -->
<script src="https://cdn.jsdelivr.net/npm/@andreasnicolaou/safe/dist/index.umd.js"></script>
<!-- jsDelivr CDN (minified) -->
<script src="https://cdn.jsdelivr.net/npm/@andreasnicolaou/safe/dist/index.umd.min.js"></script>
The library will be available as safe on the global scope:
<script>
// Example: use safe utilities from the global `safe` object
const { safe: safeFn, isSuccess, isFailure } = safe;
const [error, result] = safeFn(() => JSON.parse('{"foo": 123}'));
if (isSuccess([error, result])) {
console.log('Parsed:', result);
}
</script>
You can use this library in any modern JavaScript environment:
import { safe, isSuccess, isFailure } from '@andreasnicolaou/safe';
const [error, result] = safe(() => JSON.parse('{"foo": 123}'));
if (isSuccess([error, result])) {
console.log('Parsed:', result);
}
const { safe, isSuccess, isFailure } = require('@andreasnicolaou/safe');
const [error, result] = safe(() => JSON.parse('{"foo": 123}'));
if (isSuccess([error, result])) {
console.log('Parsed:', result);
}
<script src="https://unpkg.com/@andreasnicolaou/safe/dist/index.umd.min.js"></script>
<script>
const { safe: safeFn, isSuccess, isFailure } = safe;
const [error, result] = safeFn(() => JSON.parse('{"foo": 123}'));
if (isSuccess([error, result])) {
console.log('Parsed:', result);
}
</script>
import { safe, isSuccess, isFailure } from '@andreasnicolaou/safe';
const [error, result] = safe(() => {
throw new Error('An error Occured!');
});
console.log(error); // An error Occured!
console.log(result); // undefined
console.log(isSuccess([error, result])); // false
console.log(isFailure([error, result])); // true
const { safe, safeWithRetries } = createSafeUtils({
logger: (error) => sentry.captureException(error),
logErrors: process.env.NODE_ENV === 'production',
});
Contributions are welcome! If you encounter issues or have ideas to enhance the library, feel free to submit an issue or pull request.
FAQs
A simple utility for handling synchronous and asynchronous errors without relying on try-catch blocks.
We found that @andreasnicolaou/safe 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.