Skip to content

client: explicitly return zero-type on failures in prune functions#48713

Merged
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:client_prune_zerotype
Oct 23, 2024
Merged

client: explicitly return zero-type on failures in prune functions#48713
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:client_prune_zerotype

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

Mostly a "nit", but it makes it clearer that we're returning an empty result, and not a (partially) propagated struct.

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

🙈

Mostly a "nit", but it makes it clearer that we're returning an empty result,
and not a (partially) propagated struct.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Oct 21, 2024
@thaJeztah thaJeztah added this to the 28.0.0 milestone Oct 21, 2024
Comment thread client/image_prune.go
Comment on lines -17 to +15
return report, err
return image.PruneReport{}, err
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Honestly, wish we'd used a pointer for all of these, similar to how we did for build prune; that'd allow us to just return nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just for my learning, would a refactor like that be a breaking change since users are likely building against client here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, that's the tricky bit. Effectively ANY change in signature on an exported function is a breaking change. So if we'd adhere to Go modules and SemVer, then no change whatsoever is allowed baring (e.g.) adding a field to a struct. That sometimes is, a bit limiting; more so because some things exported were done so long time ago, before go modules enforcing SemVer (compatibility was more "through documentation"), and there were no constructs like internal/ or if there were, we at the time opted to "allow" users to use things, but "at your own risk".

So, yes, we sometimes take a somewhat "flexible" approach; e.g. we've moved some types to different packages, but when doing so move the type, add an alias for the old one, which we deprecate for one release, then remove in the next. But as we're not an actual go module (so no /v27, /v28 import paths), technically we're not allowed to do any of that.

For this one, I'm on the fence; yes, it would make a cleaner API, but it's also something that could (subtly) break people, so not 100% sure if we should make the change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That sometimes is, a bit limiting; more so because some things exported were done so long time ago, before go modules enforcing SemVer (compatibility was more "through documentation"), and there were no constructs like internal/ or if there were, we at the time opted to "allow" users to use things, but "at your own risk".

I'm getting a peak into Go development history from before I became a Go dev. (~1.16 😄 )

For this one, I'm on the fence; yes, it would make a cleaner API, but it's also something that could (subtly) break people, so not 100% sure if we should make the change.

Makes sense, IIUC daemon changes are easier to justify as most use cases would not be building against those packages, but client package I assume at least some Go SDK is building against. Thanks, gives me a little more understanding of the considerations here for users. :)

Copy link
Copy Markdown
Contributor

@austinvazquez austinvazquez left a comment

Choose a reason for hiding this comment

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

Makes sense to me! :)

Comment thread client/image_prune.go
Comment on lines -17 to +15
return report, err
return image.PruneReport{}, err
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just for my learning, would a refactor like that be a breaking change since users are likely building against client here?

@thaJeztah thaJeztah self-assigned this Oct 23, 2024
@thaJeztah thaJeztah merged commit 914ed02 into moby:master Oct 23, 2024
@thaJeztah thaJeztah deleted the client_prune_zerotype branch October 23, 2024 13:14
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