Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Issues #41 Add errors when assert operators. #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vonglasow
Copy link
Member

When operators are evaluated, we can found some asserter false. This
patch add a management of errors in the asserter. Operators name and
value is added in errors stack to identify which operator fail.

Two methods are available to identify if we have errors and to get there
errors:

@@ -159,6 +166,10 @@ protected function visitOperator ( Ruler\Model\Operator $element, &$handle = nul
$value = $argument->accept($this, $handle, $eldnah);
$arguments[] = $value;

// Add operators name and their values in errors lists
if (false === $value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why false means a failed computation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the first assumption, generally when something is false, this come from an error. But you're right sometimes we want to have false as a correct value. This is also the reason why the operator not exist. I see this in two way first is to found if this operator is used (not operator) and invert the condition. But sometimes the value which should be used to raise an error could be other than "false". So the second way should be to add the false value in operator to identify from which value you can add an error for this operator.

What do you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about letting the operator to register an error somewhere instead?

$asserter->setOperator(
    'in',
    function ( ) use ($asserter) {
        // …
        $asserter->addError(…);
        return …;
    }
);

@Hywan
Copy link
Member

Hywan commented Apr 7, 2015

How do you reset the list of errors from one execution to another?

@Hywan Hywan self-assigned this Apr 7, 2015
@vonglasow
Copy link
Member Author

It's not possible for now to reset this list of errors from one execution to another. I will add it.

Thanks for your feedback

When operators are evaluated, we can found some asserter false. This
patch add a management of errors in the asserter. Operators name and
value is added in errors stack to identify which operator fail.

Two methods are available to identify if we have errors and to get there
errors:
* hasErrors return a boolean which identify if some errors have been
raised.
* getErrors return an array with operator name as key and arguments as
values.
* resetErrors clean all errors stored.
@vonglasow
Copy link
Member Author

Add resetErrors method!

@Hywan
Copy link
Member

Hywan commented Apr 8, 2015

Don't rebase your patches each time. Just at the end.

Good to have a resetErrors method but it needs to run automatically between to assert.

@Hywan
Copy link
Member

Hywan commented Jul 27, 2015

@vonglasow ping?

@vonglasow
Copy link
Member Author

Yep sorry stand by during too long I will try to finish it ASAP

@Hywan
Copy link
Member

Hywan commented Jul 27, 2015

No hurry 😃!

@Hywan Hywan assigned jubianchi and unassigned Hywan Mar 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

3 participants