
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@nickfthedev/gotry
Advanced tools
TypeScript/JavaScript error handling inspired by Go's error pattern.
npm install @nickfthedev/gotry
The package provides two functions: gotry
for synchronous operations and gotryAsync
for asynchronous operations. Both return a tuple of [result, error]
.
import { gotry } from "gotry";
const [result, error] = gotry(() => {
return someRiskyOperation();
});
if (error) {
console.error("Operation failed:", error);
return;
}
console.log("Success:", result);
import { gotryAsync } from "gotry";
const [result, error] = await gotryAsync(async () => {
return await fetchSomeData();
});
if (error) {
console.error("Fetch failed:", error);
return;
}
console.log("Data:", result);
Executes a synchronous function and returns a tuple containing the result and error (if any).
import { gotry } from "gotry";
const [result, error] = gotry(() => {
if (Math.random() > 0.5) throw new Error("Bad luck!");
return "Success!";
});
Executes an asynchronous function and returns a promise of a tuple containing the result and error (if any).
import { gotryAsync } from "gotry";
const [result, error] = await gotryAsync(async () => {
const response = await fetch("https://api.example.com/data");
return response.json();
});
Both functions follow Go's error handling pattern:
[result, null]
[null, error]
All errors are guaranteed to be instances of Error
. If a non-Error is thrown, it will be converted to an Error instance.
MIT
FAQs
Go-style error handling with try-catch wrapper
We found that @nickfthedev/gotry demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.