Skip to content

Commit

Permalink
refactor: Add generic messages for custom exceptions (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDave1999 authored Jun 10, 2024
1 parent 2effa7f commit d6139e5
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/Binder/BinderException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using static DotEnv.Core.ExceptionMessages;

namespace DotEnv.Core;

Expand All @@ -9,9 +10,9 @@ namespace DotEnv.Core;
public class BinderException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="BinderException" /> class.
/// Initializes a new instance of the <see cref="BinderException" /> class with a default message.
/// </summary>
public BinderException()
public BinderException() : base(BinderDefaultMessage)
{

}
Expand Down
5 changes: 3 additions & 2 deletions src/Parser/ParserException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using static DotEnv.Core.ExceptionMessages;

namespace DotEnv.Core;

Expand All @@ -10,9 +11,9 @@ namespace DotEnv.Core;
public class ParserException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="ParserException" /> class.
/// Initializes a new instance of the <see cref="ParserException" /> class with a default message.
/// </summary>
public ParserException()
public ParserException() : base(ParserDefaultMessage)
{

}
Expand Down
5 changes: 3 additions & 2 deletions src/Reader/VariableNotSetException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using static DotEnv.Core.ExceptionMessages;

namespace DotEnv.Core;

Expand All @@ -10,9 +11,9 @@ namespace DotEnv.Core;
public class VariableNotSetException : ArgumentException
{
/// <summary>
/// Initializes a new instance of the <see cref="VariableNotSetException" /> class.
/// Initializes a new instance of the <see cref="VariableNotSetException" /> class with a default message.
/// </summary>
public VariableNotSetException()
public VariableNotSetException() : base(VariableNotSetDefaultMessage)
{

}
Expand Down
36 changes: 36 additions & 0 deletions src/Resources/ExceptionMessages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion src/Resources/ExceptionMessages.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<data name="ArgumentIsNullOrWhiteSpaceMessage" xml:space="preserve">
<value>El argumento no puede ser una cadena vacía o estar formado sólo por caracteres de espacio en blanco.</value>
</data>
<data name="BinderDefaultMessage" xml:space="preserve">
<value>Se ha producido un error al vincular claves de configuración a un objeto fuertemente tipado.</value>
</data>
<data name="DataSourceIsEmptyOrWhitespaceMessage" xml:space="preserve">
<value>La fuente de datos está vacía o sólo contiene espacios en blanco.</value>
</data>
Expand Down Expand Up @@ -150,9 +153,15 @@
<data name="OptionInvalidMessage" xml:space="preserve">
<value>La opción no es válida.</value>
</data>
<data name="ParserDefaultMessage" xml:space="preserve">
<value>Se ha producido un error al analizar una fuente de datos con pares clave-valor.</value>
</data>
<data name="PropertyDoesNotMatchConfigKeyMessage" xml:space="preserve">
<value>La propiedad '{0}.{1}' no coincide con ninguna clave de configuración.</value>
</data>
<data name="RequiredKeysNotPresentDefaultMessage" xml:space="preserve">
<value>Las claves requeridas no están presentes en la aplicación.</value>
</data>
<data name="RequiredKeysNotPresentMessage" xml:space="preserve">
<value>'{0}' es una clave requerida por la aplicación.</value>
</data>
Expand All @@ -162,7 +171,10 @@
<data name="VariableIsAnEmptyStringMessage" xml:space="preserve">
<value>'{0}' es una expresión de interpolación inválida.</value>
</data>
<data name="VariableNotSetDefaultMessage" xml:space="preserve">
<value>La variable de entorno no está definida.</value>
</data>
<data name="VariableNotSetMessage" xml:space="preserve">
<value>'{0}' no está establecida.</value>
<value>'{0}' no está definida.</value>
</data>
</root>
12 changes: 12 additions & 0 deletions src/Resources/ExceptionMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<data name="ArgumentIsNullOrWhiteSpaceMessage" xml:space="preserve">
<value>The argument cannot be an empty string or consists only of white-space characters.</value>
</data>
<data name="BinderDefaultMessage" xml:space="preserve">
<value>An error occurred when binding configuration keys to a strongly typed object.</value>
</data>
<data name="DataSourceIsEmptyOrWhitespaceMessage" xml:space="preserve">
<value>Data source is empty or consists only in whitespace.</value>
</data>
Expand Down Expand Up @@ -150,9 +153,15 @@
<data name="OptionInvalidMessage" xml:space="preserve">
<value>The option is invalid.</value>
</data>
<data name="ParserDefaultMessage" xml:space="preserve">
<value>An error occurred while parsing a data source with key-value pairs.</value>
</data>
<data name="PropertyDoesNotMatchConfigKeyMessage" xml:space="preserve">
<value>The '{0}.{1}' property does not match any configuration key.</value>
</data>
<data name="RequiredKeysNotPresentDefaultMessage" xml:space="preserve">
<value>The required keys are not present in the application.</value>
</data>
<data name="RequiredKeysNotPresentMessage" xml:space="preserve">
<value>'{0}' is a key required by the application.</value>
</data>
Expand All @@ -162,6 +171,9 @@
<data name="VariableIsAnEmptyStringMessage" xml:space="preserve">
<value>'{0}' is an invalid interpolation expression.</value>
</data>
<data name="VariableNotSetDefaultMessage" xml:space="preserve">
<value>Environment variable is not set.</value>
</data>
<data name="VariableNotSetMessage" xml:space="preserve">
<value>'{0}' is not set.</value>
</data>
Expand Down
5 changes: 3 additions & 2 deletions src/Validator/RequiredKeysNotPresentException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using static DotEnv.Core.ExceptionMessages;

namespace DotEnv.Core;

Expand All @@ -10,9 +11,9 @@ namespace DotEnv.Core;
public class RequiredKeysNotPresentException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="RequiredKeysNotPresentException" /> class.
/// Initializes a new instance of the <see cref="RequiredKeysNotPresentException" /> class with a default message.
/// </summary>
public RequiredKeysNotPresentException()
public RequiredKeysNotPresentException() : base(RequiredKeysNotPresentDefaultMessage)
{

}
Expand Down

0 comments on commit d6139e5

Please sign in to comment.