Alex Gleason 🐍🚬 on Nostr: Let me tell you what I learned about JavaScript today, that I wish I didn't have to. ...
Let me tell you what I learned about JavaScript today, that I wish I didn't have to. If you create a rejected promise, and you put it in a variable, and you don't catch the promise in the same tick, it results in an "unhandled promise rejection" that crashes your entire application. Also, if it's not an "Error" instance that rejects (but rather a different type of primitive or object), you don't even get a stack trace. You get an error like this:
error: Uncaught (in promise) null
With absolutely no other information. Your application is crashed and you have no idea how to fix it. And you'd better pray you logged the right stuff above it to use context clues to figure it out.
Anyway, here is the problem code (left) and the fixed solution (right).
Published at
2024-10-10 02:27:57Event JSON
{
"id": "6a1ecf402012358931cab465bc20fa7b3c4403ea2aabbd8fa9927d24d22906f7",
"pubkey": "0461fcbecc4c3374439932d6b8f11269ccdb7cc973ad7a50ae362db135a474dd",
"created_at": 1728527277,
"kind": 1,
"tags": [
[
"imeta",
"url https://image.nostr.build/b3f01ac78bbc7b0663f671571df079e65ac2538a34539d723ea5c0d0138c941c.png",
"m image/png",
"x eaa5cd44b5f39fc1efd4968f0593aeb0561502cbf0a6016cd339499e5b5f42cd",
"ox b3f01ac78bbc7b0663f671571df079e65ac2538a34539d723ea5c0d0138c941c",
"size 89192",
"dim 1206x538",
"blurhash L05E?O~XWHR:-=xuofRjSzRjoKt6"
],
[
"imeta",
"url https://image.nostr.build/145b01c72531ed614ea8ac298c10c9527635b6668defa6c76e4aaed706e5fad8.png",
"m image/png",
"x 0c1ddf1a12198f52ad494fb2518e615c9ffe54e54bcc3b3da6ebed27b371f4b3",
"ox 145b01c72531ed614ea8ac298c10c9527635b6668defa6c76e4aaed706e5fad8",
"size 98568",
"dim 1206x538",
"blurhash L05E]W~XRpNL-=xaofR+X9R*jZs:"
]
],
"content": "Let me tell you what I learned about JavaScript today, that I wish I didn't have to. If you create a rejected promise, and you put it in a variable, and you don't catch the promise in the same tick, it results in an \"unhandled promise rejection\" that crashes your entire application. Also, if it's not an \"Error\" instance that rejects (but rather a different type of primitive or object), you don't even get a stack trace. You get an error like this:\n\nerror: Uncaught (in promise) null\n\nWith absolutely no other information. Your application is crashed and you have no idea how to fix it. And you'd better pray you logged the right stuff above it to use context clues to figure it out.\n\nAnyway, here is the problem code (left) and the fixed solution (right).\n\nhttps://image.nostr.build/b3f01ac78bbc7b0663f671571df079e65ac2538a34539d723ea5c0d0138c941c.png\nhttps://image.nostr.build/145b01c72531ed614ea8ac298c10c9527635b6668defa6c76e4aaed706e5fad8.png",
"sig": "545d6c7e9e89414a5b70aa296e68dfe72176b29928d87e7841c4539a26f79efe3d5e6ed2d3aa813167a3a5730df90c5b289ac3bf8fdc3f42923c5f869b4c6807"
}