
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@dschz/try-catch
Advanced tools
A tiny utility to wrap promises or async functions and return a
[error, data]
tuple — no moretry/catch
boilerplate.
Result<T, E>
npm install @dschz/try-catch
pnpm install @dschz/try-catch
yarn install @dschz/try-catch
bun install @dschz/try-catch
import { tryCatch } from "@dschz/try-catch";
const [err, res] = await tryCatch(fetch("/api/data"));
const [err, user] = await tryCatch(() => fetchUserById(123));
const [err, parsed] = await tryCatch(() => JSON.parse('{"valid":true}'));
if (err) {
console.error("Invalid JSON:", err.message);
}
⚠️ Always wrap expressions that might throw in a function. This ensures the error is caught inside the try-catch scope.
// ✅ CORRECT
await tryCatch(() => JSON.parse("{ malformed }"));
// ❌ INCORRECT — throws before tryCatch is even called
await tryCatch(JSON.parse("{ malformed }"));
type Success<T> = [error: null, data: T];
type Failure<E extends Error = Error> = [error: E, data: null];
type Result<T, E extends Error = Error> = Success<T> | Failure<E>;
The return value is a tuple:
[error, data]; // One will always be null
class MyError extends Error {
constructor(message: string) {
super(message);
this.name = "MyError";
}
}
const [err, data] = await tryCatch<MyType, MyError>(() => doSomething());
MIT © Daniel Sanchez
1.1.3
FAQs
Simple try-catch utility function for JavaScript
The npm package @dschz/try-catch receives a total of 2 weekly downloads. As such, @dschz/try-catch popularity was classified as not popular.
We found that @dschz/try-catch 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
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.