Skip to content

Commit a26728f

Browse files
Typos and Rewriting (#77)
1 parent 1476726 commit a26728f

File tree

3 files changed

+56
-45
lines changed

3 files changed

+56
-45
lines changed

README.md

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313

1414
<br />
1515

16-
This proposal aims to address the ergonomic challenges of managing multiple, often nested, `try/catch` blocks that are necessary for handling operations that may fail at various points.
16+
This proposal addresses the ergonomic challenges of managing multiple, often nested, `try/catch` blocks necessary for handling operations that may fail at various points.
1717

1818
Only the `catch (error) {}` block represents actual control flow, while no program state inherently depends on being inside a `try {}` block. Therefore, forcing the successful flow into nested blocks is not ideal.
1919

2020
<hr />
2121
<br />
2222

2323
- [Try/Catch Is Not Enough](#trycatch-is-not-enough)
24+
- [Status](#status)
25+
- [Authors](#authors)
2426
- [Caller's Approach](#callers-approach)
2527
- [What This Proposal Does Not Aim to Solve](#what-this-proposal-does-not-aim-to-solve)
2628
- [Type-Safe Errors](#type-safe-errors)
@@ -42,7 +44,6 @@ Only the `catch (error) {}` block represents actual control flow, while no progr
4244
- [The Need for an `ok` Value](#the-need-for-an-ok-value)
4345
- [Why a Proposal?](#why-a-proposal)
4446
- [Help Us Improve This Proposal](#help-us-improve-this-proposal)
45-
- [Authors](#authors)
4647
- [Inspiration](#inspiration)
4748
- [License](#license)
4849

@@ -125,7 +126,23 @@ async function handle(request, reply) {
125126
}
126127
```
127128

128-
A `try` statement provide significant flexibility and arguably result in more readable code. A `try` statement is a statement that can be used wherever a statement is expected, allowing for concise and readable error handling.
129+
A `try` statement provides significant flexibility and arguably results in more readable code. A `try` statement is a statement that can be used wherever a statement is expected, allowing for concise and readable error handling.
130+
131+
<br />
132+
133+
## Status
134+
135+
**Stage:** 0 \
136+
**Champion:** _Actively looking for one_
137+
138+
_For more information see the [TC39 proposal process](https://tc39.es/process-document/)._
139+
140+
<br />
141+
142+
## Authors
143+
144+
- [Arthur Fiorette](https://github.com/arthurfiorette) <sub>([X](https://x.com/arthurfiorette))</sub>
145+
- [Arlen Beiler](https://github.com/Arlen22)
129146

130147
<br />
131148

@@ -139,7 +156,7 @@ With that in mind, improvements in error handling can be approached in two ways:
139156

140157
```js
141158
try {
142-
const result = work()
159+
const value = work()
143160
} catch (error) {
144161
console.error(error)
145162
}
@@ -149,12 +166,12 @@ With that in mind, improvements in error handling can be approached in two ways:
149166

150167
```js
151168
function work() {
152-
// Performs some operation
169+
try {
170+
// Performs some operation
153171

154-
if (error) {
155-
return { status: "error", error }
156-
} else {
157-
return { status: "ok", data }
172+
return { ok: true, value }
173+
} catch (error) {
174+
return { ok: false, error }
158175
}
159176
}
160177
```
@@ -173,11 +190,11 @@ Ironically, these are precisely the kinds of functions where improved error hand
173190

174191
### Type-Safe Errors
175192

176-
The `throw` statement in JavaScript can throw any type of value. This proposal does not impose nor proposes any kind safety around error handling.
193+
The `throw` statement in JavaScript can throw any type of value. This proposal does not impose nor propose any kind of safety around error handling.
177194

178195
- No generic error type for the proposed [Result](#result-class) class will be added.
179196
- No catch branching based on error type will be added. See [GitHub Issue #43](https://github.com/arthurfiorette/proposal-try-operator/issues/43) for more information.
180-
- No ways to annotate a callable to specify the error type it throws will be added.
197+
- No way to annotate a callable to specify the error type it throws will be added.
181198

182199
For more information, also see [microsoft/typescript#13219](https://github.com/Microsoft/TypeScript/issues/13219). _()_
183200

@@ -232,7 +249,7 @@ const result = _result
232249

233250
### Can be inlined.
234251

235-
Similar to `void`, `typeof`, `yield` and `new`:
252+
Similar to `void`, `typeof`, `yield`, and `new`:
236253

237254
```js
238255
array.map((fn) => try fn()).filter((result) => result.ok) // works :)
@@ -334,7 +351,7 @@ A detailed discussion about this topic is available at [GitHub Issue #55](https:
334351
335352
### Void Operations
336353
337-
In scenarios where the successful result of a operation is not needed, it can be safely ignored:
354+
In scenarios where the successful result of an operation is not needed, it can be safely ignored:
338355
339356
```js
340357
function work() {
@@ -369,7 +386,7 @@ The `Result` class represents the form of the value returned by the `try` operat
369386
370387
A `Result` instance contains three properties:
371388
372-
- **`ok`**: A boolean indicating whether the expression executed successfully.
389+
- **`ok`**: A boolean indicating whether the expression was executed successfully.
373390
- **`error`**: The error thrown during execution, or `undefined` if no error occurred.
374391
- **`value`**: The data returned from the execution, or `undefined` if an error occurred.
375392
@@ -500,13 +517,6 @@ This proposal is in its early stages, and we welcome your input to help refine i
500517
501518
<br />
502519
503-
## Authors
504-
505-
- [Arthur Fiorette](https://github.com/arthurfiorette) <sub>([X](https://x.com/arthurfiorette))</sub>
506-
- [Arlen Beiler](https://github.com/Arlen22)
507-
508-
<br />
509-
510520
## Inspiration
511521
512522
- [This tweet from @LeaVerou](https://x.com/LeaVerou/status/1819381809773216099)

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"private": true,
3-
"name": "proposal-try-statements",
3+
"name": "proposal-try-operator",
44
"description": "A repository template for ECMAScript proposals.",
55
"scripts": {
66
"start": "npm run build-loose -- --watch",
77
"build": "npm run build-loose -- --strict",
88
"build-loose": "node -e 'fs.mkdirSync(\"build\", { recursive: true })' && ecmarkup --load-biblio @tc39/ecma262-biblio --verbose spec.emu build/index.html --lint-spec"
99
},
10-
"homepage": "https://github.com/arthurfiorette/proposal-try-statements#readme",
10+
"homepage": "https://github.com/arthurfiorette/proposal-try-operator#readme",
1111
"repository": {
1212
"type": "git",
13-
"url": "git+https://github.com/arthurfiorette/proposal-try-statements.git"
13+
"url": "git+https://github.com/arthurfiorette/proposal-try-operator.git"
1414
},
1515
"license": "MIT",
1616
"devDependencies": {
@@ -19,5 +19,6 @@
1919
},
2020
"engines": {
2121
"node": ">= 12"
22-
}
22+
},
23+
"version": ""
2324
}

spec.emu

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,36 @@ contributors: Arthur Fiorette, Arlen Beiler
3939
<h1>
4040
TryExpressionResult (
4141
_result_: a Completion Record,
42-
): either a normal completion containing a TryResult or an abrupt completion
42+
): either a normal completion containing a Result or an abrupt completion
4343
</h1>
4444
<dl class="header">
4545
</dl>
4646
<emu-alg>
47-
1. If _result_ is a normal completion, return TryResult.ok(_result_.[[VALUE]]).
48-
1. If _result_ is a throw completion, return TryResult.error(_result_.[[VALUE]]).
47+
1. If _result_ is a normal completion, return Result.ok(_result_.[[VALUE]]).
48+
1. If _result_ is a throw completion, return Result.error(_result_.[[VALUE]]).
4949
1. Return ? _result_.
5050
</emu-alg>
5151
</emu-clause>
5252
<emu-clause id="sec-try-expression-result-ok" type="abstract operation">
5353
<h1>
54-
TryResult.ok (
54+
Result.ok (
5555
_value_: an ECMAScript language value,
56-
): a TryResult
56+
): a Result
5757
</h1>
5858
<dl class="header">
5959
<dt>description</dt>
60-
<dd>It is the abstract equivelant of calling `TryResult.ok(value)`</dd>
60+
<dd>It is the abstract equivelant of calling `Result.ok(value)`</dd>
6161
</dl>
6262
</emu-clause>
6363
<emu-clause id="sec-try-expression-result-error" type="abstract operation">
6464
<h1>
65-
TryResult.error (
65+
Result.error (
6666
_value_: an ECMAScript language value,
67-
): a TryResult
67+
): a Result
6868
</h1>
6969
<dl class="header">
7070
<dt>description</dt>
71-
<dd>It is the abstract equivelant of calling `TryResult.error(value)`</dd>
71+
<dd>It is the abstract equivelant of calling `Result.error(value)`</dd>
7272
</dl>
7373
</emu-clause>
7474
</emu-clause>
@@ -92,28 +92,28 @@ contributors: Arthur Fiorette, Arlen Beiler
9292
</thead>
9393
<tr>
9494
<td>
95-
%TryResult%
95+
%Result%
9696
</td>
9797
<td>
98-
`TryResult`
98+
`Result`
9999
</td>
100100
<td>
101-
The `TryResult` constructor (<emu-xref href="#sec-try-result-constructor"></emu-xref>)
101+
The `Result` constructor (<emu-xref href="#sec-result-constructor"></emu-xref>)
102102
</td>
103103
</tr>
104104
</table>
105105
</emu-table>
106106
</emu-clause>
107107

108-
<emu-clause id="sec-try-result-constructor">
109-
<h1>The TryResult Constructor</h1>
110-
<p>The TryResult constructor:</p>
108+
<emu-clause id="sec-result-constructor">
109+
<h1>The Result Constructor</h1>
110+
<p>The Result constructor:</p>
111111
<ul>
112-
<li>is <dfn variants="TryResult">%TryResult%</dfn>.</li>
113-
<li>is the initial value of the *"TryResult"* property of the global object.</li>
112+
<li>is <dfn variants="Result">%Result%</dfn>.</li>
113+
<li>is the initial value of the *"Result"* property of the global object.</li>
114114
<li>is the functional equivelant of the following code:
115115
<pre><code class="javascript">
116-
class TryResult {
116+
class Result {
117117
constructor(ok, error, value) {
118118
this.ok = ok
119119
this.error = error
@@ -125,10 +125,10 @@ contributors: Arthur Fiorette, Arlen Beiler
125125
yield this.value
126126
}
127127
static ok(value) {
128-
return new TryResult(true, undefined, value)
128+
return new Result(true, undefined, value)
129129
}
130130
static error(error) {
131-
return new TryResult(false, error, undefined)
131+
return new Result(false, error, undefined)
132132
}
133133
}
134134
</code></pre>

0 commit comments

Comments
 (0)