Skip to content

Commit

Permalink
python: osdp_sys: Add some error context for public API
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Mar 12, 2024
1 parent cf18bf7 commit 253d87e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion python/osdp_sys/cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ static PyObject *pyosdp_cp_send_command(pyosdp_cp_t *self, PyObject *args)
PyObject *cmd_dict;
struct osdp_cmd cmd;

if (!PyArg_ParseTuple(args, "IO!", &pd, &PyDict_Type, &cmd_dict))
if (!PyArg_ParseTuple(args, "IO!", &pd, &PyDict_Type, &cmd_dict)) {
PyErr_SetString(PyExc_ValueError, "Invalid arguments");
Py_RETURN_FALSE;
}

if (pd < 0 || pd >= self->num_pd) {
PyErr_SetString(PyExc_ValueError, "Invalid PD offset");
Expand Down
8 changes: 6 additions & 2 deletions python/osdp_sys/pd.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ static PyObject *pyosdp_pd_notify_event(pyosdp_pd_t *self, PyObject *args)
PyObject *event_dict;
struct osdp_event event;

if (!PyArg_ParseTuple(args, "O", &event_dict))
if (!PyArg_ParseTuple(args, "O", &event_dict)) {
PyErr_SetString(PyExc_TypeError, "Failed to parse event dict!");
return NULL;
}

if (pyosdp_make_struct_event(&event, event_dict))
if (pyosdp_make_struct_event(&event, event_dict)) {
PyErr_SetString(PyExc_TypeError, "Unable to get event struct!");
return NULL;
}

if (osdp_pd_notify_event(self->ctx, &event)) {
Py_RETURN_FALSE;
Expand Down

0 comments on commit 253d87e

Please sign in to comment.