other event data must be compatible with json encoding

other event data must be compatible with json encoding

by Eran Levin -
Number of replies: 1

Hi,

I try to send email message via moodle api, and I get this strange error:

other event data must be compatible with json encoding

line 770 of /lib/classes/event/base.php: call to debugging()

line 808 of /lib/classes/event/base.php: call to core\event\base->validate_before_trigger()

line 156 of /lib/classes/message/manager.php: call to core\event\base->trigger()

line 104 of /lib/classes/message/manager.php: call to core\message\manager::send_message_to_processors()

line 251 of /lib/messagelib.php: call to core\message\manager::send_message()


I try to invoke the function with:

message_send(($message));
message is an object, containing all the relevant details.

the message is sent, but the error is printed.

anyone knows why?

Average of ratings: -
In reply to Eran Levin

Re: other event data must be compatible with json encoding

by Renaat Debleu -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
You can find the string "other event data must be compatible with json encoding" and a reason in the file lib/classes/event/base.php :

 protected final function validate_before_trigger() {
...

if ($CFG->debugdeveloper) {
...
$encoded = json_encode($this->data['other']);
// The comparison here is not set to strict as whole float numbers will be converted to integers through JSON encoding /
// decoding and send an unwanted debugging message.
if ($encoded === false or $this->data['other'] != json_decode($encoded, true)) {
debugging('other event data must be compatible with json encoding', DEBUG_DEVELOPER);
}