Support Center & Knowledge base

Reason

A reason represents the actual reason for failing in a rule. The reason should be uniquely identifiable, for instance through a GUID as the identifier.

The reason can then be used to create a specific instance called a cause, which holds more information about the actual cause of a failure.

import { Reason } from '@dolittle/rules';

static Reason ValueIsNotFortyTwo = Reason.create('4b99af88-09c0-4342-8876-24c42a48d728', 'Value should be forty two');

On the reason there are two ways to create a cause instance, one without any arguments and one with arguments.

Without arguments you simply do:

const cause = ValueIsNotFortyTwo.noArguments();

If you want to leverage arguments, which also gets interpolated in any strings in the reason:

import { Reason } from '@dolittle/rules';

static Reason ValueIsNotFortyTwo = Reason.create('4b99af88-09c0-4342-8876-24c42a48d728', 'Value '{value}' should be forty two');

const cause = ValueIsNotFortyTwo.withArguments({ value: 43 });