Skip to content

fix non-constant format string (caught by go1.24)#49201

Merged
thaJeztah merged 3 commits intomoby:masterfrom
thaJeztah:non_const_formatting
Jan 2, 2025
Merged

fix non-constant format string (caught by go1.24)#49201
thaJeztah merged 3 commits intomoby:masterfrom
thaJeztah:non_const_formatting

Conversation

@thaJeztah
Copy link
Member

Not exactly sure why our linters didn't spot this, as it did for Linux; #48359 - perhaps we're missing some GOOS=windows in our linter?

Ultimately we should also remove these libnetwork-specific errors, and just use errdefs probably.

distribution: fix non-constant format string

caught by go1.24

# github.com/docker/docker/distribution
# github.com/docker/docker/distribution/pull_v2_windows.go:145:35: non-constant format string in call to (*github.com/docker/docker/vendor/github.com/sirupsen/logrus.Entry).Debugf
FAIL    github.com/docker/docker/distribution [build failed]

libnetwork/drivers/windows: fix non-constant format string

Also updated some existing ones to use %v instead of %s for consistency.

caught by go1.24

# github.com/docker/docker/libnetwork/drivers/windows/overlay
# github.com/docker/docker/libnetwork/drivers/windows/overlay/ov_network_windows.go:206:32: non-constant format string in call to github.com/docker/docker/libnetwork/types.ForbiddenErrorf
FAIL    github.com/docker/docker/libnetwork/drivers/windows/overlay [build failed]

# github.com/docker/docker/libnetwork/drivers/windows
# github.com/docker/docker/libnetwork/drivers/windows/windows.go:449:33: non-constant format string in call to github.com/docker/docker/libnetwork/types.ForbiddenErrorf
FAIL    github.com/docker/docker/libnetwork/drivers/windows [build failed]

- What I did

- How I did it

- How to verify it

- Description for the changelog

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

caught by go1.24

    # github.com/docker/docker/distribution
    # github.com/docker/docker/distribution/pull_v2_windows.go:145:35: non-constant format string in call to (*github.com/docker/docker/vendor/github.com/sirupsen/logrus.Entry).Debugf
    FAIL    github.com/docker/docker/distribution [build failed]

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Also updated some existing ones to use `%v` instead of `%s` for consistency.

caught by go1.24

    # github.com/docker/docker/libnetwork/drivers/windows/overlay
    # github.com/docker/docker/libnetwork/drivers/windows/overlay/ov_network_windows.go:206:32: non-constant format string in call to github.com/docker/docker/libnetwork/types.ForbiddenErrorf
    FAIL    github.com/docker/docker/libnetwork/drivers/windows/overlay [build failed]

    # github.com/docker/docker/libnetwork/drivers/windows
    # github.com/docker/docker/libnetwork/drivers/windows/windows.go:449:33: non-constant format string in call to github.com/docker/docker/libnetwork/types.ForbiddenErrorf
    FAIL    github.com/docker/docker/libnetwork/drivers/windows [build failed]

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@@ -446,7 +446,7 @@ func (d *driver) DeleteNetwork(nid string) error {
if n.created {
_, err = hcsshim.HNSNetworkRequest("DELETE", config.HnsID, "")
if err != nil && err.Error() != errNotFound {
Copy link
Member Author

Choose a reason for hiding this comment

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

I just noticed this one, string-matching;

errNotFound = "HNS failed with error : The object identifier does not represent a valid object. "

For a second I was afraid I broke that one because I recalled I opened a PR in hcsshim to remove some stray whitespace in error messages;

But I think this one's not changed.

Let me have a look though if there's alternative ways to match the error (other than string matching 😬)

Copy link
Member Author

Choose a reason for hiding this comment

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

The good news; I didn't break things.

The bad news; depending on which implementation we hit, we may be broken;

return fmt.Errorf("hns failed with error : %s", hnsresponse.Error)

return fmt.Errorf("HNS failed with error : %s", hnsresponse.Error)

Looks like the "lowercase" one was changed in microsoft/hcsshim@7ec8848, which is in hcshim v0.12

Interestingly, it looks like we hit that problem 6 years; integration-cli uses strings.ToLower to work around that;

assert.Assert(c, strings.Contains(outLowerCase, "port is already allocated") ||
strings.Contains(outLowerCase, "were not connected because a duplicate name exists") ||
strings.Contains(outLowerCase, "the specified port already exists") ||
strings.Contains(outLowerCase, "hns failed with error : failed to create endpoint") ||
strings.Contains(outLowerCase, "hns failed with error : the object already exists"), fmt.Sprintf("Output: %s", out))

Copy link
Member Author

Choose a reason for hiding this comment

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

OH! I spotted the wrong commit; it's not hcsshim v0.12, but the old one that touched that error; this was the commit microsoft/hcsshim@6d67a30

@thaJeztah thaJeztah merged commit cc4d2b0 into moby:master Jan 2, 2025
163 checks passed
@thaJeztah thaJeztah deleted the non_const_formatting branch January 2, 2025 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants