Commit 6ebc057
authored
chore(sdk): Removes unnecessary throw statements (#412)
*Issue #, if available:*
#411
*Description of changes:*
Removes unnecessary exception handling patterns in
`with-durable-execution.ts`:
## 1. Simplified `validateDurableExecutionEvent`
The previous implementation threw an error inside a try block and
immediately caught all exceptions to replace with a different message:
```typescript
function validateDurableExecutionEvent(event: unknown): void {
try {
const eventObj = event as Record<string, unknown>;
if (!eventObj?.DurableExecutionArn || !eventObj?.CheckpointToken) {
throw new Error("Missing required durable execution fields");
}
} catch {
const msg = `Unexpected payload provided to start the durable
execution...`;
throw new Error(msg);
}
}
```
This was problematic because:
- The specific validation error message was never visible to callers
- Type assertions don't throw at runtime and optional chaining prevents most errors
- The `try/catch` was effectively redundant
Now simplified to directly throw the user-facing error without the wrapper.
## 2. Removed redundant catch block in `withDurableExecution`
The function contained a catch block that simply re-threw the error:
```ts
try {
response = await runHandler(...);
return response;
} catch (err) {
throw err;
}
```
This serves no purpose: errors propagate naturally without it. Replaced with a direct return of `runHandler()`.
---
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.1 parent 3c31bc3 commit 6ebc057
File tree
1 file changed
+14
-23
lines changed- packages/aws-durable-execution-sdk-js/src
1 file changed
+14
-23
lines changedLines changed: 14 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
280 | 277 | | |
281 | 278 | | |
282 | 279 | | |
| |||
368 | 365 | | |
369 | 366 | | |
370 | 367 | | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
385 | 376 | | |
386 | 377 | | |
0 commit comments