docs/agent-guides/code-quality.md
Production database. Correctness paramount. Crash > corrupt.
unwrap()Never use bare unwrap(). Instead:
For truly unreachable states (invariants that should never be violated):
// Good: documents the invariant
let value = option.expect("value must be set in Init phase");
For recoverable errors (states that could happen at runtime):
// Good: proper error handling
let Some(value) = option else {
return Err(LimboError::InvalidArgument("value not provided".into()));
};
The choice depends on whether the None/Err case represents:
expect with descriptive message)let ... else or match)Wrong:
if condition {
// happy path
} else {
// "shouldn't happen" - silently ignored
}
Right:
// If only one branch should ever be hit:
assert!(condition, "invariant violated: ...");
// OR
return Err(LimboError::InternalError("unexpected state".into()));
// OR
unreachable!("impossible state: ...");
Use if-statements only when both branches are expected paths.
Do:
Don't:
_vars, re-exports, // removed comments)