Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.