Skip to content

Commit ae510c8

Browse files
authored
chore: minor changes on wording (#14)
1 parent 0014961 commit ae510c8

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

src/content/post/stop-forwarding-errors-start-designing-them.mdx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ pub fn fetch_user(user_id: &str) -> Result<User, Exn<ServiceError>> {
264264
// You must provide context at the boundary
265265
pub fn fetch_user(user_id: &str) -> Result<User, Exn<ServiceError>> {
266266
let user = db.query(user_id)
267-
.or_raise(|| ServiceError(format!("failed to query user {user_id}")))?; // Now it compiles
267+
.or_raise(|| ServiceError(format!("failed to fetch user {user_id}")))?; // Now it compiles
268268
Ok(user)
269269
}
270270
```
@@ -277,12 +277,8 @@ Here's what this looks like in practice:
277277
pub async fn execute(&self, task: Task) -> Result<Output, ExecutorError> {
278278
let make_error = || ExecutorError(format!("failed to execute task {}", task.id));
279279

280-
let user = self.fetch_user(task.user_id)
281-
.await
282-
.or_raise(make_error)?;
283-
284-
let result = self.process(user)
285-
.or_raise(make_error)?;
280+
let user = self.fetch_user(task.user_id).await.or_raise(make_error)?;
281+
let result = self.process(user).or_raise(make_error)?;
286282

287283
Ok(result)
288284
}
@@ -298,7 +294,7 @@ failed to execute task 7829, at src/executor.rs:45:12
298294
|-> connection refused, at src/client.rs:89:24
299295
```
300296

301-
Now you know: it was task-7829, we were fetching data, and the connection was refused. You can grep for that task ID in your request logs and find everything you need.
297+
Now you know: it was task 7829, we were fetching user data, and the connection was refused. You can grep for that task ID in your request logs and find everything you need.
302298

303299
---
304300

@@ -353,12 +349,13 @@ match save_document(doc).await {
353349
}
354350
return Err(map_to_http_status(err.kind));
355351
}
352+
356353
Err(StatusCode::INTERNAL_SERVER_ERROR)
357354
}
358355
}
359356
```
360357

361-
Yes, you need to walk the tree--but compare this to the `Provide`/`Request` API. Here, you're looking for a *concrete type* like `StorageError`. It has named fields. It has documentation. Your IDE can autocomplete it. No guessing, no runtime surprises--just a well-defined struct you can reason about and maintain.
358+
Yes, you still need to walk the tree. But unlike the `Provide`/`Request` API, you end up with a concrete type like `StorageError`—a documented struct with named fields that your IDE can autocomplete. No guessing, no runtime surprisesjust something you can reason about and maintain.
362359

363360
---
364361

0 commit comments

Comments
 (0)