-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Return not found error if setting config #2027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+147
−49
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3f8aad8
fix: return not found error if setting config
spacez320 7f37f34
style: gofumpt
spacez320 00c48eb
refactor: segregate errors, config file not found interface
spacez320 5ec9e04
style: clean-up
spacez320 b3382e1
refactor: apply suggestions from code review
spacez320 97b9da7
refactor: better naming, return original error for finder
spacez320 3dd8fe3
docs: add explanation on read in config errors
spacez320 77db77a
style: clean-up
spacez320 95f1e39
style: better test name
spacez320 906777c
docs: better file not found example, remove file not found interface
spacez320 1e717eb
style: apply suggestions from code review
spacez320 caf33e2
refactor: redundant fields for file search error, interface, syscall opt
spacez320 823128e
style: variable naming, readme conforming
spacez320 e956e2f
fix: wrap file not found error
spacez320 a38b309
style: clean-up
spacez320 66a6831
style: better naming
spacez320 b33c39c
refactor: apply review comments
sagikazarmark 1a90a66
refactor: clean-ups
spacez320 b24b2a7
docs: update comment on deprecated error
sagikazarmark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,93 @@ | ||
| package viper | ||
|
|
||
| import ( | ||
| "fmt" | ||
| ) | ||
|
|
||
| // FileLookupError is returned when Viper cannot resolve a configuration file. | ||
| // | ||
| // This is meant to be a common interface for all file look-up errors, occurring either because a | ||
| // file does not exist or because it cannot find any file matching finder criteria. | ||
| type FileLookupError interface { | ||
| error | ||
|
|
||
| fileLookup() | ||
| } | ||
|
|
||
| // ConfigFileNotFoundError denotes failing to find a configuration file from a search. | ||
| // | ||
| // Deprecated: This is error wraps [FileNotFoundFromSearchError], which should be used instead. | ||
| type ConfigFileNotFoundError struct { | ||
| locations []string | ||
| name string | ||
| } | ||
|
|
||
| // Error returns the formatted error. | ||
| func (e ConfigFileNotFoundError) Error() string { | ||
| return e.Unwrap().Error() | ||
| } | ||
|
|
||
| // Unwraps to FileNotFoundFromSearchError. | ||
| func (e ConfigFileNotFoundError) Unwrap() error { | ||
| return FileNotFoundFromSearchError(e) | ||
| } | ||
|
|
||
| // FileNotFoundFromSearchError denotes failing to find a configuration file from a search. | ||
| // Wraps ConfigFileNotFoundError. | ||
| type FileNotFoundFromSearchError struct { | ||
| locations []string | ||
| name string | ||
| } | ||
|
|
||
| func (e FileNotFoundFromSearchError) fileLookup() {} | ||
|
|
||
| // Error returns the formatted error. | ||
| func (e FileNotFoundFromSearchError) Error() string { | ||
| message := fmt.Sprintf("File %q not found", e.name) | ||
|
|
||
| if len(e.locations) > 0 { | ||
| message += fmt.Sprintf(" in %v", e.locations) | ||
| } | ||
|
|
||
| return message | ||
| } | ||
|
|
||
| // FileNotFoundError denotes failing to find a specific configuration file. | ||
| type FileNotFoundError struct { | ||
| err error | ||
| path string | ||
| } | ||
|
|
||
| func (e FileNotFoundError) fileLookup() {} | ||
|
|
||
| // Error returns the formatted error. | ||
| func (e FileNotFoundError) Error() string { | ||
| return fmt.Sprintf("file not found: %s", e.path) | ||
| } | ||
|
|
||
| // ConfigFileAlreadyExistsError denotes failure to write new configuration file. | ||
| type ConfigFileAlreadyExistsError string | ||
|
|
||
| // Error returns the formatted error when configuration already exists. | ||
| func (e ConfigFileAlreadyExistsError) Error() string { | ||
| return fmt.Sprintf("Config File %q Already Exists", string(e)) | ||
| } | ||
|
|
||
| // ConfigMarshalError happens when failing to marshal the configuration. | ||
| type ConfigMarshalError struct { | ||
| err error | ||
| } | ||
|
|
||
| // Error returns the formatted configuration error. | ||
| func (e ConfigMarshalError) Error() string { | ||
| return fmt.Sprintf("While marshaling config: %s", e.err.Error()) | ||
| } | ||
|
|
||
| // UnsupportedConfigError denotes encountering an unsupported | ||
| // configuration filetype. | ||
| type UnsupportedConfigError string | ||
|
|
||
| // Error returns the formatted configuration error. | ||
| func (str UnsupportedConfigError) Error() string { | ||
| return fmt.Sprintf("Unsupported Config Type %q", string(str)) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.