Convert an `IO.Error` payload into a printable C string. The bridge's * own errors are `userError String`; for others we fall back to the * underlying field-0 if it looks like a string, else a generic tag. */
| 842 | |
| 843 | static PyObject *g_lean_callable_type = NULL; |
| 844 | static PyObject *g_lean_callable_kw_type = NULL; |
| 845 | |
| 846 | static PyObject *leancallable_call(PyObject *self_, PyObject *args, PyObject *kwds); |
| 847 | static void leancallable_dealloc(PyObject *self_); |
| 848 | static PyObject *leancallable_repr(PyObject *self_); |
| 849 | |
| 850 | /* Convert an `IO.Error` payload into a printable C string. The bridge's |
| 851 | * own errors are `userError String`; for others we fall back to the |
| 852 | * underlying field-0 if it looks like a string, else a generic tag. */ |
| 853 | static void format_lean_io_error(lean_object *err, char *buf, size_t bufsz) { |
| 854 | if (!err) { |
| 855 | snprintf(buf, bufsz, "Lean error (no payload)"); |
| 856 | return; |
| 857 | } |
| 858 | /* Most IO.Error variants (e.g. userError) carry a String at field 0. */ |
| 859 | if (lean_is_scalar(err)) { |
| 860 | snprintf(buf, bufsz, "Lean IO.Error (tag %u, no payload)", |
| 861 | (unsigned)lean_unbox(err)); |
| 862 | return; |
| 863 | } |
| 864 | unsigned tag = lean_ptr_tag(err); |
| 865 | /* lean_ctor_get returns a borrowed pointer */ |
| 866 | lean_object *fld = lean_ctor_get(err, 0); |
| 867 | if (fld && !lean_is_scalar(fld) && lean_is_string(fld)) { |
| 868 | snprintf(buf, bufsz, "%s", lean_string_cstr(fld)); |
| 869 | return; |
| 870 | } |
| 871 | /* userError-shaped: even if the tag detection above fails, just try |
| 872 | * to read field 0 as a string. */ |
| 873 | if (fld && !lean_is_scalar(fld)) { |
| 874 | const char *cs = lean_string_cstr(fld); |
| 875 | if (cs && cs[0]) { |
| 876 | snprintf(buf, bufsz, "%s", cs); |
no test coverage detected