mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-12-08 00:55:37 +00:00
Return typed error when Mount Fails
Mount can fail for a variety of reasons and caller might want to know why mount failed. Using untyped string based error does not provide enough granularity to make that verification.
This commit is contained in:
committed by
Srini Brahmaroutu
parent
0e8dbc2c1e
commit
51e2ee9753
31
mount.go
31
mount.go
@@ -20,6 +20,7 @@ limitations under the License.
|
||||
package mount
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -76,6 +77,36 @@ type MountPoint struct {
|
||||
Pass int
|
||||
}
|
||||
|
||||
type MountErrorType string
|
||||
|
||||
const (
|
||||
FilesystemMismatch MountErrorType = "FilesystemMismatch"
|
||||
HasFilesystemErrors MountErrorType = "HasFilesystemErrors"
|
||||
UnformattedReadOnly MountErrorType = "UnformattedReadOnly"
|
||||
FormatFailed MountErrorType = "FormatFailed"
|
||||
)
|
||||
|
||||
type MountError struct {
|
||||
Type MountErrorType
|
||||
Message string
|
||||
}
|
||||
|
||||
func (mountError *MountError) String() string {
|
||||
return mountError.Message
|
||||
}
|
||||
|
||||
func (mountError *MountError) Error() string {
|
||||
return mountError.Message
|
||||
}
|
||||
|
||||
func NewMountError(mountErrorValue MountErrorType, format string, args ...interface{}) error {
|
||||
mountError := &MountError{
|
||||
Type: mountErrorValue,
|
||||
Message: fmt.Sprintf(format, args...),
|
||||
}
|
||||
return mountError
|
||||
}
|
||||
|
||||
// SafeFormatAndMount probes a device to see if it is formatted.
|
||||
// Namely it checks to see if a file system is present. If so it
|
||||
// mounts it otherwise the device is formatted first then mounted.
|
||||
|
||||
Reference in New Issue
Block a user