fix(formula): address code review findings
Fixes from self-review of formula parser and bd cook: 1. Atomicity: Add cleanup on failure in cookFormula - if labels/deps transaction fails, delete the already-created issues 2. Validation: Add recursive depends_on validation for child steps and validate priority ranges for children 3. Documentation: Mark unimplemented fields (Expand, ExpandVars, Condition, Gate) with TODO(future) comments 4. Thread safety: Add note that Parser is NOT thread-safe 5. Error messages: Track first definition location for duplicate ID errors (e.g., "duplicate id at steps[1], first defined at steps[0]") 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -243,6 +243,9 @@ func cookFormula(ctx context.Context, s storage.Storage, f *formula.Formula) (*c
|
||||
return nil, fmt.Errorf("failed to create issues: %w", err)
|
||||
}
|
||||
|
||||
// Track if we need cleanup on failure
|
||||
issuesCreated := true
|
||||
|
||||
// Add labels and dependencies in a transaction
|
||||
err := s.RunInTransaction(ctx, func(tx storage.Transaction) error {
|
||||
// Add labels
|
||||
@@ -263,6 +266,18 @@ func cookFormula(ctx context.Context, s storage.Storage, f *formula.Formula) (*c
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
// Clean up: delete the issues we created since labels/deps failed
|
||||
if issuesCreated {
|
||||
cleanupErr := s.RunInTransaction(ctx, func(tx storage.Transaction) error {
|
||||
for i := len(issues) - 1; i >= 0; i-- {
|
||||
_ = tx.DeleteIssue(ctx, issues[i].ID) // Best effort cleanup
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if cleanupErr != nil {
|
||||
return nil, fmt.Errorf("%w (cleanup also failed: %v)", err, cleanupErr)
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user