Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion subprojects/robotpy-hal/hal/src/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,29 @@ RPYBUILD_PYBIND11_MODULE(m) {
#else
m.attr("__halplatform__") = "sim";
m.attr("__hal_simulation__") = true;

m.def("__test_senderr", []() {
HAL_SendError(1, 2, 0, "\xfa" "badmessage", "location", "callstack", 1);
}, release_gil());

#endif

// Redirect stderr to python stderr
sys_module = py::module_::import("sys");

HAL_SetPrintErrorImpl([](const char *line, size_t size) {
if (size == 0) {
return;
}

py::gil_scoped_acquire lock;
py::print(py::str(line, size), "file"_a=sys_module.attr("stderr"));
PyObject *o = PyUnicode_DecodeUTF8(line, size, "replace");
if (o == nullptr) {
PyErr_Clear();
py::print(py::bytes(line, size), "file"_a=sys_module.attr("stderr"));
} else {
py::print(py::reinterpret_steal<py::str>(o), "file"_a=sys_module.attr("stderr"));
}
});

// Do cleanup on module unload
Expand Down
6 changes: 6 additions & 0 deletions subprojects/robotpy-hal/tests/test_hal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ def test_hal_simdevice():

v.set(4)
assert v.get() == 4


def test_hal_send_error(capsys):
hal._wpiHal.__test_senderr()
cap = capsys.readouterr()
assert cap.err == "Error at location: �badmessage\ncallstack\n\n"
6 changes: 3 additions & 3 deletions subprojects/robotpy-wpilib/wpilib/_impl/report_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def reportErrorInternal(
not isWarning,
code,
False,
error.encode("utf-8"),
locString.encode("utf-8"),
traceString.encode("utf-8"),
error,
locString,
traceString,
True,
)

Expand Down
Loading