MCPcopy Create free account
hub / github.com/BasisResearch/lean.py / format_lean_io_error

Function format_lean_io_error

LeanPy/native/python_bridge.c:844–873  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

842
843static PyObject *g_lean_callable_type = NULL;
844static PyObject *g_lean_callable_kw_type = NULL;
845
846static PyObject *leancallable_call(PyObject *self_, PyObject *args, PyObject *kwds);
847static void leancallable_dealloc(PyObject *self_);
848static 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. */
853static 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);

Callers 1

leancallable_callFunction · 0.85

Calls 5

lean_is_scalarFunction · 0.85
lean_unboxFunction · 0.85
lean_ptr_tagFunction · 0.85
lean_ctor_getFunction · 0.85
lean_string_cstrFunction · 0.85

Tested by

no test coverage detected