Skip to content
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

refactor: Remove the “Try/Catch” block found in the EnvLoader type #163

Merged
merged 2 commits into from
Jun 10, 2024

Conversation

MrDave1999
Copy link
Owner

@MrDave1999 MrDave1999 commented Jun 10, 2024

The purpose of PR is to remove this Try/Catch block:

try
{
_parser.Parse(source);
}
catch (ParserException) { }

This Try/Catch block is bad for two reasons:

  • The real exception thrown is being hidden and absolutely nothing is done when the exception is caught.
    This only affects the readability of the code. It is not clear what this code does at first glance.
  • It is not efficient. For example, if you read seven .env files and they all have a parse error, it will throw seven exceptions only to be caught and do nothing. This makes no sense, it wastes resources unnecessarily and is slower.

The real reason why this Try/Catch block was added was so as not to interrupt the execution flow of the .env file loader.

@MrDave1999 MrDave1999 changed the title refactor: Remove the “Try/Catch” block found in the EnvLoader type. refactor: Remove the “Try/Catch” block found in the EnvLoader type Jun 10, 2024
@MrDave1999 MrDave1999 merged commit aba7c90 into master Jun 10, 2024
1 check passed
@MrDave1999 MrDave1999 deleted the refactor-6 branch June 10, 2024 17:39
@MrDave1999 MrDave1999 added the refactor Refactoring existing code, to make it more readable, cleaner or more efficient label Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactoring existing code, to make it more readable, cleaner or more efficient
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant