Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli/command/stack/swarm: waitOnServices remove redundant check for multi-error #5780

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

thaJeztah
Copy link
Member

This check was redundant, because errors.Join already checks if the
list of errors is either empty, or only contains nil errors, as can
be seen in this example;

package main

import (
    "errors"
    "testing"
)

func TestMultiErr(t *testing.T) {
    var errs []error
    if err := errors.Join(errs...); err != nil {
        t.Fatal(err)
    }

    errs = append(errs, nil, nil, nil)
    t.Logf("errs contains %d elements", len(errs))
    if err := errors.Join(errs...); err != nil {
        t.Fatal(err)
    }

    errs = append(errs, errors.New("with an error"))
    if err := errors.Join(errs...); err == nil {
        t.Fatal("expected an error")
    }
}

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Feb 1, 2025
@thaJeztah thaJeztah added this to the 28.0.0 milestone Feb 1, 2025
@thaJeztah thaJeztah requested a review from vvoland February 1, 2025 11:44
@thaJeztah thaJeztah self-assigned this Feb 1, 2025
@thaJeztah thaJeztah requested review from silvin-lubecki and a team as code owners February 1, 2025 11:45
@codecov-commenter
Copy link

codecov-commenter commented Feb 1, 2025

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Project coverage is 59.42%. Comparing base (d68c4d8) to head (dea59ea).
Report is 2 commits behind head on master.

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5780   +/-   ##
=======================================
  Coverage   59.42%   59.42%           
=======================================
  Files         347      347           
  Lines       29398    29395    -3     
=======================================
  Hits        17469    17469           
+ Misses      10957    10954    -3     
  Partials      972      972           

…lti-error

This check was redundant, because `errors.Join` already checks if the
list of errors is either empty, or only contains `nil` errors, as can
be seen in [this example][1];

    package main

    import (
        "errors"
        "testing"
    )

    func TestMultiErr(t *testing.T) {
        var errs []error
        if err := errors.Join(errs...); err != nil {
            t.Fatal(err)
        }

        errs = append(errs, nil, nil, nil)
        t.Logf("errs contains %d elements", len(errs))
        if err := errors.Join(errs...); err != nil {
            t.Fatal(err)
        }

        errs = append(errs, errors.New("with an error"))
        if err := errors.Join(errs...); err == nil {
            t.Fatal("expected an error")
        }
    }

[1]: https://go.dev/play/p/iSuGP81eght

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@vvoland vvoland merged commit 4771aba into docker:master Feb 3, 2025
89 checks passed
@thaJeztah thaJeztah deleted the multierr_simplify branch February 3, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/refactor PR's that refactor, or clean-up code status/2-code-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants