![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@fakenickels/let-anything
Advanced tools
It allows you to create monadic syntax for all sorts of monad-y values, heavily inspired by OCaml's shiny new syntax and the name is inspired by Jared's let-anything
yarn add @fakenickels/let-anything
If you ever had to deal with error handling in JS with async/await you know how painful it can get.
You can do it with try-catch
async function checkoutPurchase({productId, userId}) {
try {
const product = await Product.findOne(productId);
const user = await User.findOne(userId)
const card = await CreditCards.findOneByUserId(userId)
await Charge.create({
customerId: user.customerId,
source: card.source,
price: product.price,
});
return {success: true}
} catch(e) {
console.log(e.message) // not very helpul
return {error: "Oopsie! Something went wrong and we have no clue about it!"}
}
}
A lot of things can go wrong there and try catch will just make it very hard to determine what.
Some attempts to make that process better to handle have been offered by the community, like eres inspired by Go's way of handling with errors.
async function checkoutPurchase({productId, userId}) {
const [productErr, product] = await eres(Product.findOne(productId));
if(productErr) {
return {error: "Coulnd't find that product"}
}
const [userErr, user] = await eres(User.findOne(userId));
if(userErr) {
return {error: "User not found"}
}
const [cardErr, card] = await eres(CreditCards.findOneByUserId(userId));
if(cardErr) {
return {error: "User not found"}
}
const [chargeErr,] = await eres(Charge.create({
customerId: user.customerId,
source: card.source,
price: product.price,
}));
if(chargeErr) {
return {error: "Failed to charge user"}
}
return {success: true}
}
Well even though now we have a much more fine grained and correct error handling that's very awful and boilerplate-y and now our main logic is mixed with error handling making the code much harder to read. Looks like there is no way around that if we want to be good coders and handle our damn exceptions, or is it? plays VSauce soung Actually there is a much better way. And those FP smartass jerks (just kidding peeps) have been hiding it for themselves all along.
In the FP world there is a being called result
and with it you can box values with two branches: the sucess branch and the error branch.
import {ok, error} from ''
async function findOne(id) {
try {
const value = await originalFindOne(id)
return ok(value)
} catch(e) {
return error({error: e})
}
}
Basically if you build your code around those following some juice mathmagical laws you get better error handling for free.
FAQs
Unknown package
The npm package @fakenickels/let-anything receives a total of 1 weekly downloads. As such, @fakenickels/let-anything popularity was classified as not popular.
We found that @fakenickels/let-anything demonstrated a not healthy version release cadence and project activity because the last version was released 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.