Skip to content

Commit cbd92bb

Browse files
authored
Merge pull request #234 from CESNET/pytrap_improved_errmessage
pytrap: improved error message on bad UniRec field redefinition
2 parents 7523514 + c2e3d69 commit cbd92bb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pytrap/src/unirecmodule.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,20 @@ UnirecTemplate_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
20952095
self->urtmplt = NULL;
20962096
int ret;
20972097
if ((ret = ur_define_set_of_fields(spec)) != UR_OK) {
2098-
PyErr_SetString(TrapError, "ur_define_set_of_fields() failed.");
2098+
switch (ret) {
2099+
case UR_E_INVALID_NAME:
2100+
PyErr_SetString(TrapError, "ur_define_set_of_fields() failed due to bad name of some field in the template. The name must start with letter [a-zA-Z] and can contain only [a-zA-Z0-9_].");
2101+
break;
2102+
case UR_E_TYPE_MISMATCH:
2103+
PyErr_SetString(TrapError, "ur_define_set_of_fields() failed because some field with the existing name is being redefined (even in a different NEMEA module due to global context) with a different type, which is not allowed.");
2104+
break;
2105+
case UR_E_MEMORY:
2106+
PyErr_SetString(TrapError, "ur_define_set_of_fields() failed due to memory allocation error.");
2107+
break;
2108+
default:
2109+
// this should not happen...
2110+
PyErr_SetString(TrapError, "ur_define_set_of_fields() failed due to unkown reason.");
2111+
}
20992112
Py_DECREF(self);
21002113
return NULL;
21012114
}

0 commit comments

Comments
 (0)