function createError(messages, errCode, meta) {
    // The error value may be "undefined", so check if the argument was provided
    const hasValue = meta && 'value' in meta;
    // Throw a custom error type with the code attached
    const err = new Error(
        `${messages[errCode] || UNKNOWN_ERROR_MSG} (code: ${errCode}${
            hasValue ? `, value: ${meta.value}` : ''
        })`
    );
    // @ts-expect-error - TS doesn't like extending Error
    err.code = errCode;
    return err;
}
Create an error with an attached code
@private
@param {Record<number, string>} messages  Map of code-to-messages to use
@param {number} errCode                   Numeric error code
@param {{value: unknown} | {}} [meta]     Metadata with value to associate with the error