-
Notifications
You must be signed in to change notification settings - Fork 14
chore: add missing sections #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+170
−17
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| --- | ||
| title: Validation Steps | ||
| description: Use explicit validation steps to fail fast on invalid input | ||
| sidebar: | ||
| order: 30 | ||
| --- | ||
|
|
||
| import { Aside } from '@astrojs/starlight/components'; | ||
|
|
||
| Validation steps catch invalid input early, before expensive operations run. Structure them to fail fast with no retries. | ||
|
|
||
| ## Why Explicit Validation Steps? | ||
|
|
||
| pgflow retries all exceptions based on `maxAttempts`. Without explicit validation, input errors waste retry attempts: | ||
|
|
||
| ```typescript | ||
| // Without validation - wastes retry attempts on invalid input | ||
| new Flow<{ email: string }>({ slug: 'sendEmail', maxAttempts: 5 }) | ||
| .step( | ||
| { slug: 'send' }, | ||
| async (input) => { | ||
| if (!input.run.email.includes('@')) { | ||
| throw new Error('Invalid email'); // Retries 5 times! | ||
| } | ||
| return await sendEmail(input.run.email); | ||
| } | ||
| ) | ||
| ``` | ||
|
|
||
| With explicit validation, failures stop immediately: | ||
|
|
||
| ```typescript | ||
| // With validation - fails immediately on invalid input | ||
| new Flow<{ email: string }>({ slug: 'sendEmail' }) | ||
| .step( | ||
| { slug: 'validInput', maxAttempts: 1 }, | ||
| (input) => { | ||
| if (!input.run.email.includes('@')) { | ||
| throw new Error('Invalid email'); | ||
| } | ||
| return input.run; | ||
| } | ||
| ) | ||
| .step( | ||
| { slug: 'send', dependsOn: ['validInput'], maxAttempts: 5 }, | ||
| async (input) => await sendEmail(input.validInput.email) | ||
| ) | ||
| ``` | ||
|
|
||
| ## Keep Validation Synchronous | ||
|
|
||
| Validation steps should be fast, synchronous functions that check input format and structure. Avoid async operations like database queries or API calls - those belong in separate steps with appropriate retry configuration. | ||
|
|
||
| ```typescript | ||
| // Good: Fast, synchronous validation | ||
| .step( | ||
| { slug: 'validOrder', maxAttempts: 1 }, | ||
| (input) => { | ||
| const { amount, items } = input.run; | ||
|
|
||
| if (amount <= 0) throw new Error('amount must be positive'); | ||
| if (!items?.length) throw new Error('items cannot be empty'); | ||
|
|
||
| return input.run; | ||
| } | ||
| ) | ||
|
|
||
| // Bad: Async checks in validation | ||
| .step( | ||
| { slug: 'validCustomer', maxAttempts: 1 }, | ||
| async (input) => { | ||
| // Database lookups belong in separate steps with retries | ||
| const exists = await checkCustomerExists(input.run.customerId); | ||
| if (!exists) throw new Error('Customer not found'); | ||
| return input.run; | ||
| } | ||
| ) | ||
| ``` | ||
|
|
||
| <Aside type="tip"> | ||
| Validation steps check **format and structure** (email format, positive numbers, array length). Existence checks and external validations belong in regular steps with retry configuration. | ||
| </Aside> | ||
|
|
||
| ## See Also | ||
|
|
||
| - [Retrying Steps](/build/retrying-steps/) - Understanding failure types and retry policies | ||
| - [Context Object](/concepts/context-object/) - Accessing validated input in dependent steps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The page rename to
/build/retrying-steps/updates the navigation, but there is no corresponding redirect entry for the previous/build/configuring-retries/URL. Any external links, bookmarks, or cached search results for the old path will now return 404s. The documentation guidelines inCLAUDE.mdrequire adding redirects when renaming pages. Please add a mapping inredirects.config.mjsto forward/build/configuring-retries/to/build/retrying-steps/so historical links continue to work.Useful? React with 👍 / 👎.