Commit 9949be66 authored by Steven Allen's avatar Steven Allen

fix: panic on invalid priority/flag values

parent 7fbc0dff
...@@ -56,6 +56,8 @@ const ( ...@@ -56,6 +56,8 @@ const (
) )
// WithDefault resolves the value of the flag given the provided default value. // WithDefault resolves the value of the flag given the provided default value.
//
// Panics if Flag is an invalid value.
func (f Flag) WithDefault(defaultValue bool) bool { func (f Flag) WithDefault(defaultValue bool) bool {
switch f { switch f {
case False: case False:
...@@ -126,17 +128,30 @@ const ( ...@@ -126,17 +128,30 @@ const (
// WithDefault resolves the priority with the given default. // WithDefault resolves the priority with the given default.
// //
// If `defaultPriority` is Default/0, this function will return 0. // If defaultPriority is Default/0, this function will return 0.
//
// Panics if the priority has an invalid value (e.g., not DefaultPriority,
// Disabled, or > 0).
func (p Priority) WithDefault(defaultPriority Priority) (priority int64, enabled bool) { func (p Priority) WithDefault(defaultPriority Priority) (priority int64, enabled bool) {
switch p { switch p {
case Disabled: case Disabled:
return 0, false return 0, false
case DefaultPriority: case DefaultPriority:
if defaultPriority < 0 { switch defaultPriority {
case Disabled:
return 0, false return 0, false
case DefaultPriority:
return 0, true
default:
if defaultPriority <= 0 {
panic(fmt.Sprintf("invalid priority %d < 0", int64(defaultPriority)))
}
return int64(defaultPriority), true
} }
return int64(defaultPriority), true
default: default:
if p <= 0 {
panic(fmt.Sprintf("invalid priority %d < 0", int64(p)))
}
return int64(p), true return int64(p), true
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment