Skip to content

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

Merged
vvoland merged 1 commit intodocker:masterfrom
thaJeztah:multierr_simplify
Feb 3, 2025
Merged

cli/command/stack/swarm: waitOnServices remove redundant check for multi-error#5780
vvoland merged 1 commit intodocker:masterfrom
thaJeztah:multierr_simplify

Conversation

@thaJeztah
Copy link
Copy Markdown
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 a team and silvin-lubecki as code owners February 1, 2025 11:45
@codecov-commenter
Copy link
Copy Markdown

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
@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