Skip to content

runconfig: remove exported errors#50532

Merged
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:runconfig_rm_errors
Jul 28, 2025
Merged

runconfig: remove exported errors#50532
thaJeztah merged 1 commit intomoby:masterfrom
thaJeztah:runconfig_rm_errors

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

These errors were not used as sentinel error, and used as any other "invalid parameter" / "invalid argument" error, so remove them, and just produce errors where used.

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

@thaJeztah thaJeztah added this to the 29.0.0 milestone Jul 27, 2025
@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels Jul 27, 2025
@thaJeztah thaJeztah force-pushed the runconfig_rm_errors branch from 228db4b to 5ea0872 Compare July 27, 2025 17:53
@thaJeztah
Copy link
Copy Markdown
Member Author

Ah, fun one; perhaps I shouldn't use the cerrdefs for now; I think that test sends an empty config on commit, so we may need this PR as well;

=== RUN   TestCommitInheritsEnv
    commit_test.go:30: assertion failed: error is not nil: Error response from daemon: invalid JSON: EOF
--- FAIL: TestCommitInheritsEnv (0.09s)

Comment thread runconfig/errors.go
Comment on lines -3 to -5
const (
// ErrConflictContainerNetworkAndLinks conflict between --net=container and links
ErrConflictContainerNetworkAndLinks validationError = "conflicting options: container type network can't be used with links. This would result in undefined behavior"
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.

nit: Maybe we could still leave these consts and then use them directly in cerrdefs.ErrInvalidArgument.WithMessage(...)?

Also, what's wrong with having validationError?

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.

Ah, right;

nit: Maybe we could still leave these consts and then use them directly in

I was originally considering keeping them as consts, but my main train of thought here was that they are not "special". Un-exporting them would be an option, but from this file (and some other places I've seen), it quickly led to "to return an error, it must be defined first!"), sometimes after that resulting in exporting those errors, and now it all becomes tightly coupled and a "contract".

I'm not "sold" on all of these errors, so putting them inline makes it more clear "just an error message; not a contract; change if needed".

Also, what's wrong with having validationError?

That's a good one, and I went back-and-forth a bit; I initially kept the type, then considered making it a function that wraps the containerd types;

func validationError(msg string) error {
    return cerrdefs.ErrInvalidArgument.WithMessage(msg)
}

But then thought; maybe we just need to get used to using cerrdefs, so perhaps better to remove that helper; I'd be fine putting that one back though if that was what you meant.

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.

Yeah 100% on unexporting them! The only thing that I like about the current approach is that there is a centralized place for them to look at. But then as you've said:

putting them inline makes it more clear "just an error message; not a contract; change if needed".

so I'm okay with your 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.

func validationError(msg string) error {
    return cerrdefs.ErrInvalidArgument.WithMessage(msg)
}

Yep that helper would avoid a lot of unneeded repetition and also makes it really easy to see that all of these are InvalidArgument.
OTOH, when writing new code here, one would probably forget about this helper anyway, and would lead to inconsistent usage later, so maybe indeed it's better to just use the cerrdefs directly..

Comment thread runconfig/errors.go
Comment on lines -3 to -5
const (
// ErrConflictContainerNetworkAndLinks conflict between --net=container and links
ErrConflictContainerNetworkAndLinks validationError = "conflicting options: container type network can't be used with links. This would result in undefined behavior"
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.

Yeah 100% on unexporting them! The only thing that I like about the current approach is that there is a centralized place for them to look at. But then as you've said:

putting them inline makes it more clear "just an error message; not a contract; change if needed".

so I'm okay with your change 👍🏻

Comment thread runconfig/errors.go
Comment on lines -3 to -5
const (
// ErrConflictContainerNetworkAndLinks conflict between --net=container and links
ErrConflictContainerNetworkAndLinks validationError = "conflicting options: container type network can't be used with links. This would result in undefined behavior"
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.

func validationError(msg string) error {
    return cerrdefs.ErrInvalidArgument.WithMessage(msg)
}

Yep that helper would avoid a lot of unneeded repetition and also makes it really easy to see that all of these are InvalidArgument.
OTOH, when writing new code here, one would probably forget about this helper anyway, and would lead to inconsistent usage later, so maybe indeed it's better to just use the cerrdefs directly..

@thaJeztah
Copy link
Copy Markdown
Member Author

Yep that helper would avoid a lot of unneeded repetition and also makes it really easy to see that all of these are InvalidArgument.

OK, you convinced me (I was going back and forth) and yes, it's probably cleaner.

I see this one needs a rebase, so let me add that utility 😄

These errors were not used as sentinel error, and used as any other
"invalid parameter" / "invalid argument" error, so remove them, and
just produce errors where used.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the runconfig_rm_errors branch from 94a663a to 26fda34 Compare July 28, 2025 09:46
@thaJeztah thaJeztah merged commit a362ae9 into moby:master Jul 28, 2025
249 of 250 checks passed
@thaJeztah thaJeztah deleted the runconfig_rm_errors branch July 28, 2025 10:46
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

Development

Successfully merging this pull request may close these issues.

2 participants