JavaScript is powerful, but its error handling is a mess. nullish checks everywhere, cryptic undefined is not a function errors, and inconsistent Promise handling make debugging painful. It's time to fix it.
The Problem: JavaScript’s Broken Error Handling
JavaScript lacks a native, structured way to handle success and failure cases. You either:
Rely on try/catch/finally, which only works for thrown errors.
Use null or undefined, forcing endless manual checks.
Work with Promises that fail silently if not properly caught.
This results in fragile, unpredictable code. TypeScript helps with types, but it doesn’t fix JavaScript’s fundamental error-handling flaws.
  
  
  The Solution: @rslike/std
Inspired by Rust’s Result and Option, @rslike/std introduces a structured way to handle errors and optional values.
1. Result: Explicit Success or Failure
import { Result } from "@rslike/std";
const safeDivide = (a: number, b: number) => {
  return new Result(() => {
    if (b === 0) throw new Error("Cannot divide by zero");
    return a / b;
  });
};
const result = safeDivide(10, 0);
console.log(result.unwrapOr("Error: Division failed"));
No more silent failures. You must handle both success and error cases.
  
  
  2. Option: No More null or undefined
import { Option } from "@rslike/std";
const findUser = (id: number) => {
  return new Option(() => (id === 1 ? { name: "Alice" } : undefined));
};
const user = findUser(2);
console.log(user.unwrapOr("No user found"));
No need for if (user !== null), just structured, predictable code.
Why This Matters
- Predictable: No more guessing if a function returns null, undefined, or an error.
- Readable: Code clearly expresses intent—handling success and failure.
- Safe: Eliminates unexpected runtime crashes.
Fix your JavaScript Today!
JavaScript’s error handling is broken, but we don’t have to accept it. @rslike/std brings clarity, safety, and sanity to your JavaScript/TypeScript projects. Try it out today:
👉 Install the package:
npm install @rslike/std
yarn add @rslike/std
pnpm add @rslike/std
bun add @rslike/std
deno add @rslike/std
🚀 Fix your JavaScript! Write better code!
github: https://github.com/vitalics/rslike/tree/main/packages/std
npm: https://www.npmjs.com/package/@rslike/std
Post Scriptum
I decided to pay for any (no matter pet or production) project that uses a @rslike/std package. You can contact me via email: vitalicset@gmail.com or via telegram vitalicset or comments to get more details.
 
 
              
 
    
Top comments (0)