Skip to content

Commit 76ef2a0

Browse files
committed
docs: add SDK example tasks (error handling, JSON file, validate config)
Add three new tasks to phase-2-improvements.md: - Task 12: Error handling example (SdkError matching, recovery) - Task 13: Create-from-JSON-file example (CLI migration path) - Task 14: Validate config example (CI pre-flight checks) Add two lower-priority example ideas to additional-improvements.md: - Idempotent deploy example (resume after interruption) - Custom progress listener example (UI/dashboard integration)
1 parent 22d9360 commit 76ef2a0

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

docs/experiments/sdk/additional-improvements.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ The CLI has a `render` command (already async). It is useful for inspecting
6969
generated configuration files without actually provisioning. This could be
7070
added alongside the other async operations in Task 9.
7171

72+
### Idempotent Deploy Example
73+
74+
An `examples/sdk/idempotent_deploy.rs` that uses `exists()` + `show()` to
75+
check environment state before each step, skipping already-completed stages.
76+
Demonstrates how to build resilient automation that can resume after
77+
interruptionsa more advanced pattern but very practical for production
78+
use.
79+
80+
### Custom Progress Listener Example
81+
82+
An `examples/sdk/custom_progress.rs` showing a richer
83+
`CommandProgressListener` implementationfor example writing to a log
84+
file, updating a progress bar, or collecting step timings. The current
85+
`PrintProgressListener` in `full_deployment.rs` is minimal; a more
86+
realistic example would help users building UIs or dashboards on top of
87+
the SDK.
88+
7289
## Lower Priority / Future
7390

7491
### SDK Changelog / Migration Guide

docs/experiments/sdk/phase-2-improvements.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,50 @@ SDK-only consumers, and cleaner public API boundaries.
229229
- Set up independent semver versioning
230230
- Publish to crates.io (or keep private, depending on project policy)
231231

232+
### Task 12: Error handling example
233+
234+
**Complexity**: Simple
235+
**Why**: Neither current example demonstrates error recovery. They both
236+
use `?` to propagate everything. SDK users need to see how to match on
237+
`SdkError` variants, handle "environment already exists" gracefully, and
238+
implement retry logic — the most common question for programmatic consumers.
239+
240+
**Work**:
241+
242+
- Create `examples/sdk/error_handling.rs`
243+
- Demonstrate matching on specific `SdkError` variants
244+
- Show recovery pattern: if environment exists, skip create
245+
- Show retry logic for transient failures (e.g., provision timeout)
246+
- Register in `Cargo.toml`
247+
248+
### Task 13: Create-from-JSON-file example
249+
250+
**Complexity**: Simple
251+
**Why**: `create_environment_from_file()` is the second entry point into
252+
the SDK (alongside the builder) but no example covers it. Users migrating
253+
from the CLI will likely have JSON config files already.
254+
255+
**Work**:
256+
257+
- Create `examples/sdk/create_from_json_file.rs`
258+
- Use `deployer.create_environment_from_file(path)` with a fixture JSON
259+
- Show validate → create → show → purge flow
260+
- Register in `Cargo.toml`
261+
262+
### Task 14: Validate config example
263+
264+
**Complexity**: Trivial
265+
**Why**: The `validate()` method is useful for CI pipelines and pre-flight
266+
checks but has no dedicated example. Demonstrates a use case distinct from
267+
"deploy everything."
268+
269+
**Work**:
270+
271+
- Create `examples/sdk/validate_config.rs`
272+
- Validate a config file and print results
273+
- Show both valid and invalid config handling
274+
- Register in `Cargo.toml`
275+
232276
## Summary
233277

234278
| # | Task | Complexity | Improves | Status |
@@ -244,3 +288,6 @@ SDK-only consumers, and cleaner public API boundaries.
244288
| 9 | Async operations (provision, etc) | High | Full workflow | Done |
245289
| 10 | Scoped environment guard | Medium | Cleanup safety | |
246290
| 11 | Extract into separate crate | High | API stability | |
291+
| 12 | Error handling example | Simple | Documentation | |
292+
| 13 | Create-from-JSON-file example | Simple | Documentation | |
293+
| 14 | Validate config example | Trivial | Documentation | |

0 commit comments

Comments
 (0)