yamcs / python-yamcs-client

Yamcs Client for Python
https://docs.yamcs.org/python-yamcs-client/
GNU Lesser General Public License v3.0
16 stars 11 forks source link

In Yamcs Python API, the error attribute of a command result is not populated reliably #19

Closed merose closed 1 year ago

merose commented 2 years ago

To reproduce:

Ensure no command data link is enabled in Yamcs. cmd_conn = processor.create_command_connection() cmd = cmd_conn.issue(cmd_name, args={...}) Expected result: cmd.is_success() is False and cmd.error is an error message

Actual result: cmd.is_success() is False, but cmd.error is sometimes populated and sometimes None

fqqb commented 1 year ago

Both is_success() and error are not immediately populated after the issue as they depend on the full completion of the command (which may take indefinite time). In this case (no available link) it completes fast (failure), therefore sometimes you see this information already updated, and sometimes you don't.

What you can do is await this information with await_complete before accessing is_success() and error.

cmd = cmd_conn.issue(...)
cmd.await_complete()
# Safe to access completion information

In the case of disabled command links, the failing ack is called Acknowledge_Sent ("S" in Yamcs UI), so an alternative reliable thing we can do, is this:

cmd = cmd_conn.issue(...)
ack = cmd.await_acknowledgment("Acknowledge_Sent")
# Use ack.status and ack.message instead of cmd.is_success() and cmd.error

This second approach can be useful when command completion is not configured at Yamcs MDB level (very common), i.e. Yamcs then cannot tell when a command is considered successful, which would cause await_complete() to timeout unless there is a Yamcs-level failure.

merose commented 1 year ago

That makes sense, thanks. In that case this is "not an issue". Will close.