This package includes functions for creating a standardized error message. The messages are in the formatted into a string that looks like: scope-name:message|arguments
. The message may also be divided into segments using the ':
' character. Using multiple segments will allow error messages to have more context. For example, the message scope:component:message
can be divided into 'scope
', 'component
', 'message
'.
-
createScope( name: string, configuration: ScopeConfiguration ): ErrorScope
- name: string - The scope name. The name will appear before each message.
- configuration: ScopeConfiguration - See Scope Configuration
The ErrorScope provides these functions:
-
createErrorMessage( message: string, ...args: unknown[] ): ErrorScope
- Creates an error message and appends the arguments.
- Parameters
- message: string - The message.
- arg: unknown - A value to include with the message.
-
parseErrorMessage( message: string ): [ string[], string[] | undefined ]
- Parses an error message.
- Parameters
- message: string - The message.
- The return value is an array with the first value being an array of message segments and the second value being an array of arguments.
-
argumentDelimiter: string - The delimiter used to separate the error message arguments. Default is '
|
'. -
messageDelimiter: string - The delimiter used to separate the error message segments. Default is '
:
'.