Commit Graph

6 Commits

Author SHA1 Message Date
Sebastiaan van Stijn 4c882e0f6c
opts: use stdlib errors and touch-up some errors
- remove uses of github.com/pkg/errors
- slight improvement on handling parsing errors
- add some test-cases

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-03-08 18:15:51 +01:00
Sebastiaan van Stijn da4b6275ba
explicitly handle errors when wrapping them
The errors.Wrap and errors.Wrapf functions gracefully handle nil-errors.
This allows them to be used unconditionally regardless if an error
was produced.

While this can be convenient, it can also be err-prone, as replacing
these with stdlib errors means they unconditionally produce an error.

This patch replaces code uses of errors.Wrap to be gated by a check
for nil-errors to future-proof our code.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-20 18:10:36 +01:00
Sebastiaan van Stijn f79193c22c
opts: fix "unused-receiver", line-length-limit linting
opts/port.go:124:7: unused-receiver: method receiver 'p' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (p *PortOpt) Type() string {
          ^
    opts/mount.go:218:7: unused-receiver: method receiver 'm' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (m *MountOpt) Type() string {
          ^
    opts/quotedstring.go:16:7: unused-receiver: method receiver 's' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (s *QuotedString) Type() string {
          ^
    opts/secret.go:82:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (o *SecretOpt) Type() string {
          ^
    opts/opts_test.go:235: line-length-limit: line is 283 characters, out of limit 200 (revive)
            `foo.bar.baz.this.should.fail.on.long.name.because.it.is.longer.thanisshouldbethis.should.fail.on.long.name.because.it.is.longer.thanisshouldbethis.should.fail.on.long.name.because.it.is.longer.thanisshouldbethis.should.fail.on.long.name.because.it.is.longer.thanisshouldbe`,
    opts/ulimit.go:61:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (o *UlimitOpt) Type() string {
          ^
    opts/weightdevice.go:82:7: unused-receiver: method receiver 'opt' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (opt *WeightdeviceOpt) Type() string {
          ^
    opts/throttledevice.go:103:7: unused-receiver: method receiver 'opt' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (opt *ThrottledeviceOpt) Type() string {
          ^
    opts/duration.go:49:7: unused-receiver: method receiver 'd' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (d *DurationOpt) Type() string {
          ^
    opts/network.go:109:7: unused-receiver: method receiver 'n' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (n *NetworkOpt) Type() string {
          ^
    opts/network.go:119:7: unused-receiver: method receiver 'n' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (n *NetworkOpt) String() string {
          ^
    opts/opts.go:113:7: unused-receiver: method receiver 'opts' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (opts *ListOpts) Type() string {
          ^
    opts/pull_behavior.go:13:7: unused-receiver: method receiver 'p' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (p *PullOpt) Type() string {
          ^
    opts/config.go:83:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (o *ConfigOpt) Type() string {
          ^
    opts/gpus.go:95:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (o *GpuOpts) Type() string {
          ^
    opts/pull_behavior.go:23:7: unused-receiver: method receiver 'p' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (p *PullOpt) IsBoolFlag() bool {
          ^
    opts/opts.go:183:7: unused-receiver: method receiver 'opts' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (opts *MapOpts) Type() string {
          ^
    opts/opts.go:361:7: unused-receiver: method receiver 'o' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (o *FilterOpt) Type() string {
          ^
    opts/opts.go:389:7: unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (c *NanoCPUs) Type() string {
          ^
    opts/opts.go:466:7: unused-receiver: method receiver 'm' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (m *MemBytes) Type() string {
          ^
    opts/opts.go:501:7: unused-receiver: method receiver 'm' is not referenced in method's body, consider removing or renaming it as _ (revive)
    func (m *MemSwapBytes) Type() string {
          ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-17 15:24:53 +01:00
Sebastiaan van Stijn 6c39bc1f60
opts: use strings.Cut for handling key/value pairs
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-12-29 15:14:15 +01:00
Sebastiaan van Stijn 82427d1a07
format (GoDoc) comments with Go 1.19 to prepare for go updates
Older versions of Go do not format these comments, so we can already
reformat them ahead of time to prevent gofmt linting failing once
we update to Go 1.19 or up.

Result of:

    gofmt -s -w $(find . -type f -name '*.go' | grep -v "/vendor/")

With some manual adjusting.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-07-19 19:10:16 +02:00
Tibor Vass 1ba368a5ac container: --gpus support
Signed-off-by: Tibor Vass <tibor@docker.com>
2019-03-21 20:14:25 +00:00