mirror of https://github.com/k3s-io/k3s
33 lines
827 B
Go
33 lines
827 B
Go
// Copyright 2020 Rancher Labs, Inc. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package generic
|
|
|
|
import (
|
|
"errors"
|
|
"strconv"
|
|
)
|
|
|
|
// errParse is returned by Set if a flag's value fails to parse, such as with an invalid integer for Int.
|
|
// It then gets wrapped through failf to provide more information.
|
|
var errParse = errors.New("parse error")
|
|
|
|
// errRange is returned by Set if a flag's value is out of range.
|
|
// It then gets wrapped through failf to provide more information.
|
|
var errRange = errors.New("value out of range")
|
|
|
|
func numError(err error) error {
|
|
ne, ok := err.(*strconv.NumError)
|
|
if !ok {
|
|
return err
|
|
}
|
|
if ne.Err == strconv.ErrSyntax {
|
|
return errParse
|
|
}
|
|
if ne.Err == strconv.ErrRange {
|
|
return errRange
|
|
}
|
|
return err
|
|
}
|