Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kindermax
Copy link
Collaborator

@kindermax kindermax commented Jul 22, 2025

Display a dependency tree in error messages when a command fails within a dependency chain (fixes #187).

This improves debuggability by clearly showing which specific command in the chain failed, rather than just a generic "failed to run command" message for the dependent command.


Open Background Agent:
Web · Cursor

Learn more about Background Agents

Summary by Sourcery

Show dependency chains in error messages when a dependent command fails by introducing a new DependencyError type, tracking command dependency paths, and adjusting execution and exit code handling accordingly.

New Features:

  • Display a visual dependency tree in error output when a command fails within a dependency chain.

Enhancements:

  • Extend execution context to carry dependency paths and wrap child failures in DependencyError.
  • Update main exit logic to respect DependencyError exit codes alongside existing errors.

Tests:

  • Add BATS tests to verify single- and multi-level dependency failure trees.
  • Provide YAML-based test scenarios for sophisticated dependency failure chains.

@sourcery-ai
Copy link

sourcery-ai bot commented Jul 22, 2025

Reviewer's Guide

Introduces a DependencyError type to capture and display a dependency chain when a command fails, enhances the execution context to track command dependencies, wraps execution errors into DependencyError in the dependency runner, updates the main exit handling to respect custom exit codes, and adds comprehensive tests to verify the dependency tree output.

Sequence diagram for error wrapping in dependency execution

sequenceDiagram
    participant Executor
    participant Context
    participant Command
    participant DependencyError
    participant ExecuteError
    Executor->>Context: executeDepends(ctx)
    Context->>Command: Execute(ChildExecutorCtx(ctx, cmd))
    Command-->>Context: error (may be ExecuteError)
    Context->>Executor: error
    Executor->>DependencyError: Wrap error if not DependencyError
    DependencyError-->>Executor: DependencyError instance
    Executor-->>Context: DependencyError
Loading

Class diagram for new DependencyError and updated Context

classDiagram
    class DependencyError {
        +string rootCommand
        +string failedCommand
        +[]string dependencyPath
        +error underlyingErr
        +int exitCode
        +Error() string
        +getUnderlyingErrorMessage() string
        +ExitCode() int
        +Unwrap() error
    }
    class Context {
        +context.Context ctx
        +*config.Command command
        +*logging.ExecLogger logger
        +[]string dependencyPath
    }
Loading

File-Level Changes

Change Details Files
Add DependencyError type for visualizing failed command dependency tree
  • Define DependencyError struct with rootCommand, failedCommand, dependencyPath, underlyingErr, exitCode
  • Implement Error to build a tree-like error message
  • Extract underlying exit status in getUnderlyingErrorMessage
  • Provide ExitCode and Unwrap methods
executor/executor.go
Track dependency path in execution context
  • Extend Context struct with dependencyPath field
  • Initialize dependencyPath in NewExecutorCtx
  • Propagate and append command names in ChildExecutorCtx
executor/executor.go
Wrap child execution errors into DependencyError in executeDepends
  • Detect non-DependencyError errors in executeDepends
  • Extract exit code from ExecuteError or default
  • Return a new DependencyError with full dependency path
executor/executor.go
Respect custom exit codes in main
  • Introduce ExitCoder interface in main.go
  • Check for ExitCode() on errors to set os.Exit code
main.go
Add tests to verify dependency tree error output
  • Enhance command_depends.bats with scenarios for single and multi-level failures
  • Create test_dependency_tree.yaml with shell commands and dependency setups
tests/command_depends.bats
tests/command_depends/lets.yaml
tests/command_depends/test_dependency_tree.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#187 Display a dependency tree in error messages when a command fails within a dependency chain, clearly showing which specific command in the chain failed.
#187 Update or add tests to verify that the new dependency tree error messages are shown correctly for various dependency failure scenarios.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kindermax - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `executor/executor.go:72` </location>
<code_context>
+	return builder.String()
+}
+
+func (e *DependencyError) getUnderlyingErrorMessage() string {
+	if e.underlyingErr == nil {
+		return fmt.Sprintf("exit status %d", e.exitCode)
</code_context>

<issue_to_address>
Parsing error messages by string content is brittle.

Checking for 'exit status' and splitting by ': ' assumes a fixed error format, which may change. Use a more reliable extraction method or document the expected format.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

return builder.String()
}

func (e *DependencyError) getUnderlyingErrorMessage() string {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Parsing error messages by string content is brittle.

Checking for 'exit status' and splitting by ': ' assumes a fixed error format, which may change. Use a more reliable extraction method or document the expected format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show depends tree for failed command

3 participants