Many real-world workflows involve several sequential steps where each step depends on the success of the previous one — reading a file, validating its contents, transforming the data, and so on. BasicReturns makes these pipelines easy to reason about: every step returns a result with anDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/dev2forge/BasicReturns/llms.txt
Use this file to discover all available pages before exploring further.
ok flag, and a single check at each stage is enough to decide whether to continue or return an error immediately. This “early return on failure” pattern keeps nesting shallow and makes the happy path easy to follow.
Chaining in Practice
The example below is taken directly from the BasicReturns README.load_and_validate_config chains a file-read step with a validation step, propagating errors from either step to the caller without losing detail.
Step-by-Step Explanation
Each step calls the previous and checks ok
Every operation in the chain is a function that returns a
BasicReturn or DataAndMsgReturn. After calling each one, inspect result.ok before proceeding. If ok is True, extract the data you need and pass it to the next step.If ok is False, return the failed result immediately
The moment any step fails, return its result (or a newly constructed
DataAndMsgReturn) without executing any remaining steps. This early-return pattern prevents downstream code from operating on invalid or missing data and keeps the function body flat.When to Propagate vs. Wrap Errors
When a step fails you have two options: pass the failed result straight back to the caller, or construct a newDataAndMsgReturn that adds context. The right choice depends on whether the caller needs to know which step failed and why.
- Propagate
- Wrap
Return the failed result directly. The caller receives the original
ok, error, and msg fields unchanged — a fully transparent pipeline. Use this when the upstream error message is already descriptive enough.Returning a failed result directly — the “propagate” approach — passes all of its fields (
ok, error, msg, and data) to the caller unchanged. This is ideal for transparent pipelines where the original error context is the most useful information the caller can receive.Minimal Three-Step Pipeline
The pattern scales naturally to any number of steps. The example below shows a read → validate → transform pipeline; each stage checksok and returns early on failure, keeping the logic linear and easy to test in isolation.