Skip to content

Commit f2a30d5

Browse files
Arlen22Copilotarthurfiorette
authored
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Arthur Fiorette <47537704+arthurfiorette@users.noreply.github.com>
1 parent 7f79d81 commit f2a30d5

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const [ok, fetchErr, res] = try fs.readFileSync("data.txt")
2121

2222
This proposal addresses the ergonomic challenges of managing multiple, often nested, `try/catch` blocks necessary for handling operations that may fail at various points.
2323

24-
The try block needlessly encloses the protected code in a block. This often prevents straightforward `const` assignment patterns and can reduce readability and static analysis through additional nesting. The `catch (error) {}` branch is usually where control-flow divergence happens, while the successful path often just assigns a variable.
24+
The try block needlessly encloses the protected code in a block. This often prevents straightforward `const` assignment patterns and can reduce readability and hinder static analysis through additional nesting. The `catch (error) {}` branch is usually where control-flow divergence happens, while the successful path often just assigns a variable.
2525

2626
The solution is to add a `try <expression>` operator, a syntax similar to `await <expression>`, which catches any error that occurs when executing its expression and returns it as a value to the caller.
2727

@@ -144,7 +144,6 @@ function getPostInfo(session, postSlug, cache, db) {
144144

145145
In this example, the `try` blocks introduce additional nesting and prevent the protection a `const` declaration would provide.
146146

147-
It also tends to interfere with static analysis tools, forcing developers to look for alternate solutions.
148147

149148
Instead, using the proposed `try` operator simplifies the function:
150149

@@ -291,7 +290,7 @@ function getUser(id, request, response) {
291290

292291
This is obviously far more code to maintain, a lot of it repetitive and often redundent in these scenarios.
293292

294-
I'm sure there are times when returning a Result might make sense, but this proposal isn't about that. It's about the `try` operator, and the try operator just needs some way to encapsulate its three values.
293+
There are times when returning a Result might make sense, but this proposal isn't about that. It's about the `try` operator, and the try operator just needs some way to encapsulate its three values.
295294

296295
Even here, the benefit of the try operator is that developers can pass the whole try expression to a helper function that converts the Result into their chosen error composition cascade. The callback that would previously have been required, which often makes static analysis more context dependant and difficult, is no longer necessary.
297296

0 commit comments

Comments
 (0)