You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if some methods would throw ArgumentNullException when the parameter is null. Some methods expect other methods to throw ArgumentNullException but the disadvantage of this is that it is not clear why the error occurred.
For example:
new EnvLoader().SetDefaultEnvFileName(Environment.GetEnvironmentVariable("DEFAULT")).Load();
Output:
Unhandledexception. System.ArgumentNullException: Value cannot be null.(Parameter 'path1')
at System.IO.Path.Combine(String path1, String path2)
at DotEnv.Core.EnvLoader.SetConfigurationEnvFile(EnvFile envFile)in C:\Users\syslan\Documents\Visual Studio 2022\DotEnv.Core\src\Loader\EnvLoader.HelperMethods.cs:line 64
at DotEnv.Core.EnvLoader.Load(EnvValidationResult&result)in C:\Users\syslan\Documents\Visual Studio 2022\DotEnv.Core\src\Loader\EnvLoader.cs:line 59
at DotEnv.Core.EnvLoader.Load()in C:\Users\syslan\Documents\Visual Studio 2022\DotEnv.Core\src\Loader\EnvLoader.cs:line 49
at DotEnv.Core.Example.Program.Main(String[]args) in C:\Users\syslan\Documents\Visual Studio 2022\DotEnv.Core\example\Program.cs:line 55
According to this output, the parameter Path1 is the one that caused the exception but this information is confusing for the consumer because it does not really tell us the cause of the error. If we guess the error it is because a null value is being passed to the SetDefaultEnvFileName method but this information is not told in the exception message, so it is confusing.
This message would be clearer to the consumer:
Unhandledexception. System.ArgumentNullException: Value cannot be null.(Parameter 'envFileName')
at DotEnv.Core.EnvLoader.SetDefaultEnvFileName(String envFileName)in C:\Users\syslan\Documents\Visual Studio 2022\DotEnv.Core\src\Loader\EnvLoader.cs:line 49
at DotEnv.Core.Example.Program.Main(String[]args) in C:\Users\syslan\Documents\Visual Studio 2022\DotEnv.Core\example\Program.cs:line 55
It is clear that the above message is much more explicit for the consumer because it tells us why the error occurred and it was because the null value was passed to the SetDefaultEnvFileName method.
I will create a PR for this.
The text was updated successfully, but these errors were encountered:
It would be nice if some methods would throw ArgumentNullException when the parameter is
null
. Some methods expect other methods to throw ArgumentNullException but the disadvantage of this is that it is not clear why the error occurred.For example:
Output:
According to this output, the parameter Path1 is the one that caused the exception but this information is confusing for the consumer because it does not really tell us the cause of the error. If we guess the error it is because a null value is being passed to the SetDefaultEnvFileName method but this information is not told in the exception message, so it is confusing.
This message would be clearer to the consumer:
It is clear that the above message is much more explicit for the consumer because it tells us why the error occurred and it was because the null value was passed to the SetDefaultEnvFileName method.
I will create a PR for this.
The text was updated successfully, but these errors were encountered: