patdx
Re:Node.js 20 is now available
on Tuesday April 18, 2023 @09:54PM (#35623307)
The big problem is Express code like the following will either hang the HTTP request forever (--unhandled-rejections=warn), until the client times out and gives up, or crash your whole server, taking down any other HTTP requests in progress (--unhandled-rejections=throw):
const db = {
async getUsers() {
throw new Error("failed to connect to database");
},
};
app.get("/", async (req, res) => {
const result = await db.getUsers();
return result;
});
There are various monkey patches/wrappers you can use to make async errors work the same as sync errors, but it is easy to forget and hard to understand, especially for newbies. Many other frameworks handle async/sync errors in a more consistent way.
Re:React is a fractal of bad design
on Wednesday March 08, 2023 @10:17AM (#35069997)
That’s a good point, that example does feel a bit contrived. Interestingly though it is actually “canon” to call setState within the render function (for certain rare situations). I didn’t actually know this until I read the React beta docs: https://beta.reactjs.org/learn/you-might-not-need-an-effect#...
Re:KanjiVG – SVGs of Kanji character strokes including order, shape an...
on Tuesday February 21, 2023 @07:52PM (#34890015)
That's a neat project. While they are extremely similar, there are still many variations. For example one small variation is 今 is written with a horizontal stroke in Japan but a slanted stroke in mainland China.
https://en.wiktionary.org/wiki/%E4%BB%8A#Alternative_forms
https://github.com/KanjiVG/kanjivg/blob/master/kanji/04eca.s...
Re:The Pretty JSON Revolution
on Wednesday February 24, 2021 @02:23AM (#26247527)
Basically yes, though `{` and `}` also start and end expression blocks in JavaScript. So the JS formatter needs to be aware that it is working with a JSON object and not a complete expression.
Valid JSON:
{
"key1": "hello",
"key2": "world"
}
You could "trick" a JS formatter to format it by wrapping with a fake function, etc. Some minimum valid JS: json({
key1: "hello",
key2: "world",
});
MongoDB has some JS libraries that use similar tricks to use JS parsers for their shell query format (which is similar to JSON). For example, around line 597: https://unpkg.com/browse/[email protected]/dist/ejson...