-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
133 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package configcat | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ErrKeyNotFound is returned when a key is not found in the configuration. | ||
type ErrKeyNotFound struct { | ||
Key string | ||
AvailableKeys []string | ||
} | ||
|
||
func (e ErrKeyNotFound) Error() string { | ||
var availableKeys = "" | ||
if len(e.AvailableKeys) > 0 { | ||
availableKeys = "'" + strings.Join(e.AvailableKeys, "', '") + "'" | ||
} | ||
return fmt.Sprintf( | ||
"failed to evaluate setting '%s' (the key was not found in config JSON); available keys: [%s]", | ||
e.Key, | ||
availableKeys, | ||
) | ||
} | ||
|
||
// ErrSettingTypeMismatch is returned when a requested setting type doesn't match with the expected type. | ||
type ErrSettingTypeMismatch struct { | ||
Key string | ||
Value interface{} | ||
ExpectedType string | ||
} | ||
|
||
func (e ErrSettingTypeMismatch) Error() string { | ||
return fmt.Sprintf( | ||
"the type of the setting '%s' doesn't match with the expected type; setting's type was '%t' but the expected type was '%s'", | ||
e.Key, | ||
e.Value, | ||
e.ExpectedType, | ||
) | ||
} | ||
|
||
// ErrConfigJsonMissing is returned when the config JSON is empty or missing. | ||
type ErrConfigJsonMissing struct { | ||
Key string | ||
} | ||
|
||
func (e ErrConfigJsonMissing) Error() string { | ||
return fmt.Sprintf( | ||
"config JSON is not present when evaluating setting '%s'; returning the `defaultValue` parameter that you specified in your application", | ||
e.Key, | ||
) | ||
} |
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