cuelang.org/go@v0.10.1/mod/module/error.go (about) 1 package module 2 3 import ( 4 "fmt" 5 ) 6 7 // A ModuleError indicates an error specific to a module. 8 type ModuleError struct { 9 Path string 10 Version string 11 Err error 12 } 13 14 func (e *ModuleError) Error() string { 15 if v, ok := e.Err.(*InvalidVersionError); ok { 16 return fmt.Sprintf("%s@%s: invalid version: %v", e.Path, v.Version, v.Err) 17 } 18 if e.Version != "" { 19 return fmt.Sprintf("%s@%s: %v", e.Path, e.Version, e.Err) 20 } 21 return fmt.Sprintf("module %s: %v", e.Path, e.Err) 22 } 23 24 func (e *ModuleError) Unwrap() error { return e.Err } 25 26 // An InvalidVersionError indicates an error specific to a version, with the 27 // module path unknown or specified externally. 28 // 29 // A ModuleError may wrap an InvalidVersionError, but an InvalidVersionError 30 // must not wrap a ModuleError. 31 type InvalidVersionError struct { 32 Version string 33 Err error 34 } 35 36 func (e *InvalidVersionError) Error() string { 37 return fmt.Sprintf("version %q invalid: %s", e.Version, e.Err) 38 } 39 40 func (e *InvalidVersionError) Unwrap() error { return e.Err } 41 42 // An InvalidPathError indicates a module, import, or file path doesn't 43 // satisfy all naming constraints. See CheckPath, CheckImportPath, 44 // and CheckFilePath for specific restrictions. 45 type InvalidPathError struct { 46 Kind string // "module", "import", or "file" 47 Path string 48 Err error 49 } 50 51 func (e *InvalidPathError) Error() string { 52 return fmt.Sprintf("malformed %s path %q: %v", e.Kind, e.Path, e.Err) 53 } 54 55 func (e *InvalidPathError) Unwrap() error { return e.Err }