
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
@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, data] = await tryCatch(fetch("/api/data"));
if (err) {
console.error("Something went wrong:", err);
} else {
console.log("Data:", data);
}
You can also pass a function that returns a promise:
const [err, user] = await tryCatch(() => fetchUserById(123));
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 © @dschz
FAQs
Simple try-catch utility function for JavaScript
The npm package @dschz/try-catch receives a total of 129 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
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.