This PR adds an error code for every error/warning emitted by the translator.
New error codes should be added to parse-log.ts in the MessageParameterTypes type, with either 'the-error-code': string or 'the-error-code': { value: number, ...otherProperties }.
Errors can be logged like:
someMalloyElement.logError(
'the-error-code',
`Oh no, you messed up! ${someValue} is illegal`
);
This PR adds an error code for every error/warning emitted by the translator.
New error codes should be added to
parse-log.ts
in theMessageParameterTypes
type, with either'the-error-code': string
or'the-error-code': { value: number, ...otherProperties }
.Errors can be logged like:
or
A third argument may be passed, which is an object that can have:
replacement
: suggested text to replace the erroring codeat
: an override for the location of the errortag
: an error tag to attach to the error, which should correspond to a tag in the documentationlogWarning
also exists for logging warnings...If using the latter style, be sure to add a message formatter into
parse-log.ts
in theMESSAGE_FORMATTERS
object:The error formatter can return a plain string message, or an object that can have:
tag
replacement
data
: data to attach to the error; if not specified, the error parameters will be used for this valueThere was also a pattern of doing:
This now becomes:
Testing for log messages has changed from
to
If you want to check that the properties of the error are set correctly, you can do
If you explicitly want to check that the message is formatted correctly, do