Skip to content

Fix no error when /config.json doesn't exist #3

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Jager567
Copy link

I rewrote the LoadConfig() function to actually return an error when os.Stat("/config.json") failed.
The previous code declared a new err in the scope of the if statement, but then returned the empty one from the named return values.

When there was an error with the os.Stat call, we would return nil.
This is because a new variable was created instead of the named return value
assigned and returning nil explicitly instead of relying on the named returns.
I think the method looks cleaner when you have less nested code blocks.
This way your brain has to do less thinking, because when no errors occur you
just have to follow the leftmost indented code to see how it works. Only in
unusual situations where errors occur you have to start reading nested code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants