-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
future-proof validateImageParts. Add custom error types.
\nSigned-off-by: davis-haba <davishaba@google.com>
- Loading branch information
1 parent
5ae8fe1
commit 3ceb9a1
Showing
5 changed files
with
160 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package assignimage | ||
|
||
import "fmt" | ||
|
||
type baseError struct { | ||
s string | ||
} | ||
|
||
func (e baseError) Error() string { | ||
return e.s | ||
} | ||
|
||
// Component field (domain|path|tag) errors. | ||
type invalidDomainError struct{ baseError } | ||
|
||
type ( | ||
invalidPathError struct{ baseError } | ||
invalidTagError struct{ baseError } | ||
missingComponentsError struct{ baseError } | ||
domainLikePathError struct{ baseError } | ||
) | ||
|
||
// Location field errors. | ||
type listTerminalError struct{ baseError } | ||
type metadataRootError struct{ baseError } | ||
|
||
func newInvalidDomainError(domain string) invalidDomainError { | ||
return invalidDomainError{ | ||
baseError{ | ||
fmt.Sprintf("assignDomain %q does not match pattern %s", domain, domainRegexp.String()), | ||
}, | ||
} | ||
} | ||
|
||
func newInvalidPathError(path string) invalidPathError { | ||
return invalidPathError{ | ||
baseError{ | ||
fmt.Sprintf("assignPath %q does not match pattern %s", path, pathRegexp.String()), | ||
}, | ||
} | ||
} | ||
|
||
func newInvalidTagError(tag string) invalidTagError { | ||
return invalidTagError{ | ||
baseError{ | ||
fmt.Sprintf("assignTag %q does not match pattern %s", tag, tagRegexp.String()), | ||
}, | ||
} | ||
} | ||
|
||
func newMissingComponentsError() missingComponentsError { | ||
return missingComponentsError{ | ||
baseError{ | ||
"at least one of [assignDomain, assignPath, assignTag] must be set", | ||
}, | ||
} | ||
} | ||
|
||
func newDomainLikePathError(path string) domainLikePathError { | ||
return domainLikePathError{ | ||
baseError{ | ||
fmt.Sprintf("assignDomain must be set if the first part of assignPath %q can be interpretted as part of a domain", path), | ||
}, | ||
} | ||
} | ||
|
||
func newListTerminalError(name string) listTerminalError { | ||
return listTerminalError{ | ||
baseError{ | ||
fmt.Sprintf("assignImage %s cannot mutate list-type fields", name), | ||
}, | ||
} | ||
} | ||
|
||
func newMetadataRootError(name string) metadataRootError { | ||
return metadataRootError{ | ||
baseError{ | ||
fmt.Sprintf("assignImage %s can't change metadata", name), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters