Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: add a type of common error

...

This example was inspired by this commit.

Thought an event attribute was sent

event:send is an action in the event library (sometimes called a module, as it uses the same syntax as modules (the colon separating the module name and the function/action/value it provides)).

The event:send action generates an event that it sent to a pico, and takes two arguments, the first being a map with certain expected keys, and the second being a string containing the host of the receiving pico.

What is wrong with this code?

Code Block
      event:send({
        "eci":eci,
        "domain":"wrangler",
        "type":"ready_for_deletion",
        "co_id": meta:rid,
      })

Answer: "co_id" is not one of the expected keys in the map (which is the first argument to the event:send action). The author was thinking that this would send an attribute of that name as one of the event attributes. Instead, since there was no "attrs" key in the map, no attributes were sent. Since "co_id" was not an expected key, the action just ignored it silently. The corrected code is:

Code Block
      event:send({
        "eci":eci,
        "domain":"wrangler",
        "type":"ready_for_deletion",
        "attrs":{"co_id": meta:rid},
      })

This example was inspired by this commit, and finishes an attempt to follow the best practice from the “Managing Pico Lifecycle” document.