Skip to content

Commit

Permalink
Editorial recommendations for README (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
garretmh authored Jan 23, 2025
1 parent a6b44f9 commit 23d2e5c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ async function handle(request, reply) {
return reply.status(500).send({ error: "Could not get user info" })
}

const posts = try await db.getPosts(userInfo.authorId)
const posts = try await db.getPosts(userInfo.value.authorId)

if (!posts.ok) {
logger.error(posts.error, "Anonymous user behavior not implemented yet")
return reply.status(500).send({ error: "Could not get posts" })
}

const comments = try await db.getComments(posts.map((post) => post.id))
const comments = try await db.getComments(posts.value.map((post) => post.id))

if (!comments.ok) {
logger.error(comments.error, "Posts without comments not implemented yet")
Expand Down Expand Up @@ -353,18 +353,21 @@ If you want to suppress the error (which is **different** from ignoring the poss
```ts
// This suppresses a possible error (Ignores and doesn't re-throw)
const [ok, _, data] = try fn()
const [ok, , data] = try fn()
```
This approach is explicit and readable, as it acknowledges the possibility of an error while indicating that you do not care about it.
The above method, often referred to as "try-catch calaboca" (a Brazilian term), can also be written as:
```ts
let ok = true
let data
try {
data = fn()
} catch {}
} catch {
ok = false
}
```
A detailed discussion about this topic is available at [GitHub Issue #13](https://github.com/arthurfiorette/proposal-try-statements/issues/13) for those interested.
Expand Down

0 comments on commit 23d2e5c

Please sign in to comment.