diff --git a/src/core/platform.c b/src/core/platform.c index 8fc534727..5ef356898 100644 --- a/src/core/platform.c +++ b/src/core/platform.c @@ -53,6 +53,7 @@ uint64_t ray_vm_willneed_bytes(void) { #include #include #include +#include /* the failing call's errno, kept by ray_vm_map_file (#1886) */ #include /* the lazily read page size and read-ahead step */ #if defined(RAY_OS_MACOS) #include /* sysctlbyname — hw.physicalcpu */ @@ -104,9 +105,13 @@ void* ray_vm_map_file_id(const char* path, size_t* out_size, ray_file_id_t* id) int fd = open(path, O_RDONLY); if (fd < 0) return NULL; + /* A failure leaves errno as the failing call set it (close keeps it), + * and an empty file leaves it 0, so a caller can name the reason (#1886). */ struct stat st; if (fstat(fd, &st) != 0) { + int e = errno; close(fd); + errno = e; return NULL; } if (id) { @@ -125,14 +130,16 @@ void* ray_vm_map_file_id(const char* path, size_t* out_size, ray_file_id_t* id) if (st.st_size <= 0) { close(fd); if (out_size) *out_size = 0; + errno = 0; return NULL; } size_t len = (size_t)st.st_size; void* p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + int map_errno = errno; close(fd); - if (p == MAP_FAILED) return NULL; + if (p == MAP_FAILED) { errno = map_errno; return NULL; } ray_sys_track_file_add((int64_t)len); /* file-backed mapping */ if (out_size) *out_size = len; @@ -1697,6 +1704,7 @@ void ray_sem_signal(ray_sem_t* s) { #include #include #include +#include /* the failing call's errno, kept by ray_vm_map_file (#1886) */ #include #include #include "mem/sys.h" @@ -1736,17 +1744,21 @@ void* ray_vm_map_file(const char* path, size_t* out_size) { if (fd < 0) return NULL; struct stat st; - if (fstat(fd, &st) != 0 || st.st_size <= 0) { + int st_rc = fstat(fd, &st); + if (st_rc != 0 || st.st_size <= 0) { + int e = st_rc != 0 ? errno : 0; close(fd); if (out_size) *out_size = 0; + errno = e; /* the failing call's, or 0 for an empty file (#1886) */ return NULL; } size_t len = (size_t)st.st_size; void* p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); + int map_errno = errno; close(fd); - if (p == MAP_FAILED) return NULL; + if (p == MAP_FAILED) { errno = map_errno; return NULL; } ray_sys_track_file_add((int64_t)len); if (out_size) *out_size = len; return p; diff --git a/src/lang/env.c b/src/lang/env.c index d39d9ac51..173abac3f 100644 --- a/src/lang/env.c +++ b/src/lang/env.c @@ -165,7 +165,7 @@ static __attribute__((noinline, cold)) ray_t* env_frame_force(ray_scope_frame_t* * (RAY_LAZY_G_FAILED): the bindings keep it too, so a later read * raises the value's own error again, not an undefined name. */ ray_retain(lazy); - return concrete ? concrete : ray_error("type", NULL); + return concrete ? concrete : ray_error("type", "lazy local: materializing answered no value"); } f->vals[i] = ok ? concrete : NULL; if (f->slot_values) @@ -175,7 +175,7 @@ static __attribute__((noinline, cold)) ray_t* env_frame_force(ray_scope_frame_t* if (ok) ray_retain(concrete); f->slot_values[j] = ok ? concrete : NULL; } - return ok ? concrete : (concrete ? concrete : ray_error("type", NULL)); + return ok ? concrete : (concrete ? concrete : ray_error("type", "lazy local: materializing answered no value")); } /* A frame's value at `i`, as a read sees it: a lazy handle forced. */ diff --git a/src/lang/eval.c b/src/lang/eval.c index ae79d01c8..0e7b2a345 100644 --- a/src/lang/eval.c +++ b/src/lang/eval.c @@ -724,7 +724,7 @@ static ray_t* materialize_owned_args(ray_t** args, int64_t n) { args[i] = ray_lazy_materialize(args[i]); /* consumes owned ref */ if (!args[i] || RAY_IS_ERR(args[i])) { - ray_t* err = args[i] ? args[i] : ray_error("type", NULL); + ray_t* err = args[i] ? args[i] : ray_error("type", "call: an argument answered no value"); args[i] = NULL; for (int64_t j = 0; j < n; j++) { if (args[j]) ray_release(args[j]); @@ -915,11 +915,11 @@ static ray_t* try_sum_affine(ray_t* vec, ray_t* literal) { } else { ray_t* sum = ray_sum_fn(vec); if (!sum || RAY_IS_ERR(sum)) { - return sum ? sum : ray_error("type", NULL); + return sum ? sum : ray_error("type", "sum: answered no value"); } sum = materialize_owned_value(sum); if (!sum || RAY_IS_ERR(sum)) { - return sum ? sum : ray_error("type", NULL); + return sum ? sum : ray_error("type", "sum: answered no value"); } ce.sum_i = sum->i64; ray_release(sum); @@ -981,7 +981,7 @@ ray_t* ray_raise_fn(ray_t* val) { * was compiled. */ static ray_t* undefined_name_error(int64_t sym) { ray_t* s = ray_sym_str(sym); /* borrowed */ - if (!s) return ray_error("name", NULL); + if (!s) return ray_error("name", "name: undefined name with no text (symbol %lld)", (long long)sym); return ray_error("name", "'%.*s' undefined", (int)ray_str_len(s), ray_str_ptr(s)); } @@ -1614,12 +1614,12 @@ static ray_t* atomic_map_binary_parted(ray_binary_fn fn, uint16_t dag_opcode, ray_t* r = right_parted ? rsegs[s] : right; if (!l || !r) { ray_release(out); - return ray_error("type", NULL); + return ray_error("type", "parted: a partition has no segment for this operation"); } ray_t* seg = atomic_map_binary_op(fn, dag_opcode, l, r); if (!seg || RAY_IS_ERR(seg)) { ray_release(out); - return seg ? seg : ray_error("domain", NULL); + return seg ? seg : ray_error("domain", "parted: a partition's segment answered no value"); } if (!ray_is_vec(seg)) { int8_t st = seg->type; @@ -2191,7 +2191,7 @@ static ray_t* map_cell_error(ray_t* left, int left_coll, ray_t* a, int la, if (own_a && own_b) ray_error_free(b); if (own_a) return a; if (own_b) return b; - return ray_error("type", NULL); + return ray_error("type", "map: an element's call answered no value"); } /* Whether a cell's result is a number a typed numeric or temporal vector @@ -3374,7 +3374,7 @@ ray_t* call_fn1(ray_t* fn, ray_t* arg) { if (!(fn->attrs & RAY_FN_LAZY_AWARE) && ray_is_lazy(a)) { ray_retain(a); /* give materialise its own ref; arg is borrowed */ a = ray_lazy_materialize(a); /* consumes the retain we just added */ - if (!a || RAY_IS_ERR(a)) return a ? a : ray_error("type", NULL); + if (!a || RAY_IS_ERR(a)) return a ? a : ray_error("type", "call: a lazy argument answered no value"); owned = true; } ray_t* r; @@ -3398,7 +3398,7 @@ ray_t* call_fn1(ray_t* fn, ray_t* arg) { ray_t* a = arg; ray_retain(a); if (ray_is_lazy(a)) a = ray_lazy_materialize(a); /* consumes our ref */ - return a ? a : ray_error("type", NULL); + return a ? a : ray_error("type", "call: a lazy argument answered no value"); } return call_vary_values(fn, &arg, 1); } @@ -3420,7 +3420,7 @@ ray_t* call_fn2(ray_t* fn, ray_t* a, ray_t* b) { if (ray_is_lazy(la)) { ray_retain(la); /* give materialise its own ref; a is borrowed */ la = ray_lazy_materialize(la); /* consumes the retain we just added */ - if (!la || RAY_IS_ERR(la)) return la ? la : ray_error("type", NULL); + if (!la || RAY_IS_ERR(la)) return la ? la : ray_error("type", "call: a lazy argument answered no value"); owned_a = true; } if (ray_is_lazy(lb)) { @@ -3428,7 +3428,7 @@ ray_t* call_fn2(ray_t* fn, ray_t* a, ray_t* b) { lb = ray_lazy_materialize(lb); /* consumes the retain we just added */ if (!lb || RAY_IS_ERR(lb)) { if (owned_a) ray_release(la); - return lb ? lb : ray_error("type", NULL); + return lb ? lb : ray_error("type", "call: a lazy argument answered no value"); } owned_b = true; } @@ -3456,7 +3456,7 @@ ray_t* call_fn2(ray_t* fn, ray_t* a, ray_t* b) { if (ray_is_lazy(la)) { ray_retain(la); la = ray_lazy_materialize(la); - if (!la || RAY_IS_ERR(la)) return la ? la : ray_error("type", NULL); + if (!la || RAY_IS_ERR(la)) return la ? la : ray_error("type", "call: a lazy argument answered no value"); owned_a = true; } if (ray_is_lazy(lb)) { @@ -3464,7 +3464,7 @@ ray_t* call_fn2(ray_t* fn, ray_t* a, ray_t* b) { lb = ray_lazy_materialize(lb); if (!lb || RAY_IS_ERR(lb)) { if (owned_a) ray_release(la); - return lb ? lb : ray_error("type", NULL); + return lb ? lb : ray_error("type", "call: a lazy argument answered no value"); } owned_b = true; } @@ -4024,7 +4024,7 @@ ray_t* ray_table_fn(ray_t* names, ray_t* cols) { ray_t* ray_key_fn(ray_t* x) { if (x->type == RAY_DICT) { ray_t* keys = ray_dict_keys(x); - if (!keys) return ray_error("type", NULL); + if (!keys) return ray_error("type", "key: the dict has no keys"); ray_retain(keys); return keys; } @@ -4057,7 +4057,7 @@ ray_t* ray_value_fn(ray_t* x) { } if (x->type != RAY_DICT) return ray_error("type", "value: expected a dict or table, got %s", ray_type_name(x->type)); ray_t* vals = ray_dict_vals(x); - if (!vals) return ray_error("type", NULL); + if (!vals) return ray_error("type", "value: the dict has no values"); ray_retain(vals); return vals; } @@ -4087,7 +4087,7 @@ ray_t* ray_set_fn(ray_t* name_obj, ray_t* val_expr) { ray_err_t err = ray_env_set(name_obj->i64, val); if (err != RAY_OK) { ray_release(val); - return ray_error(ray_err_code_str(err), NULL); + return ray_error(ray_err_code_str(err), "set: cannot bind '%.*s' (%s)", (int)(ray_sym_str(name_obj->i64) ? ray_str_len(ray_sym_str(name_obj->i64)) : 1), ray_sym_str(name_obj->i64) ? ray_str_ptr(ray_sym_str(name_obj->i64)) : "?", ray_err_code_str(err)); } return val; /* set returns the value */ } @@ -4107,7 +4107,7 @@ ray_t* ray_let_fn(ray_t* name_obj, ray_t* val_expr) { if (err != RAY_OK) { ray_release(val); return err == RAY_ERR_ACCESS ? ray_error("access", "restricted") - : ray_error(ray_err_code_str(err), NULL); + : ray_error(ray_err_code_str(err), "let: cannot bind '%.*s' (%s)", (int)(ray_sym_str(name_obj->i64) ? ray_str_len(ray_sym_str(name_obj->i64)) : 1), ray_sym_str(name_obj->i64) ? ray_str_ptr(ray_sym_str(name_obj->i64)) : "?", ray_err_code_str(err)); } return val; } @@ -4420,7 +4420,7 @@ ray_t* ray_times_fn(ray_t** args, int64_t n) { ray_t* cexpr = args[0]; if (ray_times_binding(args[0], &name, &cexpr) && ray_sym_is_reserved(name) && !ray_sym_is_ipc_hook(name)) - return ray_error(ray_err_code_str(RAY_ERR_RESERVED), NULL); + return ray_error(ray_err_code_str(RAY_ERR_RESERVED), "times: '%.*s' is a reserved name", (int)(ray_sym_str(name) ? ray_str_len(ray_sym_str(name)) : 1), ray_sym_str(name) ? ray_str_ptr(ray_sym_str(name)) : "?"); ray_t* cnt = ray_eval(cexpr); if (RAY_IS_ERR(cnt)) return cnt; if (ray_is_lazy(cnt)) @@ -4438,7 +4438,7 @@ ray_t* ray_times_fn(ray_t** args, int64_t n) { ray_err_t e = ray_env_set_local_rows(name, idx, 0); ray_release(idx); if (e == RAY_ERR_ACCESS) return ray_error("access", "restricted"); - if (e != RAY_OK) return ray_error(ray_err_code_str(e), NULL); + if (e != RAY_OK) return ray_error(ray_err_code_str(e), "times: cannot bind '%.*s' (%s)", (int)(ray_sym_str(name) ? ray_str_len(ray_sym_str(name)) : 1), ray_sym_str(name) ? ray_str_ptr(ray_sym_str(name)) : "?", ray_err_code_str(e)); } for (int64_t i = 1; i < n; i++) { ray_t* val = ray_eval(args[i]); @@ -5109,7 +5109,7 @@ static ray_t* call_lambda_impl(ray_t* lambda, ray_t** call_args, int64_t argc, if (!arg || RAY_IS_ERR(arg)) { ray_env_pop_scope(); if (call_frame) ray_env_pop_scope(); - return arg ? arg : ray_error("type", NULL); + return arg ? arg : ray_error("type", "lambda: a lazy argument answered no value"); } } /* Parameters carry the arguments' row provenance into the body. */ @@ -5413,7 +5413,7 @@ static inline ray_t* vm_apply_unary_raw(ray_t* fn_obj, ray_t* arg) { ray_unary_fn fn = (ray_unary_fn)(uintptr_t)fn_obj->i64; if (RAY_UNLIKELY(RAY_IS_NULL(arg))) return (fn == (ray_unary_fn)ray_nil_fn || fn == (ray_unary_fn)ray_type_fn) - ? fn(arg) : ray_error("type", NULL); + ? fn(arg) : ray_error("type", "%s: the generic null is not an argument; only nil?, type and ser take it", ray_fn_name(fn_obj)); if ((fn_obj->attrs & RAY_FN_ATOMIC) && arg->type >= 0) return atomic_map_unary(fn, arg); return fn(arg); @@ -5436,17 +5436,17 @@ static ray_t* vm_call_binary_raw(ray_t* fn_obj, ray_t* left, ray_t* right, if (!(fn_obj->attrs & RAY_FN_LAZY_AWARE)) { if (left && ray_is_lazy(left)) { left = ray_lazy_materialize(left); - if (!left || RAY_IS_ERR(left)) { ray_release(right); return left ? left : ray_error("type", NULL); } + if (!left || RAY_IS_ERR(left)) { ray_release(right); return left ? left : ray_error("type", "call: a lazy argument answered no value"); } } if (right && ray_is_lazy(right)) { right = ray_lazy_materialize(right); - if (!right || RAY_IS_ERR(right)) { ray_release(left); return right ? right : ray_error("type", NULL); } + if (!right || RAY_IS_ERR(right)) { ray_release(left); return right ? right : ray_error("type", "call: a lazy argument answered no value"); } } } RAY_ASSERT_VALUE(left); RAY_ASSERT_VALUE(right); if (RAY_UNLIKELY(RAY_IS_NULL(left) || RAY_IS_NULL(right))) { result = (fn == ray_identical_fn || fn == (ray_binary_fn)ray_eq_fn || fn == (ray_binary_fn)ray_neq_fn) - ? fn(left, right) : ray_error("type", NULL); + ? fn(left, right) : ray_error("type", "%s: the generic null is not an argument; only identical, == and != take it", ray_fn_name(fn_obj)); } else if (fn == ray_concat_fn && (left_rows == 1 || right_rows == 1) && vm_text_value(left) && vm_text_value(right) && (left_rows == 1 || ray_is_atom(left)) && (right_rows == 1 || ray_is_atom(right))) { @@ -5670,7 +5670,7 @@ op_loadenv: { * and then used twice: `((fn [v] (if (> v 0) v 0)) (first xs))`. */ val = ray_lazy_materialize(val); /* consumes the slot's ref */ if (!val || RAY_IS_ERR(val)) { - vm_err_obj = val ? val : ray_error("type", NULL); + vm_err_obj = val ? val : ray_error("type", "lambda: a lazy local answered no value"); LOCAL(slot) = NULL; /* ref already consumed */ goto vm_error; } @@ -5759,7 +5759,7 @@ op_storeglobal: { ray_err_t err = ray_env_set(name_obj->i64, val); if (err != RAY_OK) { ray_release(POP()); - vm_err_obj = ray_error(ray_err_code_str(err), NULL); + vm_err_obj = ray_error(ray_err_code_str(err), "set: cannot bind '%.*s' (%s)", (int)(ray_sym_str(name_obj->i64) ? ray_str_len(ray_sym_str(name_obj->i64)) : 1), ray_sym_str(name_obj->i64) ? ray_str_ptr(ray_sym_str(name_obj->i64)) : "?", ray_err_code_str(err)); goto vm_error; } DISPATCH(); @@ -5778,7 +5778,7 @@ op_storeglobal_w: { ray_err_t err = ray_env_set(name_obj->i64, val); if (err != RAY_OK) { ray_release(POP()); - vm_err_obj = ray_error(ray_err_code_str(err), NULL); + vm_err_obj = ray_error(ray_err_code_str(err), "set: cannot bind '%.*s' (%s)", (int)(ray_sym_str(name_obj->i64) ? ray_str_len(ray_sym_str(name_obj->i64)) : 1), ray_sym_str(name_obj->i64) ? ray_str_ptr(ray_sym_str(name_obj->i64)) : "?", ray_err_code_str(err)); goto vm_error; } DISPATCH(); @@ -5892,7 +5892,7 @@ op_jmpf: { arg = ray_lazy_materialize(arg); \ if (!arg || RAY_IS_ERR(arg)) { \ ray_release(fn_obj); \ - vm_err_obj = arg ? arg : ray_error("type", NULL); \ + vm_err_obj = arg ? arg : ray_error("type", "lambda: a lazy argument answered no value"); \ goto vm_error; \ } \ } \ @@ -6124,7 +6124,7 @@ op_callf: { if (fn_args[i] && ray_is_lazy(fn_args[i])) { fn_args[i] = ray_lazy_materialize(fn_args[i]); if (!fn_args[i] || RAY_IS_ERR(fn_args[i])) { - result = fn_args[i] ? fn_args[i] : ray_error("type", NULL); + result = fn_args[i] ? fn_args[i] : ray_error("type", "call: an argument answered no value"); fn_args[i] = NULL; ray_release(fn_args[1 - i]); goto unary_done; @@ -6143,7 +6143,7 @@ op_callf: { * consumes it — no extra ray_release after the call. */ if (!(fn_obj->attrs & RAY_FN_LAZY_AWARE) && fn_args[0] && ray_is_lazy(fn_args[0])) { fn_args[0] = ray_lazy_materialize(fn_args[0]); /* consumes owned ref */ - if (!fn_args[0] || RAY_IS_ERR(fn_args[0])) { result = fn_args[0] ? fn_args[0] : ray_error("type", NULL); fn_args[0] = NULL; break; } + if (!fn_args[0] || RAY_IS_ERR(fn_args[0])) { result = fn_args[0] ? fn_args[0] : ray_error("type", "call: a lazy argument answered no value"); fn_args[0] = NULL; break; } } if (RAY_UNLIKELY(fn_obj->attrs & RAY_FN_ROWWISE) && (result = rowwise_apply(RAY_UNARY, (void*)(uintptr_t)unary, fn_args, arg_rows, 1)) != NULL) { @@ -6161,7 +6161,7 @@ op_callf: { * tree walker and in OP_CALL1. */ if (RAY_UNLIKELY(RAY_IS_NULL(fn_args[0]))) result = (unary == (ray_unary_fn)ray_nil_fn || unary == (ray_unary_fn)ray_type_fn || - unary == (ray_unary_fn)ray_ser_fn) ? unary(fn_args[0]) : ray_error("type", NULL); + unary == (ray_unary_fn)ray_ser_fn) ? unary(fn_args[0]) : ray_error("type", "%s: the generic null is not an argument; only nil?, type and ser take it", ray_fn_name(fn_obj)); else if ((fn_obj->attrs & RAY_FN_ATOMIC) && fn_args[0] && fn_args[0]->type >= 0) result = atomic_map_unary(unary, fn_args[0]); else @@ -6199,11 +6199,11 @@ op_callf: { if (!(fn_obj->attrs & RAY_FN_LAZY_AWARE)) { if (fn_args[0] && ray_is_lazy(fn_args[0])) { fn_args[0] = ray_lazy_materialize(fn_args[0]); /* consumes owned ref */ - if (!fn_args[0] || RAY_IS_ERR(fn_args[0])) { result = fn_args[0] ? fn_args[0] : ray_error("type", NULL); fn_args[0] = NULL; ray_release(fn_args[1]); fn_args[1] = NULL; break; } + if (!fn_args[0] || RAY_IS_ERR(fn_args[0])) { result = fn_args[0] ? fn_args[0] : ray_error("type", "call: a lazy argument answered no value"); fn_args[0] = NULL; ray_release(fn_args[1]); fn_args[1] = NULL; break; } } if (fn_args[1] && ray_is_lazy(fn_args[1])) { fn_args[1] = ray_lazy_materialize(fn_args[1]); /* consumes owned ref */ - if (!fn_args[1] || RAY_IS_ERR(fn_args[1])) { result = fn_args[1] ? fn_args[1] : ray_error("type", NULL); ray_release(fn_args[0]); fn_args[0] = NULL; fn_args[1] = NULL; break; } + if (!fn_args[1] || RAY_IS_ERR(fn_args[1])) { result = fn_args[1] ? fn_args[1] : ray_error("type", "call: a lazy argument answered no value"); ray_release(fn_args[0]); fn_args[0] = NULL; fn_args[1] = NULL; break; } } } /* The same path as OP_CALL2: the elementwise map for an atomic @@ -6496,7 +6496,7 @@ op_mkclosure: { ray_release(keys); ray_release(vals); ray_release(flags); lam->type = -RAY_I64; ray_release(lam); ray_release(slots); ray_release(names); ray_release(tmpl); - vm_err_obj = v ? v : ray_error("type", NULL); + vm_err_obj = v ? v : ray_error("type", "lambda: a captured local answered no value"); goto vm_error; } } @@ -6545,7 +6545,7 @@ op_loadenvg: { if (val) { if (ray_is_lazy(val)) { val = ray_lazy_materialize(val); - if (!val || RAY_IS_ERR(val)) { vm_err_obj = val ? val : ray_error("type", NULL); LOCAL(slot) = NULL; goto vm_error; } + if (!val || RAY_IS_ERR(val)) { vm_err_obj = val ? val : ray_error("type", "lambda: a lazy local answered no value"); LOCAL(slot) = NULL; goto vm_error; } LOCAL(slot) = val; } ray_retain(val); @@ -6574,7 +6574,7 @@ op_force: { uint8_t v_rows = POPPED_ROWS(); if (v && ray_is_lazy(v)) { v = ray_lazy_materialize(v); /* consumes; concrete or error */ - if (!v || RAY_IS_ERR(v)) { vm_err_obj = v ? v : ray_error("type", NULL); goto vm_error; } + if (!v || RAY_IS_ERR(v)) { vm_err_obj = v ? v : ray_error("type", "lambda: a lazy local answered no value"); goto vm_error; } } PUSHR(v, v_rows); DISPATCH(); @@ -6759,7 +6759,7 @@ vm_error_cleanup: { return vm_err_obj; if (vm_err_detail) return ray_error(vm_err_str, "%s", vm_err_detail); - return ray_error(vm_err_str, NULL); + return ray_error(vm_err_str, "lambda: %s error in compiled code", vm_err_str); } #undef DISPATCH @@ -7740,19 +7740,19 @@ static ray_t* eval_impl(ray_t* obj, bool* summed) { if (n == 3 && fn2) { ray_t* left = ray_eval(elems[1]); int8_t left_rows = g_eval_rows; - if (!left || RAY_IS_ERR(left)) { ray_release(head); ret = left ? left : ray_error("type", NULL); goto out; } + if (!left || RAY_IS_ERR(left)) { ray_release(head); ret = left ? left : ray_error("type", "call: an argument answered no value"); goto out; } ray_t* right = ray_eval(elems[2]); int8_t right_rows = g_eval_rows; rows = rowwise ? rows_join(left_rows, right_rows) : 0; ray_release(head); - if (!right || RAY_IS_ERR(right)) { ray_release(left); ret = right ? right : ray_error("type", NULL); goto out; } + if (!right || RAY_IS_ERR(right)) { ray_release(left); ret = right ? right : ray_error("type", "call: an argument answered no value"); goto out; } if (ray_is_lazy(left)) { left = ray_lazy_materialize(left); - if (!left || RAY_IS_ERR(left)) { ray_release(right); ret = left ? left : ray_error("type", NULL); goto out; } + if (!left || RAY_IS_ERR(left)) { ray_release(right); ret = left ? left : ray_error("type", "call: a lazy argument answered no value"); goto out; } } if (ray_is_lazy(right)) { right = ray_lazy_materialize(right); - if (!right || RAY_IS_ERR(right)) { ray_release(left); ret = right ? right : ray_error("type", NULL); goto out; } + if (!right || RAY_IS_ERR(right)) { ray_release(left); ret = right ? right : ray_error("type", "call: a lazy argument answered no value"); goto out; } } ret = (is_collection(left) || is_collection(right)) ? minmax_map(fn2, left, right) : fn2(left, right); @@ -7772,7 +7772,7 @@ static ray_t* eval_impl(ray_t* obj, bool* summed) { ray_t* fast = ray_try_count_select_expr(elems[1], &handled); if (handled) { ray_release(head); - ret = fast ? fast : ray_error("type", NULL); + ret = fast ? fast : ray_error("type", "call: the fused form answered no value"); rows = 0; goto out; } } @@ -7799,7 +7799,7 @@ static ray_t* eval_impl(ray_t* obj, bool* summed) { * consumes it — no extra ray_release needed after the call. */ if (!(fn_attrs & RAY_FN_LAZY_AWARE) && arg && ray_is_lazy(arg)) { arg = ray_lazy_materialize(arg); /* consumes owned ref */ - if (!arg || RAY_IS_ERR(arg)) { ret = arg ? arg : ray_error("type", NULL); goto out; } + if (!arg || RAY_IS_ERR(arg)) { ret = arg ? arg : ray_error("type", "call: a lazy argument answered no value"); goto out; } } ray_t* result; RAY_ASSERT_VALUE(arg); @@ -7822,7 +7822,7 @@ static ray_t* eval_impl(ray_t* obj, bool* summed) { if (RAY_IS_NULL(arg)) { /* Only nil?/type/ser safely handle null */ result = (fn == (ray_unary_fn)ray_nil_fn || fn == (ray_unary_fn)ray_type_fn || - fn == (ray_unary_fn)ray_ser_fn) ? fn(arg) : ray_error("type", NULL); + fn == (ray_unary_fn)ray_ser_fn) ? fn(arg) : ray_error("type", "%s: the generic null is not an argument; only nil?, type and ser take it", nm); } else if ((fn_attrs & RAY_FN_ATOMIC) && is_collection(arg)) result = atomic_map_unary(fn, arg); else @@ -7921,14 +7921,14 @@ static ray_t* eval_impl(ray_t* obj, bool* summed) { left = ray_lazy_materialize(left); /* consumes owned ref */ if (!left || RAY_IS_ERR(left)) { ray_release(head); if (right) ray_release(right); - ret = left ? left : ray_error("type", NULL); goto out; + ret = left ? left : ray_error("type", "call: an argument answered no value"); goto out; } } if (right && ray_is_lazy(right)) { right = ray_lazy_materialize(right); /* consumes owned ref */ if (!right || RAY_IS_ERR(right)) { ray_release(head); if (left) ray_release(left); - ret = right ? right : ray_error("type", NULL); goto out; + ret = right ? right : ray_error("type", "call: an argument answered no value"); goto out; } } } @@ -8022,7 +8022,7 @@ static ray_t* eval_impl(ray_t* obj, bool* summed) { ray_t* stack_args[64]; ray_t** args = stack_args; if (argc > 64) { - if ((uint64_t)argc > SIZE_MAX / sizeof(ray_t*)) { ray_release(head); ret = ray_error("limit", NULL); goto out; } + if ((uint64_t)argc > SIZE_MAX / sizeof(ray_t*)) { ray_release(head); ret = ray_error("limit", "call: %lld arguments overflow the argument array", (long long)argc); goto out; } args = ray_alloc_raw((size_t)argc * sizeof(ray_t*)); if (!args) { ray_release(head); ret = ray_error("oom", NULL); goto out; } } @@ -8043,7 +8043,7 @@ static ray_t* eval_impl(ray_t* obj, bool* summed) { any_rows = rows_join(any_rows, g_eval_rows); if (i < 64) argv_rows[i] = vrows_from(g_eval_rows); if (!args[i] || RAY_IS_ERR(args[i])) { - ray_t* err = (!args[i]) ? ray_error("type", NULL) : args[i]; + ray_t* err = (!args[i]) ? ray_error("type", "call: an argument answered no value") : args[i]; for (int64_t j = 0; j < i; j++) ray_release(args[j]); if (args != stack_args) ray_free_raw(args); ray_release(head); @@ -8078,7 +8078,7 @@ static ray_t* eval_impl(ray_t* obj, bool* summed) { args[i] = ray_eval(elems[i + 1]); arg_rows[i] = g_eval_rows; if (!args[i] || RAY_IS_ERR(args[i])) { - ray_t* err = (!args[i]) ? ray_error("type", NULL) : args[i]; + ray_t* err = (!args[i]) ? ray_error("type", "call: an argument answered no value") : args[i]; for (int64_t j = 0; j < i; j++) ray_release(args[j]); ray_release(head); ret = err; goto out; diff --git a/src/lang/internal.h b/src/lang/internal.h index 34f597022..c2a59ea04 100644 --- a/src/lang/internal.h +++ b/src/lang/internal.h @@ -338,7 +338,7 @@ static inline ray_t* collection_elem(ray_t* coll, int64_t i, int *allocated) { const char* sp = ray_str_vec_get(coll, i, &slen); return ray_str(sp ? sp : "", sp ? slen : 0); } - default: *allocated = 0; return ray_error("type", NULL); + default: *allocated = 0; return ray_error("type", "element: a %s value has no elements", ray_type_name(coll->type)); } } diff --git a/src/lang/syscmd.c b/src/lang/syscmd.c index 487d8819b..c64e22ce6 100644 --- a/src/lang/syscmd.c +++ b/src/lang/syscmd.c @@ -578,7 +578,7 @@ ray_t* ray_syscmd_string_dispatch_fn(ray_t* x) { * straight to the named handler, no string parsing. */ static ray_t* invoke_by_name(const char* name, ray_t* arg) { const ray_syscmd_t* e = ray_syscmd_lookup(name, strlen(name)); - if (!e || !e->fn) return ray_error("nyi", NULL); + if (!e || !e->fn) return ray_error("nyi", "command: :%s is not a known command", name); if (e->flags & RAY_SYSCMD_REPL_ONLY) return ray_error("domain", "command is REPL-only"); ray_syscmd_ctx_t ctx = { NULL, false }; diff --git a/src/ops/agg_engine.c b/src/ops/agg_engine.c index 766f0297e..b97931f62 100644 --- a/src/ops/agg_engine.c +++ b/src/ops/agg_engine.c @@ -13773,7 +13773,7 @@ static ray_t* agg_build_compact(ray_graph_t* g, ray_op_t* op, ray_t* tbl, } ray_t* src = ray_table_col(tbl, want[i]); if (src && RAY_IS_ERR(src)) { ray_release(compact); scratch_free(want_hdr); return src; } - if (!src) { ray_release(compact); scratch_free(want_hdr); return ray_error("nyi", NULL); } + if (!src) { ray_release(compact); scratch_free(want_hdr); return ray_error("nyi", "group: a column the aggregate reads is not in the table"); } assert(!RAY_IS_PARTED(src->type)); gcol = gather_by_idx(src, idx, n_sel); /* fresh, no alias */ if (!gcol || RAY_IS_ERR(gcol)) { @@ -13842,7 +13842,7 @@ static ray_t* exec_group_v2_once(ray_graph_t* g, ray_op_t* op, ray_t* tbl, const ray_group_emit_filter_t* efp = ef.enabled ? &ef : NULL; /* exec_group_v2_run reads g's op extensions unconditionally; a NULL * graph is an error here, not a request for an unfiltered run. */ - if (!g) return ray_error("nyi", NULL); + if (!g) return ray_error("nyi", "group: no plan to run"); if (!g->selection) return exec_group_v2_run(g, op, tbl, ray_table_nrows(tbl), NULL, NULL, 0, group_limit, efp); diff --git a/src/ops/builtins.c b/src/ops/builtins.c index 6a051fb77..ba7cf8f0f 100644 --- a/src/ops/builtins.c +++ b/src/ops/builtins.c @@ -1964,7 +1964,7 @@ ray_t* ray_cast_fn(ray_t* type_sym, ray_t* val) { /* Nullable targets preserve nulls; BOOL/U8 produce ordinary values. */ if (ray_is_atom(val) && RAY_ATOM_IS_NULL(val)) { ray_t* s2 = ray_sym_str(type_sym->i64); - if (!s2) return ray_error("domain", NULL); + if (!s2) return ray_error("domain", "as: the target type symbol has no text"); const char* tn = ray_str_ptr(s2); size_t tl = ray_str_len(s2); int8_t tt = 0; @@ -1998,7 +1998,7 @@ ray_t* ray_cast_fn(ray_t* type_sym, ray_t* val) { return ray_error("domain", "as: unknown target type name"); } ray_t* s = ray_sym_str(type_sym->i64); - if (!s) return ray_error("domain", NULL); + if (!s) return ray_error("domain", "as: the target type symbol has no text"); const char* tname = ray_str_ptr(s); size_t tlen = ray_str_len(s); diff --git a/src/ops/cmp.c b/src/ops/cmp.c index 3355bc145..baa2b7c6f 100644 --- a/src/ops/cmp.c +++ b/src/ops/cmp.c @@ -547,7 +547,7 @@ static ray_t* logic_map_c(ray_binary_fn fn, const char* name, ray_t* a, ray_t* b ray_t* ea = ac ? collection_elem(a, i, &la) : a; ray_t* eb = bc ? collection_elem(b, i, &lb) : b; ray_t* r = (RAY_IS_ERR(ea) || RAY_IS_ERR(eb)) - ? ray_error("type", NULL) : fn(ea, eb); + ? ray_error("type", "logic: a cell could not be read") : fn(ea, eb); if (la) ray_release(ea); if (lb) ray_release(eb); if (!r || RAY_IS_ERR(r)) { ray_release(out); return r ? r : ray_error("oom", NULL); } diff --git a/src/ops/collection.c b/src/ops/collection.c index 685d64cf4..2c707e955 100644 --- a/src/ops/collection.c +++ b/src/ops/collection.c @@ -3224,7 +3224,7 @@ ray_t* distinct_vec_eager(ray_t* x) { * when the column is met on its own): a NULL segment, a partition without * the column, then yields its rows as the type's null. */ static ray_t* parted_to_flat_vec_c(ray_t* x, const int64_t* cnt, int64_t ncnt) { - if (!x || !RAY_IS_PARTED(x->type)) return ray_error("type", NULL); + if (!x || !RAY_IS_PARTED(x->type)) return ray_error("type", "parted: the value is not a parted column"); int8_t base = (int8_t)RAY_PARTED_BASETYPE(x->type); ray_t** segs = (ray_t**)ray_data(x); int64_t total = parted_rows_counted(x, cnt, ncnt); @@ -3297,7 +3297,7 @@ static ray_t* parted_to_flat_vec_c(ray_t* x, const int64_t* cnt, int64_t ncnt) { if (!elem || RAY_IS_ERR(elem) || store_typed_elem(out, pos, elem) != 0) { if (allocated && elem && !RAY_IS_ERR(elem)) ray_release(elem); ray_release(out); - return elem && RAY_IS_ERR(elem) ? elem : ray_error("type", NULL); + return elem && RAY_IS_ERR(elem) ? elem : ray_error("type", "parted: a cell could not be read"); } if (allocated) ray_release(elem); } @@ -5166,7 +5166,7 @@ ray_t* ray_cut_fn(ray_t* vec, ray_t* idxs) { } int alloc = 0; ray_t* ie = collection_elem(idxs, i, &alloc); - if (!ie || RAY_IS_ERR(ie)) { ray_release(out); return ie ? ie : ray_error("type", NULL); } + if (!ie || RAY_IS_ERR(ie)) { ray_release(out); return ie ? ie : ray_error("type", "cut: an index answered no value"); } if (!ray_is_atom(ie) || (ie->type != -RAY_I64 && ie->type != -RAY_I32 && ie->type != -RAY_I16 && ie->type != -RAY_U8)) { @@ -5234,14 +5234,14 @@ ray_t* ray_cross_fn(ray_t* a, ray_t* b) { } int alloc_a = 0; ray_t* ae = cross_elem(a, i, &alloc_a); - if (!ae || RAY_IS_ERR(ae)) { ray_release(out); return ae ? ae : ray_error("type", NULL); } + if (!ae || RAY_IS_ERR(ae)) { ray_release(out); return ae ? ae : ray_error("type", "cross: an element answered no value"); } for (int64_t j = 0; j < nb; j++) { int alloc_b = 0; ray_t* be = cross_elem(b, j, &alloc_b); if (!be || RAY_IS_ERR(be)) { if (alloc_a) ray_release(ae); ray_release(out); - return be ? be : ray_error("type", NULL); + return be ? be : ray_error("type", "cross: an element answered no value"); } ray_t* pair = ray_list_new(2); if (!pair || RAY_IS_ERR(pair)) { diff --git a/src/ops/embedding.c b/src/ops/embedding.c index 06a0bcf79..f8b5ce496 100644 --- a/src/ops/embedding.c +++ b/src/ops/embedding.c @@ -27,6 +27,9 @@ #include "store/embmodel.h" #include "core/pool.h" #include +#include "core/errpath.h" +/* a path as messages show it: a long one by its tail (#1886) */ +#define EPATH(p) ray_err_path((p), (char[RAY_ERR_PATH_MAX + 1]){0}) /* ========================================================================== * Rayfall builtins — direct metrics, exact KNN, HNSW lifecycle/query @@ -741,7 +744,7 @@ ray_t* ray_hnsw_save_fn(ray_t* path, ray_t* h) { memcpy(buf, p, len); buf[len] = '\0'; ray_err_t err = ray_hnsw_save(idx, buf); - if (err != RAY_OK) return ray_error("io", NULL); + if (err != RAY_OK) return ray_error("io", ".emb.hnsw.set \"%s\": saving the index failed (%s)", EPATH(buf), ray_err_code_str(err)); return RAY_NULL_OBJ; } diff --git a/src/ops/exec.c b/src/ops/exec.c index b104472f9..8320d8d90 100644 --- a/src/ops/exec.c +++ b/src/ops/exec.c @@ -22,6 +22,9 @@ */ #include "ops/internal.h" +#include "core/errpath.h" +/* a path as messages show it: a long one by its tail (#1886) */ +#define EPATH(p) ray_err_path((p), (char[RAY_ERR_PATH_MAX + 1]){0}) #include "ops/colgather.h" /* ray_col_gather_slot: the refinement over encoded columns */ #include "ops/colbind.h" #include "ops/cdfuse.h" /* ray_cd_bounded_all: count distinct of an encoded scan */ @@ -575,7 +578,7 @@ static ray_t* exec_node_inner(ray_graph_t* g, ray_op_t* op); /* Broadcast a scalar atom to a column vector of nrows elements. * Returns a new vector (caller owns). On failure returns ray_error(). */ ray_t* broadcast_scalar(ray_t* atom, int64_t nrows) { - if (!atom) return ray_error("domain", NULL); + if (!atom) return ray_error("domain", "broadcast: no atom to broadcast"); if (nrows <= 0) { /* Empty table: return an empty vector of the matching type */ int8_t at = atom->type; @@ -1840,7 +1843,7 @@ static bool str_seg_fill(const str_sel_ctx_t* x, str_seg_sel_t* s, ray_col_scrat const int64_t k0 = row - v * RAY_ENC_VEC; if (k0 + piece > vv.n) { ray_scan_fail_note(x->fail, key, ray_error("corrupt", - "column %s: STR selection: vector %lld holds %d rows", s->e->path, (long long)v, vv.n)); + "column %s: STR selection: vector %lld holds %d rows", EPATH(s->e->path), (long long)v, vv.n)); return false; } const uint32_t* cd = vv.codes + k0; @@ -1859,7 +1862,7 @@ static bool str_seg_fill(const str_sel_ctx_t* x, str_seg_sel_t* s, ray_col_scrat ray_col_range_t rv; ray_t* err = ray_col_range(s->rs, row, n - at, sc, &rv); if (!err && rv.n <= 0) - err = s->e ? ray_error("range", "column %s: STR selection: empty range read at row %lld", s->e->path, (long long)row) + err = s->e ? ray_error("range", "column %s: STR selection: empty range read at row %lld", EPATH(s->e->path), (long long)row) : ray_error("range", "column %.*s: STR selection: empty range read at row %lld", x->cname_len, x->cname, (long long)row); if (err) { ray_scan_fail_note(x->fail, key, err); return false; } @@ -3975,7 +3978,7 @@ static ray_t* exec_elementwise_tree(ray_graph_t* g, ray_op_t* root) { if (state[id] != EW_NEW) continue; state[id] = EW_SEEN; ray_op_t* n = op_node(g, id); - if (!n) { result = ray_error("nyi", NULL); goto done; } + if (!n) { result = ray_error("nyi", "execute: a node of the expression is missing from the plan"); goto done; } for (int k = 0; k < n->arity; k++) { ray_op_t* c = op_child(g, n, k); if (c && op_is_elementwise(c->opcode)) { @@ -3990,7 +3993,7 @@ static ray_t* exec_elementwise_tree(ray_graph_t* g, ray_op_t* root) { while (sp > 0) { ew_ent_t e = stk[--sp]; ray_op_t* n = op_node(g, e.id); - if (!n) { result = ray_error("nyi", NULL); goto done; } + if (!n) { result = ray_error("nyi", "execute: a node of the expression is missing from the plan"); goto done; } if (e.phase == 0) { /* discover */ if (state[e.id] == EW_DONE) /* shared node, evaluated */ @@ -3999,7 +4002,7 @@ static ray_t* exec_elementwise_tree(ray_graph_t* g, ray_op_t* root) { /* Re-discovering a node whose emit is still pending means * the node is its own ancestor — a cyclic graph. Refuse * rather than read a missing value. */ - result = ray_error("nyi", NULL); + result = ray_error("nyi", "execute: the expression's plan is cyclic"); goto done; } state[e.id] = EW_PENDING; @@ -4040,7 +4043,7 @@ static ray_t* exec_elementwise_tree(ray_graph_t* g, ray_op_t* root) { ray_op_t* c = op_child(g, n, k); if (c && op_is_elementwise(c->opcode)) { in[k] = vals[c->id]; - if (!in[k]) { result = ray_error("nyi", NULL); goto emit_fail; } + if (!in[k]) { result = ray_error("nyi", "execute: an input of an element-wise node has no value"); goto emit_fail; } } else { in[k] = exec_node(g, c); /* may recurse; depth-guarded */ owned[k] = true; @@ -4309,7 +4312,7 @@ void ray_exec_memo_pop(ray_graph_t* g, const ray_exec_memo_save_t* save) { static RAY_TLS int tl_filter_depth; ray_t* exec_node(ray_graph_t* g, ray_op_t* op) { - if (!op) return ray_error("nyi", NULL); + if (!op) return ray_error("nyi", "execute: no plan node"); /* Shared node already computed: hand out a ref (the memo's own ref goes * at exec_memo_end). */ @@ -4805,17 +4808,17 @@ static ray_t* exec_keep_cols(ray_t* tbl, const int64_t* keep, int keep_n) { } static ray_t* exec_node_inner(ray_graph_t* g, ray_op_t* op) { - if (!op) return ray_error("nyi", NULL); + if (!op) return ray_error("nyi", "execute: no plan node"); switch (op->opcode) { case OP_SCAN: { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "execute: the scan node has no extension"); ray_t* scan_tbl = scan_table_of(g, ext); - if (!scan_tbl) return ray_error("schema", NULL); + if (!scan_tbl) return ray_error("schema", "execute: the scan node has no table"); ray_t* col = ray_table_col(scan_tbl, ext->sym); - if (!col) return ray_error("schema", NULL); + if (!col) return ray_error("schema", "execute: the scanned column is not in the table"); if (RAY_IS_ERR(col)) return col; /* a failed decode keeps its own code and message */ if (col->type == RAY_MAPCOMMON) return materialize_mapcommon(col); @@ -4835,7 +4838,7 @@ static ray_t* exec_node_inner(ray_graph_t* g, ray_op_t* op) { case OP_CONST: { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext || !ext->literal) return ray_error("nyi", NULL); + if (!ext || !ext->literal) return ray_error("nyi", "execute: the constant node has no value"); ray_retain(ext->literal); return ext->literal; } @@ -6655,10 +6658,10 @@ static ray_t* exec_node_inner(ray_graph_t* g, ray_op_t* op) { if (!input || RAY_IS_ERR(input)) return input; if (input->type != RAY_TABLE) { ray_release(input); - return ray_error("nyi", NULL); + return ray_error("nyi", "execute: the projection's input is not a table"); } ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) { ray_release(input); return ray_error("nyi", NULL); } + if (!ext) { ray_release(input); return ray_error("nyi", "execute: the projection node has no extension"); } uint32_t n_cols = ext->sort.n_cols; uint32_t* columns = ext->sort.columns; @@ -6723,7 +6726,7 @@ static ray_t* exec_node_inner(ray_graph_t* g, ray_op_t* op) { ray_release(result); g->table = saved_table; ray_release(input); - return vec ? vec : ray_error("nyi", NULL); + return vec ? vec : ray_error("nyi", "execute: a projected column has no value"); } /* A scalar atom becomes a one-element column, widened * below only if another column carries the input's @@ -6737,7 +6740,7 @@ static ray_t* exec_node_inner(ray_graph_t* g, ray_op_t* op) { ray_release(result); g->table = saved_table; ray_release(input); - return vec ? vec : ray_error("nyi", NULL); + return vec ? vec : ray_error("nyi", "execute: a projected column has no value"); } } /* Synthetic name: _expr_0, _expr_1, ... */ @@ -7039,7 +7042,7 @@ static ray_t* exec_node_inner(ray_graph_t* g, ray_op_t* op) { } default: - return ray_error("nyi", NULL); + return ray_error("nyi", "execute: plan opcode %d is not implemented", (int)op->opcode); } } @@ -7075,7 +7078,7 @@ ray_t* ray_result_merge(ray_t* accum, ray_t* partial) { } if (!a_col || !p_col) { ray_release(merged); - return ray_error("schema", NULL); + return ray_error("schema", "parted merge: a column is missing from a partition's result"); } ray_t* combined = ray_vec_concat(a_col, p_col); if (!combined || RAY_IS_ERR(combined)) { @@ -7137,13 +7140,13 @@ ray_t* build_segment_table(ray_t* parted_tbl, int32_t seg_idx) { * value across seg_rows elements. */ if (col->len < 2) { ray_release(seg_tbl); - return ray_error("schema", NULL); + return ray_error("schema", "parted segment: the partition key column holds fewer than 2 cells"); } ray_t** mc_ptrs = (ray_t**)ray_data(col); ray_t* kv = mc_ptrs[0]; /* key_values */ if (!kv || seg_idx >= kv->len) { ray_release(seg_tbl); - return ray_error("schema", NULL); + return ray_error("schema", "parted segment: segment %d is past the partition key", (int)seg_idx); } int8_t kv_type = kv->type; size_t esz = (size_t)ray_sym_elem_size(kv_type, kv->attrs); @@ -7178,7 +7181,7 @@ ray_t* build_segment_table(ray_t* parted_tbl, int32_t seg_idx) { } else if (RAY_IS_PARTED(m.type)) { if (seg_idx >= m.n_segs) { ray_release(seg_tbl); - return ray_error("schema", NULL); + return ray_error("schema", "parted segment: segment %d is past the column's %d segments", (int)seg_idx, (int)m.n_segs); } ray_t* seg = ray_table_parted_seg_idx(parted_tbl, c, seg_idx); if (!seg) { @@ -7235,7 +7238,7 @@ ray_t* build_segment_table(ray_t* parted_tbl, int32_t seg_idx) { * streaming should have been rejected by ray_execute(). * Error here as defense-in-depth to avoid silent duplication. */ ray_release(seg_tbl); - return ray_error("schema", NULL); + return ray_error("schema", "parted segment: a column would be gathered twice"); } } return seg_tbl; @@ -7507,7 +7510,7 @@ static _Thread_local int exec_depth; /* nesting of ray_execute on this thread * result. Do not revalidate every OP_SCAN against g->table here: graph APIs * legitimately scan derived columns produced by upstream operators. */ static ray_t* validate_scan_columns(ray_graph_t* g) { - if (!g) return ray_error("nyi", NULL); + if (!g) return ray_error("nyi", "execute: no plan"); for (uint32_t i = 0; i < g->node_count; i++) { ray_op_t* op = &g->nodes[i]; @@ -7810,7 +7813,7 @@ static ray_t* ray_execute_inner(ray_graph_t* g, ray_op_t* root, bool reset_cance g->compile_err = NULL; return e; } - return ray_error("nyi", NULL); + return ray_error("nyi", "execute: no plan to run"); } /* Lazy-init the global thread pool on first call */ @@ -7858,7 +7861,7 @@ static ray_t* ray_execute_inner(ray_graph_t* g, ray_op_t* root, bool reset_cance if (seg_count == 0) seg_count = (int32_t)m.n_segs; else if ((int32_t)m.n_segs != seg_count) - return ray_error("schema", NULL); + return ray_error("schema", "parted execute: the columns disagree on the number of partitions"); } else if (m.type != RAY_MAPCOMMON) { has_flat = true; } @@ -7956,7 +7959,7 @@ static ray_t* ray_execute_inner(ray_graph_t* g, ray_op_t* root, bool reset_cance * count, which is a schema error. Surface it rather than * silently dropping data. */ if (seg_mask && seg_mask_count != (int64_t)seg_count) - return ray_error("schema", NULL); + return ray_error("schema", "parted execute: the partition mask does not cover every partition"); ray_t* saved_table = g->table; ray_t* result = NULL; diff --git a/src/ops/expr.c b/src/ops/expr.c index da1a893fb..8fff6bcd8 100644 --- a/src/ops/expr.c +++ b/src/ops/expr.c @@ -4107,7 +4107,7 @@ static ray_t* expr_eval_full_parted(const ray_expr_t* expr, int64_t nrows) { break; } } - if (!ref_parted) { ray_release(out); return ray_error("nyi", NULL); } + if (!ref_parted) { ray_release(out); return ray_error("nyi", "parted expression: no parted column to evaluate over"); } int64_t n_segs = expr_nsegs(ref_parted); uint8_t esz = ray_elem_size(expr->out_type); diff --git a/src/ops/graph_builtin.c b/src/ops/graph_builtin.c index 281d9b2ae..92c743b18 100644 --- a/src/ops/graph_builtin.c +++ b/src/ops/graph_builtin.c @@ -172,7 +172,7 @@ ray_t* ray_graph_build_fn(ray_t** args, int64_t n) { if (src_col && RAY_IS_ERR(src_col)) return src_col; ray_t* dst_col = ray_table_col(tbl, dst_sym); if (dst_col && RAY_IS_ERR(dst_col)) return dst_col; - if (!src_col || !dst_col) return ray_error("name", NULL); + if (!src_col || !dst_col) return ray_error("name", "graph.build: the table has no %s column '%.*s'", !src_col ? "src" : "dst", (int)(ray_sym_str(!src_col ? src_sym : dst_sym) ? ray_str_len(ray_sym_str(!src_col ? src_sym : dst_sym)) : 1), ray_sym_str(!src_col ? src_sym : dst_sym) ? ray_str_ptr(ray_sym_str(!src_col ? src_sym : dst_sym)) : "?"); if (!ray_is_vec(src_col) || !ray_is_vec(dst_col)) return ray_error("type", "graph.build: src and dst columns must be vectors, got %s and %s", ray_type_name(src_col->type), ray_type_name(dst_col->type)); if (src_col->len != dst_col->len) return ray_error("length", "graph.build: src and dst columns must have equal length, got %lld and %lld", (long long)src_col->len, (long long)dst_col->len); @@ -228,7 +228,7 @@ ray_t* ray_graph_build_fn(ray_t** args, int64_t n) { } if (!w_col || !ray_is_vec(w_col)) { ray_rel_free(rel); ray_release(edges); - return ray_error("name", NULL); + return ray_error("name", "graph.build: the table has no weight column '%.*s'", (int)(ray_sym_str(weight_sym) ? ray_str_len(ray_sym_str(weight_sym)) : 1), ray_sym_str(weight_sym) ? ray_str_ptr(ray_sym_str(weight_sym)) : "?"); } if (w_col->len != src_col->len) { ray_rel_free(rel); ray_release(edges); diff --git a/src/ops/group.c b/src/ops/group.c index db4e8d4c3..aa03dedb1 100644 --- a/src/ops/group.c +++ b/src/ops/group.c @@ -5158,7 +5158,7 @@ static ray_t* reduce_result(uint16_t opcode, int8_t op_out_type, int8_t in_type, ray_t* r = ray_f64(ray_f64_fin(val)); return dur_dev ? ray_timespan_of_f64_atom(r) : r; } - default: return ray_error("nyi", NULL); + default: return ray_error("nyi", "group: aggregate opcode %d has no final value", (int)opcode); } } @@ -14017,10 +14017,10 @@ static int group_needed_cols(ray_graph_t* g, const ray_op_ext_t* ext, int64_t nc static ray_t* exec_group_parted(ray_graph_t* g, ray_op_t* op, ray_t* parted_tbl, int64_t group_limit) { int64_t ncols = ray_table_ncols(parted_tbl); - if (ncols <= 0) return ray_error("nyi", NULL); + if (ncols <= 0) return ray_error("nyi", "parted group: the table has no columns"); ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "parted group: the plan node has no extension"); uint32_t n_keys = ext->n_keys; uint32_t n_aggs = ext->n_aggs; @@ -14036,7 +14036,7 @@ static ray_t* exec_group_parted(ray_graph_t* g, ray_op_t* op, ray_t* parted_tbl, break; } } - if (n_parts <= 0) return ray_error("nyi", NULL); + if (n_parts <= 0) return ray_error("nyi", "parted group: the table has no partitions"); /* Every partition empty: the answer of an empty plain table of the same * columns (#1621) -- one row of the aggregates over no values keyless, * no group under by:. */ @@ -17576,7 +17576,7 @@ static ray_t* exec_group_run(ray_graph_t* g, ray_op_t* op, ray_t* tbl, } ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "group: the plan node has no extension"); /* group_limit is a HINT (HEAD(GROUP) fusion), not a semantic: v2 threads * it down to the radix strategy's bounded emit and the caller trims the diff --git a/src/ops/idxop.c b/src/ops/idxop.c index 97aefdb94..4bff95825 100644 --- a/src/ops/idxop.c +++ b/src/ops/idxop.c @@ -1570,7 +1570,7 @@ ray_t* ray_dict_acc_finish(ray_dict_acc_t* a, int64_t len) { if (!cs) { ray_release(codes); ray_release(first_occ); ray_release(idx); ray_dict_acc_free(a); - return ray_error("io", NULL); + return ray_error("io", "dict index: the accumulator holds no codes"); } codes->len = len; memcpy(ray_data(codes), cs, (size_t)len * 4); first_occ->len = a->n_distinct; memcpy(ray_data(first_occ), a->first_occ, (size_t)a->n_distinct * 4); diff --git a/src/ops/join.c b/src/ops/join.c index 3a8b8036c..3aa6ec13c 100644 --- a/src/ops/join.c +++ b/src/ops/join.c @@ -1872,14 +1872,14 @@ static ray_t* join_flatten_parted(ray_t* tbl) { static ray_t* exec_join_flat(ray_graph_t* g, ray_op_t* op, ray_t* left_table, ray_t* right_table) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "join: the plan node has no extension"); int64_t left_rows = ray_table_nrows(left_table); int64_t right_rows = ray_table_nrows(right_table); /* Guard: radix path stores row indices as int32_t (widened to int64_t on gather). * Chained HT path uses uint32_t. Cap at INT32_MAX for correctness. */ if (right_rows > (int64_t)INT32_MAX || left_rows > (int64_t)INT32_MAX) - return ray_error("nyi", NULL); + return ray_error("nyi", "join: a side of more than %lld rows is not supported", (long long)INT32_MAX); uint32_t n_keys = ext->join.n_join_keys; uint8_t join_type = ext->join.join_type; @@ -2891,13 +2891,13 @@ ray_t* exec_join(ray_graph_t* g, ray_op_t* op, ray_t* left_table, ray_t* right_t static ray_t* exec_antijoin_flat(ray_graph_t* g, ray_op_t* op, ray_t* left_table, ray_t* right_table) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "anti-join: the plan node has no extension"); int64_t left_rows = ray_table_nrows(left_table); int64_t right_rows = ray_table_nrows(right_table); if (right_rows > (int64_t)INT32_MAX || left_rows > (int64_t)INT32_MAX) - return ray_error("nyi", NULL); + return ray_error("nyi", "anti-join: a side of more than %lld rows is not supported", (long long)INT32_MAX); uint32_t n_keys = ext->join.n_join_keys; @@ -3234,7 +3234,7 @@ static ray_t* join_mask_flat(ray_t* left_table, ray_t* right_table, int64_t left_rows = ray_table_nrows(left_table); int64_t right_rows = ray_table_nrows(right_table); if (right_rows > (int64_t)INT32_MAX || left_rows > (int64_t)INT32_MAX) - return ray_error("nyi", NULL); + return ray_error("nyi", "join mask: a side of more than %lld rows is not supported", (long long)INT32_MAX); ray_t* mask = ray_vec_new(RAY_BOOL, left_rows); if (!mask || RAY_IS_ERR(mask)) return mask ? mask : ray_error("oom", NULL); @@ -4462,7 +4462,7 @@ ray_t* exec_window_join(ray_graph_t* g, ray_op_t* op, static ray_t* exec_window_join_flat(ray_graph_t* g, ray_op_t* op, ray_t* left_table, ray_t* right_table) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "window-join: the plan node has no extension"); uint32_t n_eq = ext->asof.n_eq_keys; uint8_t join_type = ext->asof.join_type; @@ -4473,7 +4473,7 @@ static ray_t* exec_window_join_flat(ray_graph_t* g, ray_op_t* op, /* Resolve time key */ ray_op_ext_t* time_ext = find_ext(g, ext->asof.time_key); if (!time_ext || time_ext->base.opcode != OP_SCAN) - return ray_error("nyi", NULL); + return ray_error("nyi", "window-join: the time key must be a column"); int64_t time_sym = time_ext->sym; /* Resolve equality keys. @@ -4496,7 +4496,7 @@ static ray_t* exec_window_join_flat(ray_graph_t* g, ray_op_t* op, ray_op_ext_t* ek = find_ext(g, ext->asof.eq_keys[k]); if (!ek || ek->base.opcode != OP_SCAN) { scratch_free(eqbuf_hdr); - return ray_error("nyi", NULL); + return ray_error("nyi", "window-join: an equality key must be a column"); } eq_syms[k] = ek->sym; } @@ -4516,7 +4516,7 @@ static ray_t* exec_window_join_flat(ray_graph_t* g, ray_op_t* op, } if (!lt_time_vec || !rt_time_vec) { scratch_free(eqbuf_hdr); - return ray_error("schema", NULL); + return ray_error("schema", "window-join: a time key column is missing from its table"); } int8_t time_type = lt_time_vec->type; @@ -4567,7 +4567,7 @@ static ray_t* exec_window_join_flat(ray_graph_t* g, ray_op_t* op, if (lt_time_hdr) scratch_free(lt_time_hdr); if (rt_time_hdr) scratch_free(rt_time_hdr); scratch_free(eqbuf_hdr); - return ray_error("schema", NULL); + return ray_error("schema", "window-join: an equality key column is missing from its table"); } lt_eq[k] = lv; rt_eq[k] = rv; diff --git a/src/ops/journal.c b/src/ops/journal.c index 13379b69c..35eee0cd6 100644 --- a/src/ops/journal.c +++ b/src/ops/journal.c @@ -22,6 +22,7 @@ */ #include "journal.h" +#include "core/errpath.h" #include "store/journal.h" #include "store/serde.h" #include "core/ipc.h" @@ -44,10 +45,20 @@ static const char* str_to_cpath(ray_t* s, char* buf, size_t bufsz) { } /* Map a ray_err_t into a Rayfall error object so callers can `try` them. */ -static ray_t* err_to_ray(ray_err_t e, const char* fallback) { +static ray_t* err_to_ray(ray_err_t e, const char* fallback, const char* op) { if (e == RAY_OK) return RAY_NULL_OBJ; const char* code = ray_err_code_str(e); - return ray_error(code ? code : (fallback ? fallback : "io"), NULL); + code = code ? code : (fallback ? fallback : "io"); + return ray_error(code, "%s: the journal failed (%s)", op, code); /* named (#1886) */ +} + +/* As err_to_ray, for a builtin given a path: it names the path too. */ +static ray_t* err_to_ray_path(ray_err_t e, const char* op, const char* path) { + if (e == RAY_OK) return RAY_NULL_OBJ; + const char* code = ray_err_code_str(e); + code = code ? code : "io"; + char pbuf[RAY_ERR_PATH_MAX + 1]; + return ray_error(code, "%s \"%s\": the journal failed (%s)", op, ray_err_path(path, pbuf), code); } /* (.log.open args) — args is a 2-tuple (`async; "base") or (`sync; "base"). @@ -79,7 +90,7 @@ ray_t* ray_log_open_fn(ray_t** args, int64_t n) { return ray_error("type", ".log.open base path too long or not a string"); ray_err_t e = ray_journal_open_append(base, mode); - return err_to_ray(e, "io"); + return err_to_ray_path(e, ".log.open", base); } /* Checked atom construction for (.log.status). ray_bool and ray_i64 test @@ -228,7 +239,7 @@ ray_t* ray_log_write_fn(ray_t* expr) { if (written != pay_size) { ray_sys_free(payload); if (owned) ray_release(expr); - return ray_error("io", NULL); + return ray_error("io", ".log.write: serialized %lld of %lld bytes", (long long)written, (long long)pay_size); } ray_ipc_header_t hdr = { @@ -242,7 +253,7 @@ ray_t* ray_log_write_fn(ray_t* expr) { ray_err_t e = ray_journal_write_bytes(&hdr, payload, pay_size); ray_sys_free(payload); if (owned) ray_release(expr); - return err_to_ray(e, "io"); + return err_to_ray(e, "io", ".log.write"); } /* Prepare the private report BEFORE evaluating any journal entry. A result- @@ -340,7 +351,7 @@ ray_t* ray_log_validate_fn(ray_t* path) { int64_t chunks = 0, valid_bytes = 0; ray_err_t e = ray_journal_validate(p, &chunks, &valid_bytes); - if (e != RAY_OK) return err_to_ray(e, "io"); + if (e != RAY_OK) return err_to_ray_path(e, ".log.validate", p); ray_t* list = ray_list_new(2); ray_t* a = ray_i64(chunks); @@ -363,7 +374,7 @@ ray_t* ray_log_roll_fn(ray_t** args, int64_t n) { if (n != 0) return ray_error("arity", ".log.roll takes no arguments"); if (!ray_journal_is_open()) return ray_error("domain", ".log.roll: no journal open"); - return err_to_ray(ray_journal_roll(), "io"); + return err_to_ray(ray_journal_roll(), "io", ".log.roll"); } ray_t* ray_log_snapshot_fn(ray_t** args, int64_t n) { @@ -374,7 +385,7 @@ ray_t* ray_log_snapshot_fn(ray_t** args, int64_t n) { ray_err_t e = ray_journal_snapshot(); ray_t* why = e != RAY_OK ? ray_journal_take_error() : NULL; if (why) return why; /* the serializer's own code and message */ - return err_to_ray(e, "io"); + return err_to_ray(e, "io", ".log.snapshot"); } /* (.log.posts [flag]) — the posts switch (#1608). No argument reads it; @@ -398,13 +409,13 @@ ray_t* ray_log_posts_fn(ray_t** args, int64_t n) { ray_t* ray_log_sync_fn(ray_t** args, int64_t n) { (void)args; if (n != 0) return ray_error("arity", ".log.sync takes no arguments"); - return err_to_ray(ray_journal_sync(), "io"); + return err_to_ray(ray_journal_sync(), "io", ".log.sync"); } ray_t* ray_log_close_fn(ray_t** args, int64_t n) { (void)args; if (n != 0) return ray_error("arity", ".log.close takes no arguments"); - return err_to_ray(ray_journal_close(), "io"); + return err_to_ray(ray_journal_close(), "io", ".log.close"); } /* (.log.purge) — close the active journal (if open) and unlink ALL files @@ -415,5 +426,5 @@ ray_t* ray_log_close_fn(ray_t** args, int64_t n) { ray_t* ray_log_purge_fn(ray_t** args, int64_t n) { (void)args; if (n != 0) return ray_error("arity", ".log.purge takes no arguments"); - return err_to_ray(ray_journal_purge(), "io"); + return err_to_ray(ray_journal_purge(), "io", ".log.purge"); } diff --git a/src/ops/pivot.c b/src/ops/pivot.c index dac1b219d..13a1d11a2 100644 --- a/src/ops/pivot.c +++ b/src/ops/pivot.c @@ -2124,7 +2124,7 @@ ray_t* exec_pivot(ray_graph_t* g, ray_op_t* op, ray_t* tbl) { } ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "pivot: the plan node has no extension"); uint32_t n_idx = ext->pivot.n_index; uint16_t agg_op = ext->pivot.agg_op; diff --git a/src/ops/query.c b/src/ops/query.c index a7f88642a..b868965f9 100644 --- a/src/ops/query.c +++ b/src/ops/query.c @@ -1251,7 +1251,7 @@ ray_t* ray_tbl_col_empty(ray_t* tbl, int64_t sym) { if (!seg) return ray_error("nyi", "empty column of a parted column without segments"); if (seg->type != RAY_ENCCOL) return ray_group_gather(seg, NULL, 0); ray_col_meta_t sm; - if (!ray_col_meta_of(seg, &sm)) return ray_error("schema", NULL); + if (!ray_col_meta_of(seg, &sm)) return ray_error("schema", "column: a segment's metadata cannot be read"); m.type = sm.type; m.attrs = sm.attrs; /* segment 0's SYM width */ m.enc = seg; /* and its domain */ @@ -7561,7 +7561,7 @@ static ray_t* key_range_bind(const key_range_plan_t* p, ray_col_src_t* srcs, ray if (!err) bound[k] = true; } else { plain[k] = ray_table_col(p->tbl, p->syms[k]); /* plain, or already decoded */ - if (!plain[k]) err = ray_error("schema", NULL); + if (!plain[k]) err = ray_error("schema", "key range: a key column is not in the table"); else if (RAY_IS_ERR(plain[k])) { err = plain[k]; plain[k] = NULL; } } } @@ -14432,7 +14432,7 @@ static ray_t* rw_eval_call(ray_t* e, rw_ctx_t* c, int depth) { int64_t s = ray_sym_intern(nm, (size_t)ln); ray_err_t berr = ray_env_set_local_rows(s, v, rows); ray_release(v); - if (berr != RAY_OK) { out = ray_error(ray_err_code_str(berr), NULL); break; } + if (berr != RAY_OK) { out = ray_error(ray_err_code_str(berr), "row-wise: cannot bind a local (%s)", ray_err_code_str(berr)); break; } hid = ray_sym(s); if (!hid || RAY_IS_ERR(hid)) { out = hid ? hid : ray_error("oom", NULL); break; } a = hid; @@ -14525,7 +14525,7 @@ static ray_t* rw_eval_let(ray_t* e, rw_ctx_t* c, int depth) { if (err != RAY_OK) { ray_release(v); return err == RAY_ERR_ACCESS ? ray_error("access", "restricted") - : ray_error(ray_err_code_str(err), NULL); + : ray_error(ray_err_code_str(err), "let: cannot bind a local (%s)", ray_err_code_str(err)); } return v; } @@ -22247,7 +22247,7 @@ static ray_t* hoist_do_expr(ray_t* e, hoist_ctx_t* c, int depth) { *c->cols = t2; } else { ray_err_t be = ray_env_set_local_rows(hid, v, brows[k] == 1 ? 1 : 0); - if (be != RAY_OK) { err = ray_error(ray_err_code_str(be), NULL); break; } + if (be != RAY_OK) { err = ray_error(ray_err_code_str(be), "do: cannot bind a hoisted local (%s)", ray_err_code_str(be)); break; } } ren.from[ren.n] = bn[k]; ren.to[ren.n] = hid; ren.n++; } @@ -25969,7 +25969,7 @@ static bool prune_stand_in_type_ok(int8_t t) { * `seg` — its type, SYM width and domain — read from metadata, no decode. */ static ray_t* prune_stand_in_seg(ray_t* seg) { ray_col_meta_t m; - if (!ray_col_meta_of(seg, &m)) return ray_error("schema", NULL); + if (!ray_col_meta_of(seg, &m)) return ray_error("schema", "partition prune: a segment's metadata cannot be read"); ray_t* v; if (m.type == RAY_SYM) { v = ray_sym_vec_new(m.attrs & RAY_SYM_W_MASK, 1); @@ -26030,7 +26030,7 @@ static ray_t* parted_keep_partitions(ray_t* tbl, const uint64_t* keep, int64_t n for (int64_t c = 0; c < ncols; c++) { int64_t name = ray_table_col_name(tbl, c); ray_col_meta_t m; - if (!ray_table_col_meta_idx(tbl, c, &m)) { ray_release(out); return ray_error("schema", NULL); } + if (!ray_table_col_meta_idx(tbl, c, &m)) { ray_release(out); return ray_error("schema", "partition prune: column %lld's metadata cannot be read", (long long)c); } ray_t* slot = NULL; if (m.type == RAY_MAPCOMMON) { ray_t* mc = ray_table_col_idx(tbl, c); /* MAPCOMMON: plain */ @@ -26087,7 +26087,7 @@ static ray_t* parted_keep_partitions(ray_t* tbl, const uint64_t* keep, int64_t n } else { /* shaped like any partition's segment (the pruned one may be a ragged gap) */ for (int64_t q = 0; !seg && q < n_parts; q++) seg = prune_seg(tbl, c, q); - seg = seg ? prune_stand_in_seg(seg) : ray_error("schema", NULL); + seg = seg ? prune_stand_in_seg(seg) : ray_error("schema", "partition prune: no partition has a segment of column %lld", (long long)c); if (!seg || RAY_IS_ERR(seg)) { ray_release(nw); ray_release(out); return seg ? seg : ray_error("oom", NULL); @@ -28100,7 +28100,7 @@ static ray_t* select_drop_dependent_keys(ray_t* dict, ray_t* tbl, unsigned plan) /* as the evaluator applies it: the opcode's kernel widens a narrow * column, a constant on either side */ ray_binary_fn f = (ray_binary_fn)(uintptr_t)op[i]->i64; - ray_t* v = !bc ? ray_error("schema", NULL) : RAY_IS_ERR(bc) ? bc + ray_t* v = !bc ? ray_error("schema", "select: a by: key column has no value") : RAY_IS_ERR(bc) ? bc : atomic_map_binary_op(f, RAY_FN_OPCODE(op[i]), cside[i] == 1 ? bc : c, cside[i] == 1 ? c : bc); if (v && !RAY_IS_ERR(v)) { grouped = ray_table_add_col(grouped, alias[i], v); ray_release(v); } else { ray_release(grouped); grouped = v ? v : ray_error("oom", NULL); } @@ -39712,7 +39712,7 @@ ray_t* ray_insert(ray_t** args, int64_t n) { dict_vals->len = 0; ray_free(dict_vals); ray_release(tbl); ray_release(row_orig); - return ray_error("value", NULL); + return ray_error("value", "insert: the row's key '%.*s' is not a column of the table", (int)(ray_sym_str(dk) ? ray_str_len(ray_sym_str(dk)) : 1), ray_sym_str(dk) ? ray_str_ptr(ray_sym_str(dk)) : "?"); } } row = dict_vals; @@ -41283,7 +41283,7 @@ ray_t* ray_upsert(ray_t** args, int64_t n) { for (int64_t i = 0; i < src_ncols; i++) if (ray_table_col_name(row, i) == scn) src_matches++; if (tbl_matches != 1 || src_matches != 1) { ray_release(tbl); ray_release(key_sym); ray_release(row); - return ray_error("value", NULL); + return ray_error("value", "upsert: payload column '%.*s' must appear exactly once in the target and in the payload", (int)(ray_sym_str(scn) ? ray_str_len(ray_sym_str(scn)) : 1), ray_sym_str(scn) ? ray_str_ptr(ray_sym_str(scn)) : "?"); } } @@ -41320,7 +41320,7 @@ ray_t* ray_upsert(ray_t** args, int64_t n) { if (!found) { scratch_free(keynames_hdr); ray_release(tbl); ray_release(key_sym); ray_release(row); - return ray_error("value", NULL); + return ray_error("value", "upsert: the payload has no key column '%.*s'", (int)(ray_sym_str(key_names[k]) ? ray_str_len(ray_sym_str(key_names[k])) : 1), ray_sym_str(key_names[k]) ? ray_str_ptr(ray_sym_str(key_names[k])) : "?"); } } /* Key column positions in the target. Every key name is a @@ -44144,7 +44144,7 @@ static ray_t* asof_carry_recompute(ray_t* qtab, ray_t* template, if (!dict || RAY_IS_ERR(dict)) return dict ? dict : ray_error("oom", NULL); ray_t* raw = ray_select_impl(&dict, 1, SELECT_ALIASES_RESOLVED); ray_release(dict); - if (!raw || RAY_IS_ERR(raw)) return raw ? raw : ray_error("type", NULL); + if (!raw || RAY_IS_ERR(raw)) return raw ? raw : ray_error("type", "asof-join: recomputing the carried columns answered no value"); /* Reorder group-by output (eq keys first, then aggs) back to `template`'s * column order so positional column concat stays valid next day. */ @@ -44283,7 +44283,7 @@ ray_t* ray_asof_join_fn(ray_t** args, int64_t n) { ray_t* day_r_seg = NULL; if (rseg >= 0) { day_r_seg = asof_eval_select_segment(rdict, rparted, (int32_t)rseg); - if (!day_r_seg || RAY_IS_ERR(day_r_seg)) { err = day_r_seg ? day_r_seg : ray_error("type", NULL); break; } + if (!day_r_seg || RAY_IS_ERR(day_r_seg)) { err = day_r_seg ? day_r_seg : ray_error("type", "asof-join: a right partition's select answered no value"); break; } } /* qtab = prior carry rows PREPENDED to today's quotes. Carry rows @@ -44333,13 +44333,13 @@ ray_t* ray_asof_join_fn(ray_t** args, int64_t n) { ray_release(sk); ray_release(qtab); qtab = qs; - if (!qtab || RAY_IS_ERR(qtab)) { err = qtab ? qtab : ray_error("type", NULL); qtab = NULL; if (day_r_seg) ray_release(day_r_seg); break; } + if (!qtab || RAY_IS_ERR(qtab)) { err = qtab ? qtab : ray_error("type", "asof-join: the query table answered no value"); qtab = NULL; if (day_r_seg) ray_release(day_r_seg); break; } } /* Emit this day's trades (if any) against the prevailing-quote view. */ if (lseg >= 0) { ray_t* day_l = asof_eval_select_segment(ldict, lparted, (int32_t)lseg); - if (!day_l || RAY_IS_ERR(day_l)) { err = day_l ? day_l : ray_error("type", NULL); if (qtab) ray_release(qtab); if (day_r_seg) ray_release(day_r_seg); break; } + if (!day_l || RAY_IS_ERR(day_l)) { err = day_l ? day_l : ray_error("type", "asof-join: a left partition's select answered no value"); if (qtab) ray_release(qtab); if (day_r_seg) ray_release(day_r_seg); break; } ray_t* rt; if (qtab) { rt = qtab; ray_retain(rt); } @@ -44349,14 +44349,14 @@ ray_t* ray_asof_join_fn(ray_t** args, int64_t n) { * first-appearance would (no stale carry slot invented). */ if (!empty_r) { empty_r = asof_empty_right(rdict, rparted); - if (!empty_r || RAY_IS_ERR(empty_r)) { err = empty_r ? empty_r : ray_error("type", NULL); empty_r = NULL; ray_release(day_l); if (day_r_seg) ray_release(day_r_seg); break; } + if (!empty_r || RAY_IS_ERR(empty_r)) { err = empty_r ? empty_r : ray_error("type", "asof-join: the empty right table answered no value"); empty_r = NULL; ray_release(day_l); if (day_r_seg) ray_release(day_r_seg); break; } } rt = empty_r; ray_retain(rt); } ray_t* part = ray_asof_join_core(keys_vec, day_l, rt); ray_release(day_l); ray_release(rt); - if (!part || RAY_IS_ERR(part)) { err = part ? part : ray_error("type", NULL); if (qtab) ray_release(qtab); if (day_r_seg) ray_release(day_r_seg); break; } + if (!part || RAY_IS_ERR(part)) { err = part ? part : ray_error("type", "asof-join: a partition's join answered no value"); if (qtab) ray_release(qtab); if (day_r_seg) ray_release(day_r_seg); break; } /* Same positional-concat guard for the day-to-day output * accumulation: every day's asof output must share the running @@ -44379,7 +44379,7 @@ ray_t* ray_asof_join_fn(ray_t** args, int64_t n) { * today keeps its carried row through the group-last. */ if (rseg >= 0) { ray_t* nc = asof_carry_recompute(qtab, day_r_seg, eq_names, n_eq_c); - if (!nc || RAY_IS_ERR(nc)) { err = nc ? nc : ray_error("type", NULL); if (qtab) ray_release(qtab); ray_release(day_r_seg); break; } + if (!nc || RAY_IS_ERR(nc)) { err = nc ? nc : ray_error("type", "asof-join: recomputing the carried columns answered no value"); if (qtab) ray_release(qtab); ray_release(day_r_seg); break; } if (carry) ray_release(carry); carry = nc; } diff --git a/src/ops/rerank.c b/src/ops/rerank.c index aaffa9ed7..90697e9fd 100644 --- a/src/ops/rerank.c +++ b/src/ops/rerank.c @@ -252,7 +252,7 @@ static bool rr_member_accept(int64_t node_id, void* ctx) { ray_t* exec_ann_rerank(ray_graph_t* g, ray_op_t* op, ray_t* src) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "ann rerank: the plan node has no extension"); if (!src) return ray_error("type", "ann rerank: expects a table source, got null"); if (src->type != RAY_TABLE) return ray_error("type", "ann rerank: expects a table source, got %s", ray_type_name(src->type)); @@ -261,7 +261,7 @@ ray_t* exec_ann_rerank(ray_graph_t* g, ray_op_t* op, ray_t* src) { int32_t dim = ext->rerank.dim; int64_t k = ext->rerank.k; int32_t ef = ext->rerank.ef_search; - if (!idx || !query || dim <= 0 || k <= 0) return ray_error("schema", NULL); + if (!idx || !query || dim <= 0 || k <= 0) return ray_error("schema", "ann rerank: no index, query, dimension or k"); if (dim != idx->dim) return ray_error("length", "ann rerank: query dim must match index dim %lld, got %lld", (long long)idx->dim, (long long)dim); int64_t src_rows = ray_table_nrows(src); @@ -351,7 +351,7 @@ static int rr_found_cmp(const void* a, const void* b) { ray_t* exec_knn_rerank(ray_graph_t* g, ray_op_t* op, ray_t* src) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "knn rerank: the plan node has no extension"); if (!src) return ray_error("type", "knn rerank: expects a table source, got null"); if (src->type != RAY_TABLE) return ray_error("type", "knn rerank: expects a table source, got %s", ray_type_name(src->type)); @@ -359,7 +359,7 @@ ray_t* exec_knn_rerank(ray_graph_t* g, ray_op_t* op, ray_t* src) { const float* query = ext->rerank.query_vec; int32_t dim = ext->rerank.dim; int64_t k = ext->rerank.k; - if (col_sym <= 0 || !query || dim <= 0 || k <= 0) return ray_error("schema", NULL); + if (col_sym <= 0 || !query || dim <= 0 || k <= 0) return ray_error("schema", "knn rerank: no column, query, dimension or k"); /* Special-case empty source: return a well-shaped empty result rather * than falling into the top-K code with k_eff=0. */ @@ -376,7 +376,7 @@ ray_t* exec_knn_rerank(ray_graph_t* g, ray_op_t* op, ray_t* src) { * doesn't correctly materialise RAY_LIST columns. */ ray_t* col = ray_table_col(src, col_sym); if (col && RAY_IS_ERR(col)) return col; - if (!col) return ray_error("name", NULL); + if (!col) return ray_error("name", "knn rerank: the table has no column '%.*s'", (int)(ray_sym_str(col_sym) ? ray_str_len(ray_sym_str(col_sym)) : 1), ray_sym_str(col_sym) ? ray_str_ptr(ray_sym_str(col_sym)) : "?"); /* a list of vectors, or the same in every partition of a parted table */ const bool parted = RAY_IS_PARTED(col->type) && RAY_PARTED_BASETYPE(col->type) == RAY_LIST; if (col->type != RAY_LIST && !parted) diff --git a/src/ops/sort.c b/src/ops/sort.c index 280b8e3d1..a17b009d1 100644 --- a/src/ops/sort.c +++ b/src/ops/sort.c @@ -3823,11 +3823,11 @@ ray_t* exec_sort(ray_graph_t* g, ray_op_t* op, ray_t* tbl, int64_t limit) { if (!tbl || RAY_IS_ERR(tbl)) return tbl; ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "sort: the plan node has no extension"); int64_t nrows = ray_table_nrows(tbl); int64_t ncols = ray_table_ncols(tbl); - if (ncols > 4096) return ray_error("nyi", NULL); /* stack safety */ + if (ncols > 4096) return ray_error("nyi", "sort: more than 4096 columns"); /* stack safety */ uint32_t n_sort = ext->sort.n_cols; /* ---- Top-K shortcut ---- @@ -3903,7 +3903,7 @@ ray_t* exec_sort(ray_graph_t* g, ray_op_t* op, ray_t* tbl, int64_t limit) { name ? (int)ray_str_len(name) : 0, name ? ray_str_ptr(name) : ""); } - if (!err) err = ray_error("nyi", NULL); + if (!err) err = ray_error("nyi", "sort: a sort key has no value"); for (uint32_t j = 0; j < k; j++) { if (sort_owned[j] && sort_vecs[j] && !RAY_IS_ERR(sort_vecs[j])) ray_release(sort_vecs[j]); diff --git a/src/ops/strdom.c b/src/ops/strdom.c index 6927063aa..45ddd0c93 100644 --- a/src/ops/strdom.c +++ b/src/ops/strdom.c @@ -30,6 +30,9 @@ #include #include +#include "core/errpath.h" +/* a path as messages show it: a long one by its tail (#1886) */ +#define EPATH(p) ray_err_path((p), (char[RAY_ERR_PATH_MAX + 1]){0}) /* Open addressing over the interned strings, at most half full. A slot * holds 0 (empty) or the id + 1 in its low 40 bits under a 24-bit tag from @@ -227,7 +230,7 @@ static int sd_view(sd_build_t* b, int64_t v, int64_t vrows, ray_t** err) { * vrows and b->sdict, so this cannot fire on any file */ if (got > 0 && (b->vv->n != vrows || b->vv->dict_n != b->sdict->n)) { *err = ray_error("corrupt", "column %s: string domain: vector %lld holds %d rows of %u entries", - b->se->path, (long long)v, b->vv->n, b->vv->dict_n); + EPATH(b->se->path), (long long)v, b->vv->n, b->vv->dict_n); return -1; } if (got > 0 && !b->remap) { diff --git a/src/ops/string.c b/src/ops/string.c index 57288ba21..187c3a861 100644 --- a/src/ops/string.c +++ b/src/ops/string.c @@ -2907,7 +2907,7 @@ static ray_t* concat_text_values(ray_t** args, int n_args, bool str_out) { /* CONCAT(a, b, ...) */ ray_t* exec_concat(ray_graph_t* g, ray_op_t* op) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "concat: the plan node has no extension"); int64_t raw_nargs = ext->sym; if (raw_nargs < 2 || raw_nargs > 255) return ray_error("arity", "concat: expected 2 to 255 arguments, got %lld", (long long)raw_nargs); int n_args = (int)raw_nargs; diff --git a/src/ops/strop.c b/src/ops/strop.c index e237e637c..d90b21ff1 100644 --- a/src/ops/strop.c +++ b/src/ops/strop.c @@ -898,7 +898,7 @@ ray_t* ray_split_fn(ray_t* str, ray_t* delim) { int64_t nidx = delim->len; if (nidx == 0) return RAY_NULL_OBJ; /* null for empty indices */ int64_t idx_buf[256]; - if (nidx > 256) return ray_error("limit", NULL); + if (nidx > 256) return ray_error("limit", "split: more than 256 cut positions, got %lld", (long long)nidx); split_read_cuts(delim, nidx, idx_buf); ray_t* bad_pos = split_positions_check(idx_buf, nidx, str->len); if (bad_pos) return bad_pos; @@ -958,7 +958,7 @@ ray_t* ray_split_fn(ray_t* str, ray_t* delim) { if (nidx == 0) return RAY_NULL_OBJ; /* null for empty indices */ /* Extract indices as i64 */ int64_t idx_buf[256]; - if (nidx > 256) return ray_error("limit", NULL); + if (nidx > 256) return ray_error("limit", "split: more than 256 cut positions, got %lld", (long long)nidx); split_read_cuts(delim, nidx, idx_buf); ray_t* bad_pos = split_positions_check(idx_buf, nidx, ray_is_atom(str) ? (int64_t)ray_str_len(str) : str->len); diff --git a/src/ops/system.c b/src/ops/system.c index d102eb91f..9c9107e6c 100644 --- a/src/ops/system.c +++ b/src/ops/system.c @@ -63,6 +63,9 @@ void* ray_runtime_get_sys_args(void); #include #include #include +#include "core/errpath.h" +/* a path as messages show it: a long one by its tail (#1886) */ +#define EPATH(p) ray_err_path((p), (char[RAY_ERR_PATH_MAX + 1]){0}) #include #include #include @@ -268,7 +271,11 @@ ray_t* ray_set_splayed_fn(ray_t** args, int64_t n) { const char* why = ray_col_limit_msg(); if (why) return ray_error("limit", "%s", why); } - if (err != RAY_OK) return ray_error(ray_err_code_str(err), NULL); + /* the save answers a code only, and its cleanup makes calls after the + * failing one: the reason is what the code says, never errno (#1886) */ + if (err != RAY_OK) + return ray_error(ray_err_code_str(err), ".db.splayed.set \"%s\": the save failed (%s)", + EPATH(dir), ray_err_code_str(err)); ray_retain(tbl); return tbl; @@ -371,7 +378,7 @@ ray_t* ray_get_parted_fn(ray_t** args, int64_t n) { if (!args[1] || args[1]->type != -RAY_SYM) return ray_error("type", ".db.parted.get expects a sym table name, got %s", ray_type_name(args[1]->type)); ray_t* name_atom = ray_sym_str(args[1]->i64); - if (!name_atom) return ray_error("name", NULL); + if (!name_atom) return ray_error("name", ".db.parted.get: the table name symbol has no text"); char name[256]; size_t nlen = ray_str_len(name_atom); diff --git a/src/ops/tblop.c b/src/ops/tblop.c index 8f19667bc..caf8bcacd 100644 --- a/src/ops/tblop.c +++ b/src/ops/tblop.c @@ -2092,9 +2092,10 @@ static ray_t* alter_target(ray_t** args, int64_t n, if (idx_is_atom_num) { int64_t i_check = as_i64(idx); if (i_check < 0 || i_check >= var->len) { + int64_t vlen = var->len; /* read before the release (#1886) */ ray_release(var); ray_release(idx); ray_release(val); ray_release(name_sym); - return ray_error("index", NULL); + return ray_error("index", "alter: index %lld is out of range for length %lld", (long long)i_check, (long long)vlen); } } @@ -2220,7 +2221,7 @@ static ray_t* alter_target(ray_t** args, int64_t n, nremove = 1; } else if (ray_is_vec(idx) && ray_int_key_type(idx->type)) { nremove = idx->len; - if (nremove > 256) { ray_release(idx); ray_release(name_sym); return ray_error("limit", NULL); } + if (nremove > 256) { ray_release(idx); ray_release(name_sym); return ray_error("limit", "alter: more than 256 indices to remove, got %lld", (long long)nremove); } for (int64_t i = 0; i < nremove; i++) /* an integer index vector, read in place (#1854) */ remove_idx[i] = read_col_i64(ray_data(idx), i, idx->type, idx->attrs); } else { diff --git a/src/ops/temporal.c b/src/ops/temporal.c index 84d34df31..03778373b 100644 --- a/src/ops/temporal.c +++ b/src/ops/temporal.c @@ -749,7 +749,7 @@ ray_t* exec_extract(ray_graph_t* g, ray_op_t* op) { if (!input || RAY_IS_ERR(input)) return input; ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) { ray_release(input); return ray_error("nyi", NULL); } + if (!ext) { ray_release(input); return ray_error("nyi", "extract: the plan node has no extension"); } int64_t field = ext->sym; if (field == RAY_EXTRACT_DATE || field == RAY_EXTRACT_TIME) { @@ -814,7 +814,7 @@ ray_t* exec_date_trunc(ray_graph_t* g, ray_op_t* op) { if (!input || RAY_IS_ERR(input)) return input; ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) { ray_release(input); return ray_error("nyi", NULL); } + if (!ext) { ray_release(input); return ray_error("nyi", "trunc: the plan node has no extension"); } ray_t* result = ray_temporal_truncate(input, (int)ext->sym); ray_release(input); diff --git a/src/ops/traverse.c b/src/ops/traverse.c index 6d2f5a947..f785380b3 100644 --- a/src/ops/traverse.c +++ b/src/ops/traverse.c @@ -106,10 +106,10 @@ static ray_t* exec_expand_factorized(ray_rel_t* rel, uint8_t direction, ray_t* s * Count-then-fill pattern (same as exec_join). */ ray_t* exec_expand(ray_graph_t* g, ray_op_t* op, ray_t* src_vec) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "expand: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "expand: no graph is bound to the plan node"); /* Factorized mode: emit pre-aggregated degree counts */ if (ext->graph.factorized) @@ -303,10 +303,10 @@ ray_t* exec_expand(ray_graph_t* g, ray_op_t* op, ray_t* src_vec) { /* exec_var_expand: iterative BFS with depth limit and cycle detection */ ray_t* exec_var_expand(ray_graph_t* g, ray_op_t* op, ray_t* start_vec) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "var-expand: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "var-expand: no graph is bound to the plan node"); uint8_t direction = ext->graph.direction; uint8_t min_depth = ext->graph.min_depth; @@ -490,10 +490,10 @@ cleanup:; ray_t* exec_shortest_path(ray_graph_t* g, ray_op_t* op, ray_t* src_val, ray_t* dst_val) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "shortest path: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "shortest path: no graph is bound to the plan node"); uint8_t direction = ext->graph.direction; ray_csr_t* csr = (direction == 1) ? &rel->rev : &rel->fwd; ray_csr_t* csr_rev = &rel->rev; @@ -669,10 +669,10 @@ ray_t* exec_shortest_path(ray_graph_t* g, ray_op_t* op, * -------------------------------------------------------------------------- */ ray_t* exec_pagerank(ray_graph_t* g, ray_op_t* op) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "pagerank: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "pagerank: no graph is bound to the plan node"); int64_t n = rel->fwd.n_nodes; uint16_t iters = ext->graph.max_iter; @@ -775,10 +775,10 @@ ray_t* exec_pagerank(ray_graph_t* g, ray_op_t* op) { * -------------------------------------------------------------------------- */ ray_t* exec_connected_comp(ray_graph_t* g, ray_op_t* op) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "connected components: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "connected components: no graph is bound to the plan node"); int64_t n = rel->fwd.n_nodes; if (n <= 0) return ray_error("length", "graph.connected: graph must have at least one node, got %lld", (long long)n); @@ -963,11 +963,11 @@ static double dijkstra_masked( ray_t* exec_dijkstra(ray_graph_t* g, ray_op_t* op, ray_t* src_val, ray_t* dst_val) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "dijkstra: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); - if (!rel->fwd.props) return ray_error("schema", NULL); /* need edge properties */ + if (!rel) return ray_error("schema", "dijkstra: no graph is bound to the plan node"); + if (!rel->fwd.props) return ray_error("schema", "dijkstra: the graph has no edge properties; build it with a weight column"); /* need edge properties */ int64_t n = rel->fwd.n_nodes; int64_t m = rel->fwd.n_edges; @@ -983,8 +983,8 @@ ray_t* exec_dijkstra(ray_graph_t* g, ray_op_t* op, ray_t* props = rel->fwd.props; ray_t* weight_vec = ray_table_col(props, weight_sym); if (weight_vec && RAY_IS_ERR(weight_vec)) return weight_vec; - if (!weight_vec) return ray_error("schema", NULL); - if (weight_vec->type != RAY_F64) return ray_error("schema", NULL); + if (!weight_vec) return ray_error("schema", "dijkstra: the edge properties have no weight column"); + if (weight_vec->type != RAY_F64) return ray_error("schema", "dijkstra: the weight column must be F64"); double* weights = (double*)ray_data(weight_vec); /* Dijkstra requires non-negative edge weights */ @@ -1113,14 +1113,14 @@ ray_t* exec_dijkstra(ray_graph_t* g, ray_op_t* op, /* exec_wco_join: Worst-Case Optimal Join via general Leapfrog Triejoin */ ray_t* exec_wco_join(ray_graph_t* g, ray_op_t* op) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "wco join: the plan node has no graph extension"); ray_rel_t** rels = (ray_rel_t**)ext->wco.rels; uint8_t n_rels = ext->wco.n_rels; uint8_t n_vars = ext->wco.n_vars; - if (!rels || n_rels == 0) return ray_error("schema", NULL); - if (n_vars > LFTJ_MAX_VARS) return ray_error("nyi", NULL); + if (!rels || n_rels == 0) return ray_error("schema", "wco join: no relations to join"); + if (n_vars > LFTJ_MAX_VARS) return ray_error("nyi", "wco join: more variables than the join supports"); /* Validate sorted CSR (both fwd and rev, since LFTJ may use either) */ for (uint8_t r = 0; r < n_rels; r++) { @@ -1132,7 +1132,7 @@ ray_t* exec_wco_join(ray_graph_t* g, ray_op_t* op) { lftj_enum_ctx_t ctx; memset(&ctx, 0, sizeof(ctx)); if (!lftj_build_default_plan(&ctx, rels, n_rels, n_vars)) - return ray_error("nyi", NULL); + return ray_error("nyi", "wco join: no join plan for these relations"); /* Allocate output buffers */ int64_t out_cap = 4096; @@ -1219,10 +1219,10 @@ ray_t* exec_wco_join(ray_graph_t* g, ray_op_t* op) { * -------------------------------------------------------------------------- */ ray_t* exec_louvain(ray_graph_t* g, ray_op_t* op) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "louvain: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "louvain: no graph is bound to the plan node"); int64_t n = rel->fwd.n_nodes; int64_t m = rel->fwd.n_edges; @@ -1376,10 +1376,10 @@ ray_t* exec_louvain(ray_graph_t* g, ray_op_t* op) { * -------------------------------------------------------------------------- */ ray_t* exec_degree_cent(ray_graph_t* g, ray_op_t* op) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "degree centrality: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "degree centrality: no graph is bound to the plan node"); int64_t n = rel->fwd.n_nodes; if (n <= 0) return ray_error("length", "graph.degree: graph must have at least one node, got %lld", (long long)n); @@ -1443,10 +1443,10 @@ ray_t* exec_degree_cent(ray_graph_t* g, ray_op_t* op) { * -------------------------------------------------------------------------- */ ray_t* exec_topsort(ray_graph_t* g, ray_op_t* op) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "topsort: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "topsort: no graph is bound to the plan node"); int64_t n = rel->fwd.n_nodes; if (n <= 0) return ray_error("length", "graph.topsort: graph must have at least one node, got %lld", (long long)n); @@ -1538,10 +1538,10 @@ ray_t* exec_topsort(ray_graph_t* g, ray_op_t* op) { * -------------------------------------------------------------------------- */ ray_t* exec_cluster_coeff(ray_graph_t* g, ray_op_t* op) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "clustering coefficient: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "clustering coefficient: no graph is bound to the plan node"); int64_t n = rel->fwd.n_nodes; if (n <= 0) return ray_error("length", "graph.cluster: graph must have at least one node, got %lld", (long long)n); @@ -1643,9 +1643,9 @@ ray_t* exec_cluster_coeff(ray_graph_t* g, ray_op_t* op) { * -------------------------------------------------------------------------- */ ray_t* exec_betweenness(ray_graph_t* g, ray_op_t* op) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "betweenness: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "betweenness: no graph is bound to the plan node"); int64_t n = rel->fwd.n_nodes; if (n <= 0) return ray_error("length", "graph.betweenness: graph must have at least one node, got %lld", (long long)n); @@ -1831,9 +1831,9 @@ ray_t* exec_betweenness(ray_graph_t* g, ray_op_t* op) { * -------------------------------------------------------------------------- */ ray_t* exec_closeness(ray_graph_t* g, ray_op_t* op) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "closeness: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "closeness: no graph is bound to the plan node"); int64_t n = rel->fwd.n_nodes; if (n <= 0) return ray_error("length", "graph.closeness: graph must have at least one node, got %lld", (long long)n); @@ -1980,9 +1980,9 @@ static bool uf_union(int64_t* parent, int64_t* rank_arr, int64_t a, int64_t b) { ray_t* exec_mst(ray_graph_t* g, ray_op_t* op) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "mst: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel || !rel->fwd.props) return ray_error("schema", NULL); + if (!rel || !rel->fwd.props) return ray_error("schema", "mst: the graph has no edge properties; build it with a weight column"); int64_t n = rel->fwd.n_nodes; int64_t m = rel->fwd.n_edges; @@ -1991,7 +1991,7 @@ ray_t* exec_mst(ray_graph_t* g, ray_op_t* op) { int64_t weight_sym = ext->graph.weight_col_sym; ray_t* weight_vec = ray_table_col(rel->fwd.props, weight_sym); if (weight_vec && RAY_IS_ERR(weight_vec)) return weight_vec; - if (!weight_vec || weight_vec->type != RAY_F64) return ray_error("schema", NULL); + if (!weight_vec || weight_vec->type != RAY_F64) return ray_error("schema", "mst: the edge properties need an F64 weight column"); double* weights = (double*)ray_data(weight_vec); int64_t* fwd_off = (int64_t*)ray_data(rel->fwd.offsets); @@ -2082,9 +2082,9 @@ ray_t* exec_mst(ray_graph_t* g, ray_op_t* op) { * -------------------------------------------------------------------------- */ ray_t* exec_random_walk(ray_graph_t* g, ray_op_t* op, ray_t* src_val) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "random walk: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "random walk: no graph is bound to the plan node"); int64_t n = rel->fwd.n_nodes; uint16_t walk_len = ext->graph.max_iter; @@ -2152,10 +2152,10 @@ ray_t* exec_random_walk(ray_graph_t* g, ray_op_t* op, ray_t* src_val) { * -------------------------------------------------------------------------- */ ray_t* exec_dfs(ray_graph_t* g, ray_op_t* op, ray_t* src_val) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "dfs: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "dfs: no graph is bound to the plan node"); int64_t n = rel->fwd.n_nodes; uint8_t max_depth = ext->graph.max_depth; @@ -2277,14 +2277,14 @@ ray_t* exec_dfs(ray_graph_t* g, ray_op_t* op, ray_t* src_val) { ray_t* exec_astar(ray_graph_t* g, ray_op_t* op, ray_t* src_val, ray_t* dst_val) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "astar: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel) return ray_error("schema", NULL); - if (!rel->fwd.props) return ray_error("schema", NULL); + if (!rel) return ray_error("schema", "astar: no graph is bound to the plan node"); + if (!rel->fwd.props) return ray_error("schema", "astar: the graph has no edge properties; build it with a weight column"); ray_t* np = (ray_t*)ext->graph.node_props; - if (!np) return ray_error("schema", NULL); + if (!np) return ray_error("schema", "astar: the graph has no node properties for the coordinates"); int64_t n = rel->fwd.n_nodes; int64_t m = rel->fwd.n_edges; @@ -2299,7 +2299,7 @@ ray_t* exec_astar(ray_graph_t* g, ray_op_t* op, int64_t weight_sym = ext->graph.weight_col_sym; ray_t* weight_vec = ray_table_col(rel->fwd.props, weight_sym); if (weight_vec && RAY_IS_ERR(weight_vec)) return weight_vec; - if (!weight_vec) return ray_error("schema", NULL); + if (!weight_vec) return ray_error("schema", "astar: the edge properties have no weight column"); double* weights_arr = (double*)ray_data(weight_vec); /* Resolve coordinate columns from node properties */ @@ -2307,7 +2307,7 @@ ray_t* exec_astar(ray_graph_t* g, ray_op_t* op, if (lat_vec && RAY_IS_ERR(lat_vec)) return lat_vec; ray_t* lon_vec = ray_table_col(np, ext->graph.coord_col_syms[1]); if (lon_vec && RAY_IS_ERR(lon_vec)) return lon_vec; - if (!lat_vec || !lon_vec) return ray_error("schema", NULL); + if (!lat_vec || !lon_vec) return ray_error("schema", "astar: the node properties have no coordinate columns"); double* lat = (double*)ray_data(lat_vec); double* lon = (double*)ray_data(lon_vec); @@ -2429,10 +2429,10 @@ ray_t* exec_astar(ray_graph_t* g, ray_op_t* op, ray_t* exec_k_shortest(ray_graph_t* g, ray_op_t* op, ray_t* src_val, ray_t* dst_val) { ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "k shortest paths: the plan node has no graph extension"); ray_rel_t* rel = (ray_rel_t*)ext->graph.rel; - if (!rel || !rel->fwd.props) return ray_error("schema", NULL); + if (!rel || !rel->fwd.props) return ray_error("schema", "k shortest paths: the graph has no edge properties; build it with a weight column"); int64_t n = rel->fwd.n_nodes; int64_t m = rel->fwd.n_edges; @@ -2446,7 +2446,7 @@ ray_t* exec_k_shortest(ray_graph_t* g, ray_op_t* op, int64_t weight_sym = ext->graph.weight_col_sym; ray_t* weight_vec = ray_table_col(rel->fwd.props, weight_sym); if (weight_vec && RAY_IS_ERR(weight_vec)) return weight_vec; - if (!weight_vec) return ray_error("schema", NULL); + if (!weight_vec) return ray_error("schema", "k shortest paths: the edge properties have no weight column"); double* weights_k = (double*)ray_data(weight_vec); int64_t* fwd_off = (int64_t*)ray_data(rel->fwd.offsets); diff --git a/src/ops/window.c b/src/ops/window.c index d2cff15a5..77930185d 100644 --- a/src/ops/window.c +++ b/src/ops/window.c @@ -955,7 +955,7 @@ ray_t* exec_window(ray_graph_t* g, ray_op_t* op, ray_t* tbl) { if (!tbl || RAY_IS_ERR(tbl)) return tbl; ray_op_ext_t* ext = find_ext(g, op->id); - if (!ext) return ray_error("nyi", NULL); + if (!ext) return ray_error("nyi", "window: the plan node has no extension"); /* Frame-spec validation: the compute path honors the whole partition, * the running frame, and fixed trailing ROWS frames. Other numeric @@ -1132,7 +1132,7 @@ ray_t* exec_window(ray_graph_t* g, ray_op_t* op, ray_t* tbl) { &sort_owned[k]); sort_descs[k] = 0; /* partition keys always ASC */ if (!sort_vecs[k] || RAY_IS_ERR(sort_vecs[k])) { - ray_t* err = sort_vecs[k] ? sort_vecs[k] : ray_error("nyi", NULL); + ray_t* err = sort_vecs[k] ? sort_vecs[k] : ray_error("nyi", "window: a partition key has no value"); for (uint32_t j = 0; j < k; j++) if (sort_owned[j] && sort_vecs[j] && !RAY_IS_ERR(sort_vecs[j])) ray_release(sort_vecs[j]); @@ -1146,7 +1146,7 @@ ray_t* exec_window(ray_graph_t* g, ray_op_t* op, ray_t* tbl) { sort_descs[n_part + k] = ext->window.order_descs[k]; if (!sort_vecs[n_part + k] || RAY_IS_ERR(sort_vecs[n_part + k])) { ray_t* err = sort_vecs[n_part + k] ? sort_vecs[n_part + k] - : ray_error("nyi", NULL); + : ray_error("nyi", "window: an order key has no value"); for (uint32_t j = 0; j < n_part + k; j++) if (sort_owned[j] && sort_vecs[j] && !RAY_IS_ERR(sort_vecs[j])) ray_release(sort_vecs[j]); @@ -1160,7 +1160,7 @@ ray_t* exec_window(ray_graph_t* g, ray_op_t* op, ray_t* tbl) { if (fi) { func_vecs[f] = win_resolve_vec(g, fi, tbl, &func_owned[f]); if (!func_vecs[f] || RAY_IS_ERR(func_vecs[f])) { - ray_t* err = func_vecs[f] ? func_vecs[f] : ray_error("nyi", NULL); + ray_t* err = func_vecs[f] ? func_vecs[f] : ray_error("nyi", "window: a function's input has no value"); for (uint32_t j = 0; j < f; j++) if (func_owned[j] && func_vecs[j] && !RAY_IS_ERR(func_vecs[j])) ray_release(func_vecs[j]); diff --git a/src/store/col.c b/src/store/col.c index beaae2b15..9a3694bcd 100644 --- a/src/store/col.c +++ b/src/store/col.c @@ -44,6 +44,17 @@ #include "vec/str.h" #include "lang/format.h" #include +#include +#include "core/errpath.h" +/* a path as messages show it: a long one by its tail (#1886) */ +#define EPATH(p) ray_err_path((p), (char[RAY_ERR_PATH_MAX + 1]){0}) +/* why a map failed: POSIX's map leaves the failing call's errno, or 0 for an + * empty file (platform.c); Windows' sets none */ +#if defined(RAY_OS_WINDOWS) +#define COL_MAP_REASON "the file cannot be mapped" +#else +#define COL_MAP_REASON (errno ? strerror(errno) : "the file is empty") +#endif #include #include #include @@ -408,24 +419,24 @@ static ray_err_t col_save_str_list(ray_t* list, FILE* f) { * -------------------------------------------------------------------------- */ static ray_t* col_load_str_list(const uint8_t* ptr, size_t remaining) { - if (remaining < 8) return ray_error("corrupt", NULL); + if (remaining < 8) return ray_error("corrupt", "column file: the string list header is truncated"); int64_t count; memcpy(&count, ptr, 8); ptr += 8; remaining -= 8; if (count < 0 || (uint64_t)count > remaining / 4) - return ray_error("corrupt", NULL); + return ray_error("corrupt", "column file: string list count %lld exceeds the file", (long long)count); ray_t* list = ray_list_new(count); if (!list || RAY_IS_ERR(list)) return list; for (int64_t i = 0; i < count; i++) { - if (remaining < 4) { ray_release(list); return ray_error("corrupt", NULL); } + if (remaining < 4) { ray_release(list); return ray_error("corrupt", "column file: the string list is truncated at entry %lld", (long long)i); } uint32_t slen; memcpy(&slen, ptr, 4); ptr += 4; remaining -= 4; - if (slen > remaining) { ray_release(list); return ray_error("corrupt", NULL); } + if (slen > remaining) { ray_release(list); return ray_error("corrupt", "column file: string %lld runs past the end of the file", (long long)i); } ray_t* s = ray_str((const char*)ptr, (size_t)slen); if (!s || RAY_IS_ERR(s)) { ray_release(list); return s; } ptr += slen; remaining -= slen; @@ -606,7 +617,7 @@ static ray_t* col_read_recursive(const uint8_t** pp, size_t* remaining) { } static ray_t* col_read_rec(const uint8_t** pp, size_t* remaining) { - if (*remaining < 1) return ray_error("corrupt", NULL); + if (*remaining < 1) return ray_error("corrupt", "column file: a value is truncated before its type byte"); int8_t type; memcpy(&type, *pp, 1); *pp += 1; *remaining -= 1; @@ -614,11 +625,11 @@ static ray_t* col_read_rec(const uint8_t** pp, size_t* remaining) { if (type < 0) { /* Atom */ if (type == -RAY_STR || type == -RAY_SYM) { - if (*remaining < 4) return ray_error("corrupt", NULL); + if (*remaining < 4) return ray_error("corrupt", "column file: a string atom is truncated"); uint32_t slen; memcpy(&slen, *pp, 4); *pp += 4; *remaining -= 4; - if (slen > *remaining) return ray_error("corrupt", NULL); + if (slen > *remaining) return ray_error("corrupt", "column file: a string atom runs past the end of the file"); if (type == -RAY_SYM) { /* Stored as a string; re-intern → runtime-domain atom. */ int64_t id = ray_sym_intern((const char*)*pp, (size_t)slen); @@ -632,14 +643,14 @@ static ray_t* col_read_rec(const uint8_t** pp, size_t* remaining) { } else if (type == -RAY_GUID) { /* GUID atom: its 16-byte value. Files written before this * held a process pointer here and were never readable. */ - if (*remaining < 16) return ray_error("corrupt", NULL); + if (*remaining < 16) return ray_error("corrupt", "column file: a guid atom is truncated"); uint8_t gb[16]; memcpy(gb, *pp, 16); *pp += 16; *remaining -= 16; return ray_guid(gb); } else { /* Fixed atom: 8 bytes */ - if (*remaining < 8) return ray_error("corrupt", NULL); + if (*remaining < 8) return ray_error("corrupt", "column file: an atom is truncated"); int64_t val; memcpy(&val, *pp, 8); *pp += 8; *remaining -= 8; @@ -655,23 +666,23 @@ static ray_t* col_read_rec(const uint8_t** pp, size_t* remaining) { if (type == RAY_SYM) { /* SYM vector stored as per-cell strings: intern each into the * global table — runtime-domain output by construction. */ - if (*remaining < 8) return ray_error("corrupt", NULL); + if (*remaining < 8) return ray_error("corrupt", "column file: the SYM vector header is truncated"); int64_t len; memcpy(&len, *pp, 8); *pp += 8; *remaining -= 8; if (len < 0 || (uint64_t)len > *remaining / 4) - return ray_error("corrupt", NULL); + return ray_error("corrupt", "column file: SYM vector length %lld exceeds the file", (long long)len); ray_t* vec = ray_sym_vec_new(RAY_SYM_W64, len); if (!vec || RAY_IS_ERR(vec)) return vec; vec->len = len; int64_t* out = (int64_t*)ray_data(vec); for (int64_t i = 0; i < len; i++) { - if (*remaining < 4) { ray_release(vec); return ray_error("corrupt", NULL); } + if (*remaining < 4) { ray_release(vec); return ray_error("corrupt", "column file: the SYM vector is truncated at cell %lld", (long long)i); } uint32_t slen; memcpy(&slen, *pp, 4); *pp += 4; *remaining -= 4; - if (slen > *remaining) { ray_release(vec); return ray_error("corrupt", NULL); } + if (slen > *remaining) { ray_release(vec); return ray_error("corrupt", "column file: SYM cell %lld runs past the end of the file", (long long)i); } int64_t id = ray_sym_intern((const char*)*pp, (size_t)slen); *pp += slen; *remaining -= slen; if (id < 0) { ray_release(vec); return ray_error("oom", NULL); } @@ -682,25 +693,25 @@ static ray_t* col_read_rec(const uint8_t** pp, size_t* remaining) { if (is_serializable_type(type)) { /* Fixed-size vector */ - if (*remaining < 8) return ray_error("corrupt", NULL); + if (*remaining < 8) return ray_error("corrupt", "column file: the vector header is truncated"); int64_t len; memcpy(&len, *pp, 8); *pp += 8; *remaining -= 8; - if (len < 0) return ray_error("corrupt", NULL); + if (len < 0) return ray_error("corrupt", "column file: negative vector length %lld", (long long)len); /* RAY_STR: read attrs byte for nulls/pool layout */ uint8_t attrs = 0; if (type == RAY_STR) { - if (*remaining < 1) return ray_error("corrupt", NULL); + if (*remaining < 1) return ray_error("corrupt", "column file: the STR vector header is truncated"); memcpy(&attrs, *pp, 1); *pp += 1; *remaining -= 1; } uint8_t esz = ray_sym_elem_size(type, attrs); if (esz > 0 && (uint64_t)len > SIZE_MAX / esz) - return ray_error("corrupt", NULL); + return ray_error("corrupt", "column file: vector length %lld overflows the address space", (long long)len); size_t data_size = (size_t)len * esz; - if (data_size > *remaining) return ray_error("corrupt", NULL); + if (data_size > *remaining) return ray_error("corrupt", "column file: the vector data is truncated (%zu bytes needed, %zu left)", data_size, *remaining); /* The nested format carries no attrs for fixed-width vectors, so * their HAS_NULLS is rebuilt from the sentinels — the source of @@ -729,13 +740,13 @@ static ray_t* col_read_rec(const uint8_t** pp, size_t* remaining) { ray_str_t* elems = (ray_str_t*)ray_data(vec); for (int64_t i = 0; i < len; i++) if (!ray_str_is_inline(&elems[i])) elems[i].hash32 = 0; - if (*remaining < 8) { ray_release(vec); return ray_error("corrupt", NULL); } + if (*remaining < 8) { ray_release(vec); return ray_error("corrupt", "column file: the STR pool header is truncated"); } uint64_t pool_size; memcpy(&pool_size, *pp, 8); *pp += 8; *remaining -= 8; if (pool_size > *remaining || pool_size > (uint64_t)INT64_MAX) { ray_release(vec); - return ray_error("corrupt", NULL); + return ray_error("corrupt", "column file: STR pool size %llu exceeds the file", (unsigned long long)pool_size); } if (pool_size > 0) { vec->str_pool = ray_alloc((size_t)pool_size); @@ -759,11 +770,11 @@ static ray_t* col_read_rec(const uint8_t** pp, size_t* remaining) { } if (type == RAY_LIST) { - if (*remaining < 8) return ray_error("corrupt", NULL); + if (*remaining < 8) return ray_error("corrupt", "column file: the list header is truncated"); int64_t count; memcpy(&count, *pp, 8); *pp += 8; *remaining -= 8; - if (count < 0) return ray_error("corrupt", NULL); + if (count < 0) return ray_error("corrupt", "column file: negative list count %lld", (long long)count); ray_t* list = ray_list_new(count); if (!list || RAY_IS_ERR(list)) return list; @@ -778,7 +789,7 @@ static ray_t* col_read_rec(const uint8_t** pp, size_t* remaining) { } if (type == RAY_TABLE) { - if (*remaining < 16) return ray_error("corrupt", NULL); + if (*remaining < 16) return ray_error("corrupt", "column file: the table header is truncated"); int64_t ncols, nrows; memcpy(&ncols, *pp, 8); *pp += 8; *remaining -= 8; @@ -786,12 +797,12 @@ static ray_t* col_read_rec(const uint8_t** pp, size_t* remaining) { *pp += 8; *remaining -= 8; (void)nrows; /* nrows is reconstructed from columns */ - if (ncols < 0) return ray_error("corrupt", NULL); + if (ncols < 0) return ray_error("corrupt", "column file: negative column count %lld", (long long)ncols); ray_t* tbl = ray_table_new(ncols); if (!tbl || RAY_IS_ERR(tbl)) return tbl; for (int64_t c = 0; c < ncols; c++) { - if (*remaining < 8) { ray_release(tbl); return ray_error("corrupt", NULL); } + if (*remaining < 8) { ray_release(tbl); return ray_error("corrupt", "column file: the table is truncated at column %lld", (long long)c); } int64_t name_sym; memcpy(&name_sym, *pp, 8); *pp += 8; *remaining -= 8; @@ -1819,7 +1830,7 @@ static ray_err_t col_validate_str_region(ray_t* hdr, const void* ptr, static ray_t* col_validate_mapped(const char* path, col_mapped_t* out) { size_t mapped_size = 0; void* ptr = ray_vm_map_file(path, &mapped_size); - if (!ptr) return ray_error("io", NULL); + if (!ptr) return ray_error("io", "column \"%s\": cannot map the file: %s", EPATH(path), COL_MAP_REASON); /* Reject extended-format files early. STRV / STRL / LIST / TABLE * encode their payload and cannot satisfy the raw 32-byte ray_t @@ -1843,7 +1854,7 @@ static ray_t* col_validate_mapped(const char* path, col_mapped_t* out) { if (mapped_size < 32) { ray_vm_unmap_file(ptr, mapped_size); - return ray_error("corrupt", NULL); + return ray_error("corrupt", "column \"%s\": the file is shorter than its 32-byte header", EPATH(path)); } ray_t* hdr = (ray_t*)ptr; @@ -1857,11 +1868,11 @@ static ray_t* col_validate_mapped(const char* path, col_mapped_t* out) { int gen = ray_col_gen_of(ptr); if (gen == RAY_ENC_GEN_VERSION) { ray_vm_unmap_file(ptr, mapped_size); - return ray_error("version", "column %s: bad format version", path); + return ray_error("version", "column %s: bad format version", EPATH(path)); } if (gen == RAY_ENC_GEN_CORRUPT) { ray_vm_unmap_file(ptr, mapped_size); - return ray_error("corrupt", "column %s: format byte and generation marker disagree", path); + return ray_error("corrupt", "column %s: format byte and generation marker disagree", EPATH(path)); } if (gen == 2) { out->gen2 = true; @@ -1879,7 +1890,7 @@ static ray_t* col_validate_mapped(const char* path, col_mapped_t* out) { } if (hdr->len < 0) { ray_vm_unmap_file(ptr, mapped_size); - return ray_error("corrupt", NULL); + return ray_error("corrupt", "column \"%s\": negative length %lld", EPATH(path), (long long)hdr->len); } uint8_t esz = ray_sym_elem_size(hdr->type, hdr->attrs); @@ -1892,12 +1903,12 @@ static ray_t* col_validate_mapped(const char* path, col_mapped_t* out) { /* Overflow check: ensure len*esz fits in size_t with 32-byte header room */ if ((uint64_t)hdr->len > (SIZE_MAX - 32) / (esz ? esz : 1)) { ray_vm_unmap_file(ptr, mapped_size); - return ray_error("io", NULL); + return ray_error("io", "column \"%s\": length %lld overflows the address space", EPATH(path), (long long)hdr->len); } size_t data_size = (size_t)hdr->len * esz; if (32 + data_size > mapped_size) { ray_vm_unmap_file(ptr, mapped_size); - return ray_error("corrupt", NULL); + return ray_error("corrupt", "column \"%s\": the file is shorter than its data", EPATH(path)); } out->data_size = data_size; @@ -1905,7 +1916,7 @@ static ray_t* col_validate_mapped(const char* path, col_mapped_t* out) { ray_err_t se = col_validate_str_region(hdr, ptr, mapped_size, out); if (se != RAY_OK) { ray_vm_unmap_file(ptr, mapped_size); - return ray_error(ray_err_code_str(se), NULL); + return ray_error(ray_err_code_str(se), "column \"%s\": the string pool region is %s", EPATH(path), se == RAY_ERR_CORRUPT ? "corrupt" : ray_err_code_str(se)); } } else { out->has_str_pool = false; @@ -1994,13 +2005,13 @@ ray_err_t ray_col_set_index_order(const char* path, int64_t code) { static ray_t* col_load_impl(const char* path, struct ray_sym_domain_s* dom, bool require_dom) { - if (!path) return ray_error("io", NULL); + if (!path) return ray_error("io", "column load: no path"); /* Read file into temp mmap for validation, then copy to buddy block. * This avoids the mmap lifecycle problem (mmod=1 blocks are never freed). */ size_t mapped_size = 0; void* ptr = ray_vm_map_file(path, &mapped_size); - if (!ptr) return ray_error("io", NULL); + if (!ptr) return ray_error("io", "column \"%s\": cannot map the file: %s", EPATH(path), COL_MAP_REASON); /* Check for extended format magic numbers (first 4 bytes) */ if (mapped_size >= 4) { @@ -2093,7 +2104,7 @@ static ray_t* col_load_impl(const char* path, struct ray_sym_domain_s* dom, ray_release(vec); return ray_error("corrupt", "column %s: saved sym count %u exceeds symfile count %lld", - path, cm.saved_sym_count, (long long)dcount); + EPATH(path), cm.saved_sym_count, (long long)dcount); } if (cm.saved_sym_count == 0) { uint32_t bound = dcount > UINT32_MAX ? UINT32_MAX : (uint32_t)dcount; @@ -2101,7 +2112,7 @@ static ray_t* col_load_impl(const char* path, struct ray_sym_domain_s* dom, vec->attrs, bound); if (sym_err != RAY_OK) { ray_release(vec); - return ray_error(ray_err_code_str(sym_err), NULL); + return ray_error(ray_err_code_str(sym_err), "column \"%s\": a SYM cell is outside the symfile's %u symbols", EPATH(path), bound); } } } else if (require_dom) { @@ -2111,20 +2122,20 @@ static ray_t* col_load_impl(const char* path, struct ray_sym_domain_s* dom, ray_release(vec); return ray_error("sym", "column %s: SYM data but no symfile resolved " - "(missing /.sym -- a file named \"sym\" is not read -- or explicit sym argument)", path); + "(missing /.sym -- a file named \"sym\" is not read -- or explicit sym argument)", EPATH(path)); } else { /* Bare load: process-local runtime-id semantics. */ vec->sym_domain = ray_sym_runtime_domain(); uint32_t cur_sc = ray_sym_count(); if (cm.saved_sym_count > 0 && cur_sc > 0 && cur_sc < cm.saved_sym_count) { ray_release(vec); - return ray_error("corrupt", NULL); + return ray_error("corrupt", "column \"%s\": saved with %u symbols, the runtime table holds %u", EPATH(path), cm.saved_sym_count, cur_sc); } ray_err_t sym_err = validate_sym_bounds(ray_data(vec), vec->len, vec->attrs, cur_sc); if (sym_err != RAY_OK) { ray_release(vec); - return ray_error(ray_err_code_str(sym_err), NULL); + return ray_error(ray_err_code_str(sym_err), "column \"%s\": a SYM cell is outside the runtime table's %u symbols", EPATH(path), cur_sc); } } } @@ -2153,7 +2164,7 @@ ray_t* ray_col_load_dom(const char* path, struct ray_sym_domain_s* dom) { static ray_t* col_mmap_impl(const char* path, struct ray_sym_domain_s* dom, bool require_dom) { - if (!path) return ray_error("io", NULL); + if (!path) return ray_error("io", "column map: no path"); col_mapped_t cm = {0}; ray_t* err = col_validate_mapped(path, &cm); @@ -2176,7 +2187,7 @@ static ray_t* col_mmap_impl(const char* path, struct ray_sym_domain_s* dom, ray_vm_unmap_file(cm.mapped, cm.mapped_size); return ray_error("corrupt", "column %s: saved sym count %u exceeds symfile count %lld", - path, cm.saved_sym_count, (long long)dcount); + EPATH(path), cm.saved_sym_count, (long long)dcount); } if (cm.saved_sym_count == 0) { uint32_t bound = dcount > UINT32_MAX ? UINT32_MAX @@ -2185,14 +2196,14 @@ static ray_t* col_mmap_impl(const char* path, struct ray_sym_domain_s* dom, (const char*)cm.mapped + 32, vec->len, vec->attrs, bound); if (sym_err != RAY_OK) { ray_vm_unmap_file(cm.mapped, cm.mapped_size); - return ray_error(ray_err_code_str(sym_err), NULL); + return ray_error(ray_err_code_str(sym_err), "column \"%s\": a SYM cell is outside the symfile's %u symbols", EPATH(path), bound); } } } else if (require_dom) { ray_vm_unmap_file(cm.mapped, cm.mapped_size); return ray_error("sym", "column %s: SYM data but no symfile resolved " - "(missing /.sym -- a file named \"sym\" is not read -- or explicit sym argument)", path); + "(missing /.sym -- a file named \"sym\" is not read -- or explicit sym argument)", EPATH(path)); } else { /* Bare load: process-local runtime-id semantics. Fast-reject a * file whose saved dictionary count exceeds the live table — it @@ -2201,13 +2212,13 @@ static ray_t* col_mmap_impl(const char* path, struct ray_sym_domain_s* dom, if (cm.saved_sym_count > 0 && cur_sc > 0 && cur_sc < cm.saved_sym_count) { ray_vm_unmap_file(cm.mapped, cm.mapped_size); - return ray_error("corrupt", NULL); + return ray_error("corrupt", "column \"%s\": saved with %u symbols, the runtime table holds %u", EPATH(path), cm.saved_sym_count, cur_sc); } ray_err_t sym_err = validate_sym_bounds( (const char*)cm.mapped + 32, vec->len, vec->attrs, cur_sc); if (sym_err != RAY_OK) { ray_vm_unmap_file(cm.mapped, cm.mapped_size); - return ray_error(ray_err_code_str(sym_err), NULL); + return ray_error(ray_err_code_str(sym_err), "column \"%s\": a SYM cell is outside the runtime table's %u symbols", EPATH(path), cur_sc); } } } diff --git a/src/store/colwrite.c b/src/store/colwrite.c index 26b0ddb1b..1a9f107c6 100644 --- a/src/store/colwrite.c +++ b/src/store/colwrite.c @@ -39,6 +39,9 @@ #include #include #include +#include "core/errpath.h" +/* a path as messages show it: a long one by its tail (#1886) */ +#define EPATH(p) ray_err_path((p), (char[RAY_ERR_PATH_MAX + 1]){0}) /* tmp -> fsync (durable) -> rename -> dir sync; removes a stale .link * sidecar (generation-2 columns are never linked). */ @@ -103,7 +106,7 @@ static void colw_region_msg(const char* path) { if (!m || strncmp(m, "index region:", 13) != 0) return; char copy[256]; snprintf(copy, sizeof copy, "%s", m); - ray_error_free(ray_error("io", "column %s: %s", path, copy)); /* sets the message; code unused */ + ray_error_free(ray_error("io", "column %s: %s", EPATH(path), copy)); /* sets the message; code unused */ } static ray_err_t colw_gen2_vec(ray_t* vec, const char* path, bool durable, uint8_t ik_override, diff --git a/src/store/enccol.c b/src/store/enccol.c index 3e62f456e..5d418638c 100644 --- a/src/store/enccol.c +++ b/src/store/enccol.c @@ -42,6 +42,9 @@ #include #include #include +#include "core/errpath.h" +/* a path as messages show it: a long one by its tail (#1886) */ +#define EPATH(p) ray_err_path((p), (char[RAY_ERR_PATH_MAX + 1]){0}) ray_enccol_t* ray_enccol_of(ray_t* v) { if (!v || RAY_IS_ERR(v) || v->type != RAY_ENCCOL) return NULL; @@ -250,14 +253,14 @@ static ray_t* enc_parse_side_table(ray_enccol_t* e) { const uint8_t* s = e->base + e->hdr.side_off; uint64_t sl = e->hdr.side_len; uint32_t ne; memcpy(&ne, s, 4); - if (ne == 0 || ne > 3) ENC_CORRUPT("column %s: side table entry count %u", e->path, ne); - if (8 + 24ull * ne > sl) ENC_CORRUPT("column %s: side table longer than the side data", e->path); + if (ne == 0 || ne > 3) ENC_CORRUPT("column %s: side table entry count %u", EPATH(e->path), ne); + if (8 + 24ull * ne > sl) ENC_CORRUPT("column %s: side table longer than the side data", EPATH(e->path)); for (uint32_t i = 0; i < ne; i++) { const uint8_t* t = s + 8 + 24 * i; uint16_t kind; memcpy(&kind, t, 2); uint64_t off = rd_u64(t + 8), len = rd_u64(t + 16); if (len < 8 || len > sl || off > sl - len) - ENC_CORRUPT("column %s: side entry %u overruns the side data", e->path, i); + ENC_CORRUPT("column %s: side entry %u overruns the side data", EPATH(e->path), i); if (kind == RAY_ENC_SIDE_VALUE_DICT) { e->vdict_off = e->hdr.side_off + off; e->vdict_len = len; } else if (kind == RAY_ENC_SIDE_STR_DICT) { e->sdict_off = e->hdr.side_off + off; e->sdict_len = len; } else { e->fsst_off = e->hdr.side_off + off; e->fsst_len = len; } @@ -273,7 +276,7 @@ static ray_t* enc_parse_side_table(ray_enccol_t* e) { static ray_t* enc_parse_load(ray_enccol_t* e, uint32_t* saved_sym) { const uint8_t* b = e->base; uint64_t size = e->size; - if (size < RAY_ENC_DIR_OFF) ENC_CORRUPT("column %s: generation-2 file shorter than its headers", e->path); + if (size < RAY_ENC_DIR_OFF) ENC_CORRUPT("column %s: generation-2 file shorter than its headers", EPATH(e->path)); ray_t h; memcpy(&h, b, 32); uint32_t rc; memcpy(&rc, b + offsetof(ray_t, rc), 4); *saved_sym = rc; @@ -281,35 +284,35 @@ static ray_t* enc_parse_load(ray_enccol_t* e, uint32_t* saved_sym) { ray_enc_hdr_t* eh = &e->hdr; memcpy(eh, b + RAY_ENC_HDR_OFF, sizeof *eh); if (eh->header_version != RAY_ENC_HDR_VERSION) - return ray_error("version", "column %s: generation-2 header version %u", e->path, eh->header_version); + return ray_error("version", "column %s: generation-2 header version %u", EPATH(e->path), eh->header_version); if (eh->end_off != size) - ENC_CORRUPT("column %s: end offset %llu, file is %llu bytes (truncated?)", e->path, + ENC_CORRUPT("column %s: end offset %llu, file is %llu bytes (truncated?)", EPATH(e->path), (unsigned long long)eh->end_off, (unsigned long long)size); /* the directory must fit: bound len before deriving the chunk count */ if (h.len < 0 || (uint64_t)h.len > ((size - RAY_ENC_DIR_OFF) / sizeof(ray_enc_dirent_t)) * (uint64_t)RAY_ENC_CHUNK) - ENC_CORRUPT("column %s: length %lld exceeds what the file holds", e->path, (long long)h.len); + ENC_CORRUPT("column %s: length %lld exceeds what the file holds", EPATH(e->path), (long long)h.len); e->n_chunks = ray_enc_nchunks(h.len); if ((uint64_t)e->n_chunks > (size - RAY_ENC_DIR_OFF) / sizeof(ray_enc_dirent_t)) - ENC_CORRUPT("column %s: directory past the end of the file", e->path); + ENC_CORRUPT("column %s: directory past the end of the file", EPATH(e->path)); e->null_count = 0; for (int64_t c = 0; c < e->n_chunks; c++) { ray_enc_dirent_t de; memcpy(&de, b + RAY_ENC_DIR_OFF + c * sizeof de, sizeof de); if ((de.offset & 7) || de.bytes < RAY_ENC_DESC_AREA || de.offset > size || de.bytes > size - de.offset) - ENC_CORRUPT("column %s: chunk %lld at %llu, %llu bytes, overruns the file", e->path, (long long)c, + ENC_CORRUPT("column %s: chunk %lld at %llu, %llu bytes, overruns the file", EPATH(e->path), (long long)c, (unsigned long long)de.offset, (unsigned long long)de.bytes); e->null_count += de.null_count; } if (eh->side_off) { if (eh->side_len < 8 || eh->side_off > size || eh->side_len > size - eh->side_off) - ENC_CORRUPT("column %s: side data overruns the file", e->path); + ENC_CORRUPT("column %s: side data overruns the file", EPATH(e->path)); ray_t* serr = enc_parse_side_table(e); if (serr) return serr; } /* the region opens with the 80-byte wire root (spec "Index region") */ if (eh->index_off && (eh->index_off >= size || size - eh->index_off < 80)) - ENC_CORRUPT("column %s: index region overruns the file", e->path); + ENC_CORRUPT("column %s: index region overruns the file", EPATH(e->path)); return NULL; } @@ -319,7 +322,7 @@ ray_t* ray_enccol_open(void* mapped, size_t size, const char* path, * little-endian layout. */ if (!ray_enc_gen2_supported()) { ray_vm_unmap_file(mapped, size); - return ray_error("nyi", "column %s: generation 2 needs a little-endian host", path); + return ray_error("nyi", "column %s: generation 2 needs a little-endian host", EPATH(path)); } ray_file_map_t* m = (ray_file_map_t*)ray_sys_alloc(sizeof(*m)); if (!m) { ray_vm_unmap_file(mapped, size); return ray_error("oom", NULL); } @@ -340,11 +343,11 @@ ray_t* ray_enccol_open(void* mapped, size_t size, const char* path, uint32_t saved = 0; /* Descriptors and packed bodies are read in place as 8-byte words: the * format keeps every offset 8-aligned, and a mapping starts on a page. */ - ray_t* err = ((uintptr_t)mapped & 7) ? ray_error("nyi", "column %s: mapping not 8-aligned", e->path) + ray_t* err = ((uintptr_t)mapped & 7) ? ray_error("nyi", "column %s: mapping not 8-aligned", EPATH(e->path)) : enc_parse_load(e, &saved); if (!err && e->n_chunks > 0 && e->type != RAY_GUID && e->type != RAY_STR) { e->touch_ok = ray_calloc_raw((size_t)e->n_chunks); - if (!e->touch_ok) err = ray_error("oom", "column %s: chunk flags", e->path); + if (!e->touch_ok) err = ray_error("oom", "column %s: chunk flags", EPATH(e->path)); } if (!err && e->type == RAY_SYM) { if (dom) { @@ -353,15 +356,15 @@ ray_t* ray_enccol_open(void* mapped, size_t size, const char* path, int64_t dcount = ray_sym_domain_count(dom); if (saved > 0 && (int64_t)saved > dcount) err = ray_error("corrupt", "column %s: saved sym count %u exceeds symfile count %lld", - e->path, saved, (long long)dcount); + EPATH(e->path), saved, (long long)dcount); e->dom = dom; ray_sym_domain_retain(dom); e->dom_owned = true; } else if (require_dom) { err = ray_error("sym", "column %s: SYM data but no symfile resolved " - "(missing /.sym -- a file named \"sym\" is not read -- or explicit sym argument)", e->path); + "(missing /.sym -- a file named \"sym\" is not read -- or explicit sym argument)", EPATH(e->path)); } else { /* runtime ids of another process: the live table must hold them */ uint32_t cur = ray_sym_count(); - if (saved > 0 && cur > 0 && cur < saved) err = ray_error("corrupt", "column %s: saved sym count %u exceeds %u", e->path, saved, cur); + if (saved > 0 && cur > 0 && cur < saved) err = ray_error("corrupt", "column %s: saved sym count %u exceeds %u", EPATH(e->path), saved, cur); e->dom = ray_sym_runtime_domain(); e->dom_owned = false; } } @@ -431,14 +434,14 @@ static ray_t* enc_dict_load(void* ctx, ray_enc_snap_t* fail) { ray_enccol_t* e = ctx; ray_enc_kind_t k; (void)ray_enc_value_kind(e->type, e->attrs, &k); - if (enc_alloc_fails(e)) { ray_enc_snap_set(fail, "oom", "column %s: VALUE_DICT", e->path); return NULL; } + if (enc_alloc_fails(e)) { ray_enc_snap_set(fail, "oom", "column %s: VALUE_DICT", EPATH(e->path)); return NULL; } const uint8_t* d = e->base + e->vdict_off; uint32_t n; memcpy(&n, d, 4); const size_t esz = (size_t)k.T / 8; ray_t* vals = ray_vec_new(RAY_I64, n); if (!vals || RAY_IS_ERR(vals)) { ray_error_free(vals); /* vec_new can return an owned error, not just NULL */ - ray_enc_snap_set(fail, "oom", "column %s: VALUE_DICT", e->path); + ray_enc_snap_set(fail, "oom", "column %s: VALUE_DICT", EPATH(e->path)); return NULL; } vals->len = n; @@ -481,7 +484,7 @@ static ray_t* enc_sdict_build(const ray_enccol_t* e, const char* what, const uin ray_t* b = ray_vec_new(RAY_U8, blen); if (!b || RAY_IS_ERR(b)) { if (b) ray_error_free(b); - return ray_error("oom", "column %s: %s", e->path, what); + return ray_error("oom", "column %s: %s", EPATH(e->path), what); } b->len = blen; memset(ray_data(b), 0, (size_t)blen); @@ -512,7 +515,7 @@ static int64_t enc_sdict_find(const ray_enc_sdict_t* d, const char* s, size_t le static ray_t* enc_sdict_load(void* ctx, ray_enc_snap_t* fail) { ray_enccol_t* e = ctx; - if (enc_alloc_fails(e)) { ray_enc_snap_set(fail, "oom", "column %s: STR_DICT", e->path); return NULL; } + if (enc_alloc_fails(e)) { ray_enc_snap_set(fail, "oom", "column %s: STR_DICT", EPATH(e->path)); return NULL; } const uint8_t* p = e->base + e->sdict_off; uint32_t n; memcpy(&n, p, 4); const uint64_t* offs = (const uint64_t*)(p + 8); /* 8-aligned: 32-aligned entry in a mapping */ @@ -560,7 +563,7 @@ _Static_assert(sizeof(enc_idict_blob_t) % _Alignof(ray_enc_sdict_t) == 0, "the e static ray_t* enc_idict_load(void* ctx, ray_enc_snap_t* fail) { ray_enccol_t* e = ctx; - if (enc_alloc_fails(e)) { ray_enc_snap_set(fail, "oom", "column %s: DICT", e->path); return NULL; } + if (enc_alloc_fails(e)) { ray_enc_snap_set(fail, "oom", "column %s: DICT", EPATH(e->path)); return NULL; } ray_enc_dict_view_t v; ray_enc_dict_parse(e->base + e->hdr.index_off, &v); ray_t* blob = NULL; @@ -614,9 +617,9 @@ ray_t* ray_enccol_idict_codes(ray_enccol_t* e, int64_t start, int64_t n, const i const ray_enc_idict_t* d; ray_t* err = ray_enccol_idict(e, &d); if (err) return err; - if (!d) return ray_error("type", "column %s: no DICT index", e ? e->path : "?"); + if (!d) return ray_error("type", "column %s: no DICT index", e ? EPATH(e->path) : "?"); if (start < 0 || n < 0 || start > d->len || n > d->len - start) - return ray_error("range", "column %s: DICT codes [%lld, +%lld) outside %lld rows", e->path, + return ray_error("range", "column %s: DICT codes [%lld, +%lld) outside %lld rows", EPATH(e->path), (long long)start, (long long)n, (long long)d->len); *out = d->codes + start; return NULL; @@ -629,11 +632,11 @@ static ray_t* enc_icodes_build(void* ctx, ray_enc_snap_t* fail) { const enc_idict_blob_t* d; ray_t* err = enc_idict_get(e, &d); if (err) { ray_enc_snap_take(fail, err); return NULL; } - if (!d) { ray_enc_snap_set(fail, "type", "column %s: no DICT index", e->path); return NULL; } + if (!d) { ray_enc_snap_set(fail, "type", "column %s: no DICT index", EPATH(e->path)); return NULL; } ray_t* v = enc_alloc_fails(e) ? NULL : ray_vec_new(RAY_I32, d->pub.len); if (!v || RAY_IS_ERR(v)) { if (v) ray_error_free(v); - ray_enc_snap_set(fail, "oom", "column %s: DICT codes", e->path); + ray_enc_snap_set(fail, "oom", "column %s: DICT codes", EPATH(e->path)); return NULL; } v->len = d->pub.len; @@ -657,13 +660,13 @@ ray_t* ray_enccol_idict_codes_vec(ray_enccol_t* e, ray_t** out) { * padded to 8, n symbols of 8 bytes (zero past their length). */ static ray_t* enc_fsst_load(void* ctx, ray_enc_snap_t* fail) { ray_enccol_t* e = ctx; - if (enc_alloc_fails(e)) { ray_enc_snap_set(fail, "oom", "column %s: FSST_TABLE", e->path); return NULL; } + if (enc_alloc_fails(e)) { ray_enc_snap_set(fail, "oom", "column %s: FSST_TABLE", EPATH(e->path)); return NULL; } const uint8_t* p = e->base + e->fsst_off; const uint8_t n = p[0]; ray_t* blob = ray_vec_new(RAY_U8, (int64_t)sizeof(ray_fsst_table_t)); if (!blob || RAY_IS_ERR(blob)) { if (blob) ray_error_free(blob); - ray_enc_snap_set(fail, "oom", "column %s: FSST_TABLE", e->path); + ray_enc_snap_set(fail, "oom", "column %s: FSST_TABLE", EPATH(e->path)); return NULL; } blob->len = (int64_t)sizeof(ray_fsst_table_t); @@ -1380,7 +1383,7 @@ static ray_t* decode_vec(ray_enccol_t* e, int64_t c, int j, const ray_enc_desc_t *produced = 0; if ((e->type == RAY_F32 || e->type == RAY_F64) && d->encoding == RAY_ENC_ALP && !ray_enc_fp_env_ok()) - return ray_error("fpenv", "column %s: " RAY_ENC_FPENV_MSG, e->path); + return ray_error("fpenv", "column %s: " RAY_ENC_FPENV_MSG, EPATH(e->path)); int64_t rows = chunk_rows(e, c); int vlen = (int)(rows - (int64_t)j * RAY_ENC_VEC < RAY_ENC_VEC ? rows - (int64_t)j * RAY_ENC_VEC : RAY_ENC_VEC); const uint8_t* body = NULL; uint64_t avail = 0; const uint8_t* bm = NULL; @@ -2112,7 +2115,7 @@ ray_t* ray_enccol_desc_pool_bytes(ray_enccol_t* e, int64_t c, int j, const ray_e } ray_t* ray_enccol_decode_vec(ray_enccol_t* e, int64_t vec, void* out, char* pool_out, uint64_t pool_base) { - if (vec < 0 || vec >= ray_enc_nvecs(e->len)) return ray_error("range", "column %s: vector %lld", e->path, (long long)vec); + if (vec < 0 || vec >= ray_enc_nvecs(e->len)) return ray_error("range", "column %s: vector %lld", EPATH(e->path), (long long)vec); int64_t c = vec / RAY_ENC_VECS_PER_CHUNK; int j = (int)(vec % RAY_ENC_VECS_PER_CHUNK); uint64_t nb; @@ -2123,7 +2126,7 @@ ray_t* ray_enccol_decode_vec(ray_enccol_t* e, int64_t vec, void* out, char* pool ray_t* ray_enccol_vec_pool_bytes(ray_enccol_t* e, int64_t vec, uint64_t* out) { *out = 0; - if (vec < 0 || vec >= ray_enc_nvecs(e->len)) return ray_error("range", "column %s: vector %lld", e->path, (long long)vec); + if (vec < 0 || vec >= ray_enc_nvecs(e->len)) return ray_error("range", "column %s: vector %lld", EPATH(e->path), (long long)vec); int64_t c = vec / RAY_ENC_VECS_PER_CHUNK; int j = (int)(vec % RAY_ENC_VECS_PER_CHUNK); return ray_enccol_desc_pool_bytes(e, c, j, &ray_enccol_descs(e, c)[j], out); @@ -2148,7 +2151,7 @@ static ray_t* enc_str_cell(ray_enccol_t* e, int64_t row, int64_t want, ray_enc_c const char** p, uint32_t* len) { *p = NULL; *len = 0; if (e->type != RAY_STR || row < 0 || row >= e->len) - return ray_error("range", "column %s: row %lld", e->path, (long long)row); + return ray_error("range", "column %s: row %lld", EPATH(e->path), (long long)row); const int64_t vec = row / RAY_ENC_VEC; const int i = (int)(row % RAY_ENC_VEC); const int64_t c = vec / RAY_ENC_VECS_PER_CHUNK; @@ -2156,7 +2159,7 @@ static ray_t* enc_str_cell(ray_enccol_t* e, int64_t row, int64_t want, ray_enc_c const ray_enc_desc_t* d = &ray_enccol_descs(e, c)[j]; const int64_t rows = chunk_rows(e, c); const int vlen = (int)(rows - (int64_t)j * RAY_ENC_VEC < RAY_ENC_VEC ? rows - (int64_t)j * RAY_ENC_VEC : RAY_ENC_VEC); - if (i >= vlen) return ray_error("range", "column %s: row %lld", e->path, (long long)row); + if (i >= vlen) return ray_error("range", "column %s: row %lld", EPATH(e->path), (long long)row); const uint8_t* body = NULL; uint64_t avail = 0; const uint8_t* bm = NULL; payload_parts(e, c, d, &body, &avail, &bm); if (bm && ((bm[i >> 3] >> (i & 7)) & 1)) { *p = ""; return NULL; } /* a null: the empty string, as decoded */ @@ -2265,7 +2268,7 @@ static void enc_mat_chunk(void* raw, uint32_t wid, int64_t start, int64_t end) { if (c > atomic_load_explicit(&x->lowest_failed, memory_order_relaxed)) continue; while (atomic_load_explicit(&g_hold_decode, memory_order_acquire)) ray_enc_yield(); if (ray_interrupted()) { - ray_enc_snap_set(&r->snap, "cancel", "column %s: interrupted", e->path); + ray_enc_snap_set(&r->snap, "cancel", "column %s: interrupted", EPATH(e->path)); r->failed = true; continue; } @@ -2354,11 +2357,11 @@ static ray_t* enc_str_prepass(ray_enccol_t* e, uint64_t* chunk_pool, const ray_e enc_task_res_t* res = enc_alloc_fails(e) ? NULL : ray_calloc_raw((size_t)(e->n_chunks + 1) * sizeof *res); if (!bytes || !res) { ray_free_raw(bytes); ray_free_raw(res); - return ray_error("oom", "column %s: materialize", e->path); + return ray_error("oom", "column %s: materialize", EPATH(e->path)); } if (e->n_chunks > (int64_t)UINT32_MAX) { ray_free_raw(bytes); ray_free_raw(res); - return ray_error("range", "column %s: too many chunks", e->path); + return ray_error("range", "column %s: too many chunks", EPATH(e->path)); } enc_prepass_ctx_t x = { .e = e, .bytes = bytes, .res = res }; ray_pool_t* tp = ray_pool_get(); @@ -2371,7 +2374,7 @@ static ray_t* enc_str_prepass(ray_enccol_t* e, uint64_t* chunk_pool, const ray_e for (int64_t c = 0; c < e->n_chunks; c++) { if (res[c].failed || !res[c].done) { err = res[c].failed ? ray_enc_snap_error(&res[c].snap) - : ray_error("cancel", "column %s: interrupted", e->path); + : ray_error("cancel", "column %s: interrupted", EPATH(e->path)); break; } chunk_pool[c] = total; @@ -2390,7 +2393,7 @@ static double dbl_of(int64_t b) { double d; memcpy(&d, &b, 8); return d; } * 0/0 when no value (zone_scan_int / zone_scan_float, src/ops/idxop.c). */ static ray_t* enc_synth_zone(ray_enccol_t* e) { ray_t* root = enc_alloc_fails(e) ? NULL : ray_index_new_root(RAY_IDX_ZONE, e->type, e->len); - if (!root || RAY_IS_ERR(root)) return root ? root : ray_error("oom", "column %s: zone", e->path); + if (!root || RAY_IS_ERR(root)) return root ? root : ray_error("oom", "column %s: zone", EPATH(e->path)); ray_index_t* ix = ray_index_payload(root); bool fl = enc_type_float(e->type), have = false; int64_t mn = 0, mx = 0; @@ -2416,7 +2419,7 @@ static ray_t* enc_synth_zone(ray_enccol_t* e) { * (readers accept a NULL aggs). */ static ray_t* enc_synth_chunk_zone(ray_enccol_t* e) { ray_t* root = enc_alloc_fails(e) ? NULL : ray_index_new_root(RAY_IDX_CHUNK_ZONE, e->type, e->len); - if (!root || RAY_IS_ERR(root)) return root ? root : ray_error("oom", "column %s: chunk zone", e->path); + if (!root || RAY_IS_ERR(root)) return root ? root : ray_error("oom", "column %s: chunk zone", EPATH(e->path)); ray_index_t* ix = ray_index_payload(root); uint32_t nc = (uint32_t)e->n_chunks; bool fl = enc_type_float(e->type); @@ -2436,7 +2439,7 @@ static ray_t* enc_synth_chunk_zone(ray_enccol_t* e) { if (!ix->u.chunk_zone.mins || !ix->u.chunk_zone.maxs || !ix->u.chunk_zone.null_bits || (sums && !ix->u.chunk_zone.aggs) || enc_alloc_fails(e)) { ray_release(root); - return ray_error("oom", "column %s: chunk zone", e->path); + return ray_error("oom", "column %s: chunk zone", EPATH(e->path)); } mins->len = maxs->len = nc; nb->len = (nc + 7) / 8; @@ -2486,7 +2489,7 @@ static ray_t* enc_attach_index(ray_enccol_t* e, ray_t** vp) { } else if (kind == RAY_IDX_HASH || kind == RAY_IDX_SORT || kind == RAY_IDX_BLOOM || kind == RAY_IDX_PART) { /* the nth counter's step (fail_path already failed at "materialize") */ if (enc_alloc_fails(e) || atomic_load(&g_fail_index_parse)) - return ray_error("oom", "column %s: index parse", e->path); + return ray_error("oom", "column %s: index parse", EPATH(e->path)); ray_enc_idx_view_t iv; ray_enc_index_view(e->base + e->hdr.index_off, e->hdr.end_off - e->hdr.index_off, kind, e->type, e->attrs, e->len, &iv); @@ -2498,12 +2501,12 @@ static ray_t* enc_attach_index(ray_enccol_t* e, ray_t** vp) { const char* m = ray_err_msg(perr); snprintf(msg, sizeof msg, "%s", m ? m : "index parse"); ray_error_free(perr); - return ray_error(code, "column %s: %s", e->path, msg); + return ray_error(code, "column %s: %s", EPATH(e->path), msg); } } else if (kind == RAY_IDX_DICT) { /* spec "Materialization" step 2 (P6b): both tiers, then a heap root */ if (enc_alloc_fails(e) || atomic_load(&g_fail_index_parse)) - return ray_error("oom", "column %s: index parse", e->path); + return ray_error("oom", "column %s: index parse", EPATH(e->path)); const ray_enc_idict_t* d; ray_t* cv = NULL; ray_t* err = ray_enccol_idict(e, &d); @@ -2514,7 +2517,7 @@ static ray_t* enc_attach_index(ray_enccol_t* e, ray_t** vp) { if (!root || RAY_IS_ERR(root)) { if (fo && !RAY_IS_ERR(fo)) ray_release(fo); else if (fo) ray_error_free(fo); if (root) ray_error_free(root); - return ray_error("oom", "column %s: DICT index", e->path); + return ray_error("oom", "column %s: DICT index", EPATH(e->path)); } fo->len = d->n_distinct; memcpy(ray_data(fo), d->first_occ, (size_t)d->n_distinct * 4); @@ -2525,7 +2528,7 @@ static ray_t* enc_attach_index(ray_enccol_t* e, ray_t** vp) { if (unique) { if (!root) { root = enc_alloc_fails(e) ? NULL : ray_index_new_root(RAY_IDX_NONE, e->type, e->len); - if (!root || RAY_IS_ERR(root)) return root ? root : ray_error("oom", "column %s: unique marker", e->path); + if (!root || RAY_IS_ERR(root)) return root ? root : ray_error("oom", "column %s: unique marker", EPATH(e->path)); } ray_index_payload(root)->markers |= RAY_MARK_UNIQUE; } @@ -2542,12 +2545,12 @@ uint64_t ray_enccol_test_str_pool_allocs(void) { return atomic_load(&g_str_pool_ static ray_t* enc_materialize_single(void* ctx, ray_enc_snap_t* fail) { ray_enccol_t* e = ctx; - if (ray_interrupted()) { ray_enc_snap_set(fail, "cancel", "column %s: interrupted", e->path); return NULL; } - if (enc_alloc_fails(e)) { ray_enc_snap_set(fail, "oom", "column %s: materialize", e->path); return NULL; } + if (ray_interrupted()) { ray_enc_snap_set(fail, "cancel", "column %s: interrupted", EPATH(e->path)); return NULL; } + if (enc_alloc_fails(e)) { ray_enc_snap_set(fail, "oom", "column %s: materialize", EPATH(e->path)); return NULL; } ray_t* vec = e->type == RAY_SYM ? ray_sym_vec_new(e->attrs & RAY_SYM_W_MASK, e->len) : ray_vec_new(e->type, e->len); if (!vec || RAY_IS_ERR(vec)) { - if (vec) ray_enc_snap_take(fail, vec); else ray_enc_snap_set(fail, "oom", "column %s: materialize", e->path); + if (vec) ray_enc_snap_take(fail, vec); else ray_enc_snap_set(fail, "oom", "column %s: materialize", EPATH(e->path)); return NULL; } vec->len = e->len; @@ -2559,11 +2562,11 @@ static ray_t* enc_materialize_single(void* ctx, ray_enc_snap_t* fail) { const ray_enc_sdict_t* sd = NULL; /* the dictionary first: the pool starts with it */ if ((err = ray_enccol_strdict(e, &sd)) != NULL) goto fail; chunk_pool = enc_alloc_fails(e) ? NULL : ray_alloc_raw((size_t)(e->n_chunks + 1) * sizeof(uint64_t)); - if (!chunk_pool) { err = ray_error("oom", "column %s: materialize", e->path); goto fail; } + if (!chunk_pool) { err = ray_error("oom", "column %s: materialize", EPATH(e->path)); goto fail; } if ((err = enc_str_prepass(e, chunk_pool, sd)) != NULL) goto fail; if (e->hdr.str_pool_bytes > 0) { ray_t* pool = enc_alloc_fails(e) ? NULL : ray_alloc((size_t)e->hdr.str_pool_bytes); - if (!pool || RAY_IS_ERR(pool)) { err = pool ? pool : ray_error("oom", "column %s: pool", e->path); goto fail; } + if (!pool || RAY_IS_ERR(pool)) { err = pool ? pool : ray_error("oom", "column %s: pool", EPATH(e->path)); goto fail; } pool->type = RAY_U8; pool->len = (int64_t)e->hdr.str_pool_bytes; vec->str_pool = pool; @@ -2574,7 +2577,7 @@ static ray_t* enc_materialize_single(void* ctx, ray_enc_snap_t* fail) { * order, at the pool's start (the prepass counted sd->pooled * of it, so a pool exists when any entry is pooled) */ dict_pool_off = enc_alloc_fails(e) ? NULL : ray_alloc_raw((size_t)sd->n * sizeof(uint32_t)); - if (!dict_pool_off) { err = ray_error("oom", "column %s: materialize", e->path); goto fail; } + if (!dict_pool_off) { err = ray_error("oom", "column %s: materialize", EPATH(e->path)); goto fail; } char* pb = vec->str_pool ? (char*)ray_data(vec->str_pool) : NULL; uint64_t at = 0; for (uint32_t k = 0; k < sd->n; k++) { @@ -2588,7 +2591,7 @@ static ray_t* enc_materialize_single(void* ctx, ray_enc_snap_t* fail) { } } res = enc_alloc_fails(e) ? NULL : ray_calloc_raw((size_t)(e->n_chunks + 1) * sizeof *res); - if (!res) { err = ray_error("oom", "column %s: materialize", e->path); goto fail; } + if (!res) { err = ray_error("oom", "column %s: materialize", EPATH(e->path)); goto fail; } enc_mat_ctx_t x = { .e = e, .out = (uint8_t*)ray_data(vec), .pool = vec->str_pool ? (char*)ray_data(vec->str_pool) : NULL, @@ -2596,7 +2599,7 @@ static ray_t* enc_materialize_single(void* ctx, ray_enc_snap_t* fail) { .res = res, }; atomic_init(&x.lowest_failed, INT64_MAX); - if (e->n_chunks > (int64_t)UINT32_MAX) { err = ray_error("range", "column %s: too many chunks", e->path); goto fail; } + if (e->n_chunks > (int64_t)UINT32_MAX) { err = ray_error("range", "column %s: too many chunks", EPATH(e->path)); goto fail; } ray_pool_t* tp = ray_pool_get(); if (e->n_chunks >= 2 && ray_pool_par_dispatch_ok(tp, e->n_chunks, 2)) ray_pool_dispatch_n(tp, enc_mat_chunk, &x, (uint32_t)e->n_chunks); @@ -2607,7 +2610,7 @@ static ray_t* enc_materialize_single(void* ctx, ray_enc_snap_t* fail) { for (int64_t c = 0; c < e->n_chunks; c++) if (res[c].failed || !res[c].done) { /* the lowest-numbered failing task */ if (res[c].failed) *fail = res[c].snap; - else ray_enc_snap_set(fail, "cancel", "column %s: interrupted", e->path); + else ray_enc_snap_set(fail, "cancel", "column %s: interrupted", EPATH(e->path)); ray_free_raw(res); ray_free_raw(chunk_pool); ray_free_raw(dict_pool_off); ray_release(vec); return NULL; } @@ -2739,7 +2742,7 @@ static ray_t* enc_materialize_parted(void* ctx, ray_enc_snap_t* fail) { if (!out || RAY_IS_ERR(out) || !plain || !res) { if (out && !RAY_IS_ERR(out)) ray_free(out); ray_free_raw(plain); ray_free_raw(res); - ray_enc_snap_set(fail, "oom", "column %s: parted materialize", e->path); + ray_enc_snap_set(fail, "oom", "column %s: parted materialize", EPATH(e->path)); return NULL; } out->type = e->wrapper->type; @@ -2769,7 +2772,7 @@ static ray_t* enc_materialize_parted(void* ctx, ray_enc_snap_t* fail) { for (int64_t i = 0; i < n; i++) if (res[i].failed || !res[i].done) { /* lowest-numbered failing segment */ if (res[i].failed) *fail = res[i].snap; - else ray_enc_snap_set(fail, "cancel", "column %s: interrupted", e->path); + else ray_enc_snap_set(fail, "cancel", "column %s: interrupted", EPATH(e->path)); ray_free(out); /* no segment reference was taken yet */ ray_free_raw(plain); ray_free_raw(res); return NULL; @@ -2790,7 +2793,7 @@ ray_t* ray_enccol_materialize(ray_t* encv) { /* Reject before the once/cache lookup: caller control state is not a * permanent property of the file, and workers can have distinct state. */ if ((e->type == RAY_F32 || e->type == RAY_F64) && !ray_enc_fp_env_ok()) - return ray_error("fpenv", "column %s: " RAY_ENC_FPENV_MSG, e->path); + return ray_error("fpenv", "column %s: " RAY_ENC_FPENV_MSG, EPATH(e->path)); ray_t* r = ray_enc_once_get(&e->once, &e->decoded, e->kind == RAY_ENCCOL_PARTED ? enc_materialize_parted : enc_materialize_single, e); if (r && !RAY_IS_ERR(r)) dec_note(e); diff --git a/src/store/part.c b/src/store/part.c index 44b73b61c..d74958aa0 100644 --- a/src/store/part.c +++ b/src/store/part.c @@ -43,6 +43,10 @@ #include "core/numparse.h" /* ray_parse_i64 — overflow-checked integer names */ #include "lang/format.h" /* ray_type_name */ #include +#include +#include "core/errpath.h" +/* a path as messages show it: a long one by its tail (#1886) */ +#define EPATH(p) ray_err_path((p), (char[RAY_ERR_PATH_MAX + 1]){0}) #include #include #include @@ -780,7 +784,7 @@ void ray_parted_cache_clear(void) { * -------------------------------------------------------------------------- */ ray_t* ray_read_parted(const char* db_root, const char* table_name) { - if (!db_root || !table_name) return ray_error("io", NULL); + if (!db_root || !table_name) return ray_error("io", "parted load: no root or table name"); bool trace = ray_env_flag("RAY_CSV_TRACE"); if (trace) fprintf(stderr, "parted.get: root=%s table=%s\n", db_root, table_name); @@ -788,7 +792,7 @@ ray_t* ray_read_parted(const char* db_root, const char* table_name) { /* Validate table_name: no path separators or traversal */ if (strchr(table_name, '/') || strchr(table_name, '\\') || strstr(table_name, "..") || table_name[0] == '.') - return ray_error("io", NULL); + return ray_error("io", "parted load: table name '%s' must be a plain name (no '/', '..' or leading '.')", EPATH(table_name)); /* Release unused domains before opening a possibly rebuilt root. */ ray_parted_cache_prune(); @@ -797,7 +801,7 @@ ray_t* ray_read_parted(const char* db_root, const char* table_name) { char sym_path[1024]; int sn = snprintf(sym_path, sizeof(sym_path), "%s/.sym", db_root); if (sn < 0 || (size_t)sn >= sizeof(sym_path)) - return ray_error("io", NULL); + return ray_error("io", "parted load \"%s\": the symfile path is too long", EPATH(db_root)); /* Open root/sym ONCE as the shared FILE domain for every partition's * SYM columns (sym-domain spec: partitions have no own symfiles; the @@ -1117,7 +1121,7 @@ ray_t* ray_read_parted(const char* db_root, const char* table_name) { ray_free_raw(part_dirs); if (dom) ray_sym_domain_release(dom); - return part_err ? part_err : ray_error("io", NULL); + return part_err ? part_err : ray_error("io", "parted load \"%s\": no partition of table '%s' could be read", EPATH(db_root), table_name); } /* -------------------------------------------------------------------------- @@ -1227,7 +1231,7 @@ static ray_t* empty_table_like(ray_t* tmpl) { * Returns a sorted RAY_SYM vector suitable for ray_read_parted, or an error. * -------------------------------------------------------------------------- */ ray_t* ray_parted_tables(const char* db_root) { - if (!db_root || !*db_root) return ray_error("io", NULL); + if (!db_root || !*db_root) return ray_error("io", "parted tables: no root"); char** part_dirs = NULL; int64_t part_count = 0; @@ -1286,7 +1290,7 @@ ray_t* ray_parted_tables(const char* db_root) { * (empty vector when nothing needed fixing), or an error. * -------------------------------------------------------------------------- */ ray_t* ray_parted_fill(const char* db_root) { - if (!db_root || !*db_root) return ray_error("io", NULL); + if (!db_root || !*db_root) return ray_error("io", "parted fill: no root"); char** part_dirs = NULL; int64_t part_count = 0; diff --git a/src/store/serde.c b/src/store/serde.c index 6d84d623b..ca4ecd8d4 100644 --- a/src/store/serde.c +++ b/src/store/serde.c @@ -50,6 +50,10 @@ static int64_t ser_size(ray_t* obj); /* the size pass, below */ #include "lang/eval.h" #include "lang/format.h" #include +#include +#include "core/errpath.h" +/* a path as messages show it: a long one by its tail (#1886) */ +#define EPATH(p) ray_err_path((p), (char[RAY_ERR_PATH_MAX + 1]){0}) #include /* -------------------------------------------------------------------------- @@ -2018,7 +2022,7 @@ ray_err_t ray_obj_save_ex(ray_t* obj, const char* path, ray_t** err) { ray_t* ray_obj_load(const char* path) { FILE* f = fopen(path, "rb"); - if (!f) return ray_error("io", NULL); + if (!f) { int e = errno; return ray_error("io", "load \"%s\": %s", EPATH(path), strerror(e)); } /* Check fseek/ftell return values — silent failures here let a * truncated read through as "valid empty file" or worse. */ diff --git a/src/store/splay.c b/src/store/splay.c index bef1eaced..ab5af35a0 100644 --- a/src/store/splay.c +++ b/src/store/splay.c @@ -48,6 +48,9 @@ #include #include #include +#include "core/errpath.h" +/* a path as messages show it: a long one by its tail (#1886) */ +#define EPATH(p) ray_err_path((p), (char[RAY_ERR_PATH_MAX + 1]){0}) #include #include #include @@ -1633,11 +1636,27 @@ static ray_err_t splay_copy_link(const char* from, const char* to, const char* n static ray_t* splay_append_err(ray_splay_write_t* write, ray_err_t code, ray_t* err) { ray_splay_write_finish(write, code, false); - return err ? err : ray_error(ray_err_code_str(code), NULL); + return err ? err : ray_error(ray_err_code_str(code), "splayed append: the write failed (%s)", ray_err_code_str(code)); } static ray_t* splay_append_slots(ray_t* tbl, ray_t* old, const char* cur, const char* dir, bool durable, ray_t** out, bool* sym_col); +/* The reason of a column loader's error, without its own "column : " + * or "column file: " lead: the loader of a table names the directory and + * the column already, and a path given twice could push the reason out of + * the 255-byte message (#1886). */ +static const char* splay_col_reason(const char* m) { + if (strncmp(m, "column file: ", 13) == 0) return m + 13; + if (strncmp(m, "column \"", 8) == 0) { + const char* e = strstr(m + 8, "\": "); + if (e) return e + 3; + } else if (strncmp(m, "column ", 7) == 0) { + const char* e = strstr(m + 7, ": "); + if (e) return e + 2; + } + return m; +} + static ray_t* splay_load_dom_impl(const char* dir, ray_sym_domain_t* dom, bool use_mmap, bool col_syms); @@ -1651,18 +1670,18 @@ ray_t* ray_splay_append(ray_t* tbl, const char* dir, const char* sym_path, bool if (col && RAY_IS_ERR(col)) { /* a failed decode: its code, message left in the slot */ ray_err_t derr = ray_err_from_obj(col); ray_error_free(col); - return ray_error(ray_err_code_str(derr), NULL); + return ray_error(ray_err_code_str(derr), "splayed append \"%s\": a column could not be read (%s)", EPATH(dir), ray_err_code_str(derr)); } if (splay_slot_parted(col)) return ray_error("nyi", ".db.splayed.append: a parted table; write it with " ".db.splayed.set, or append its partitions one at a time"); } ray_err_t err = splay_validate_persisted_names(tbl); - if (err != RAY_OK) return ray_error(ray_err_code_str(err), NULL); + if (err != RAY_OK) return ray_error(ray_err_code_str(err), "splayed append \"%s\": a column name cannot be stored (%s)", EPATH(dir), ray_err_code_str(err)); ray_splay_write_t write; err = ray_splay_write_begin_mode(dir, RAY_COMPRESS_ABSENT, &write); - if (err != RAY_OK) return ray_error(ray_err_code_str(err), NULL); + if (err != RAY_OK) return ray_error(ray_err_code_str(err), "splayed append \"%s\": cannot start the write (%s)", EPATH(dir), ray_err_code_str(err)); write.no_auto_index = index == RAY_INDEX_OFF; write.keep_dict = index == RAY_INDEX_ON; if (!write.staged) { @@ -1673,7 +1692,7 @@ ray_t* ray_splay_append(ray_t* tbl, const char* dir, const char* sym_path, bool const char* why = ray_col_limit_msg(); if (why) return ray_error("limit", "%s", why); } - return err == RAY_OK ? NULL : ray_error(ray_err_code_str(err), NULL); + return err == RAY_OK ? NULL : ray_error(ray_err_code_str(err), "splayed append \"%s\": the write failed (%s)", EPATH(dir), ray_err_code_str(err)); } if (write.cur_err != RAY_OK) return splay_append_err(&write, write.cur_err, NULL); @@ -1735,7 +1754,7 @@ ray_t* ray_splay_append(ray_t* tbl, const char* dir, const char* sym_path, bool const char* why = ray_col_limit_msg(); if (why) return ray_error("limit", "%s", why); } - return err == RAY_OK ? NULL : ray_error(ray_err_code_str(err), NULL); + return err == RAY_OK ? NULL : ray_error(ray_err_code_str(err), "splayed append \"%s\": the write failed (%s)", EPATH(dir), ray_err_code_str(err)); } /* The table to write: each of `old`'s columns, in its order, as a @@ -1758,7 +1777,7 @@ static ray_t* splay_append_slots(ray_t* tbl, ray_t* old, const char* cur, const for (int64_t c = 0; c < on; c++) { int64_t name_id = ray_table_col_name(old, c); ray_t* na = ray_sym_str(name_id); - if (!na) { ray_release(comb); return ray_error("corrupt", NULL); } + if (!na) { ray_release(comb); return ray_error("corrupt", "splayed append: column %lld has no name", (long long)c); } int64_t j = 0; while (j < nn && ray_table_col_name(tbl, j) != name_id) j++; if (j == nn) { @@ -1788,7 +1807,7 @@ static ray_t* splay_append_slots(ray_t* tbl, ray_t* old, const char* cur, const own |= has; shared |= !has; } ray_err_t lerr = splay_copy_link(cur, dir, ray_str_ptr(na), ray_str_len(na), durable); - if (lerr != RAY_OK) { ray_release(comb); return ray_error(ray_err_code_str(lerr), NULL); } + if (lerr != RAY_OK) { ray_release(comb); return ray_error(ray_err_code_str(lerr), "splayed append \"%s\": cannot link column '%.*s' (%s)", EPATH(dir), (int)ray_str_len(na), ray_str_ptr(na), ray_err_code_str(lerr)); } ray_t* w = ray_alloc(2 * sizeof(ray_t*)); if (!w || RAY_IS_ERR(w)) { ray_release(comb); return w ? w : ray_error("oom", NULL); } w->type = (int8_t)(RAY_PARTED_BASE + ot); @@ -1849,7 +1868,7 @@ static void splay_resolve_orders(ray_t* tbl) { static ray_t* splay_load_dom_impl(const char* dir, ray_sym_domain_t* dom, bool use_mmap, bool col_syms) { - if (!dir) return ray_error("io", NULL); + if (!dir) return ray_error("io", "splayed load: no directory"); bool trace = ray_env_flag("RAY_CSV_TRACE"); if (trace) fprintf(stderr, "splayed.get: dir=%s mmap=%d\n", dir, use_mmap ? 1 : 0); @@ -1864,13 +1883,18 @@ static ray_t* splay_load_dom_impl(const char* dir, ray_sym_domain_t* dom, if (trace) fprintf(stderr, "splayed.get: schema load failed path=%s err=%s\n", path, schema && RAY_IS_ERR(schema) ? ray_err_code(schema) : "io"); - /* .d failures from ray_col_load are bare (code, no message) — - * name the directory so a missing/corrupt table is locatable. */ + /* the directory, then the loader's own reason (#1886) */ char codebuf[8]; const char* code = schema && RAY_IS_ERR(schema) ? ray_err_code(schema) : "io"; snprintf(codebuf, sizeof(codebuf), "%s", code); + char why[256]; + const char* sm = schema && RAY_IS_ERR(schema) ? ray_err_msg(schema) : NULL; + snprintf(why, sizeof why, "%s", sm ? splay_col_reason(sm) : ""); ray_error_free(schema); - return ray_error(codebuf, "splayed %s: cannot read .d schema", dir); + char dbuf[RAY_ERR_PATH_MAX + 1]; + return why[0] + ? ray_error(codebuf, "splayed %s: cannot read .d schema: %s", ray_err_path_n(dir, dbuf, 72), why) + : ray_error(codebuf, "splayed %s: cannot read .d schema", ray_err_path(dir, dbuf)); } if (schema->type != RAY_STR) { @@ -1981,17 +2005,22 @@ static ray_t* splay_load_dom_impl(const char* dir, ray_sym_domain_t* dom, path, col && RAY_IS_ERR(col) ? ray_err_code(col) : "io"); ray_release(schema); ray_release(tbl); - /* Rich loader errors (the loud "sym", domain bounds, …) name - * the path already and propagate verbatim; only a bare code - * (e.g. plain "io" from a missing column file) gains the - * dir + column context here. */ - if (col && ray_err_msg(col) != NULL) return col; + /* The table and the column, then the loader's own reason: + * the reader of a column file knows what is wrong but not + * which file it reads (#1886). The code is the loader's. */ char codebuf[8]; snprintf(codebuf, sizeof(codebuf), "%s", col && RAY_IS_ERR(col) ? ray_err_code(col) : "io"); + char why[256]; + const char* cm = col && RAY_IS_ERR(col) ? ray_err_msg(col) : NULL; + snprintf(why, sizeof why, "%s", cm ? splay_col_reason(cm) : ""); ray_error_free(col); - return ray_error(codebuf, "splayed %s: column '%.*s' failed to load", - dir, (int)name_len, name); + char dbuf[RAY_ERR_PATH_MAX + 1]; + return why[0] + ? ray_error(codebuf, "splayed %s: column '%.*s' failed to load: %s", + ray_err_path_n(dir, dbuf, 72), (int)name_len, name, why) + : ray_error(codebuf, "splayed %s: column '%.*s' failed to load", + ray_err_path(dir, dbuf), (int)name_len, name); } ray_t* new_df = ray_table_add_col(tbl, name_id, col); diff --git a/src/vec/vec.c b/src/vec/vec.c index 167738e93..2d0b41c91 100644 --- a/src/vec/vec.c +++ b/src/vec/vec.c @@ -737,13 +737,13 @@ ray_t* ray_vec_concat(ray_t* a, ray_t* b) { for (int64_t i = 0; i < a->len; i++) { if (ray_vec_is_null((ray_t*)a, i)) { ray_err_t err = ray_vec_set_null_checked(result, i, true); - if (err != RAY_OK) { ray_release(result); return ray_error(ray_err_code_str(err), NULL); } + if (err != RAY_OK) { ray_release(result); return ray_error(ray_err_code_str(err), "concat: cannot mark a null (%s)", ray_err_code_str(err)); } } } for (int64_t i = 0; i < b->len; i++) { if (ray_vec_is_null((ray_t*)b, i)) { ray_err_t err = ray_vec_set_null_checked(result, a->len + i, true); - if (err != RAY_OK) { ray_release(result); return ray_error(ray_err_code_str(err), NULL); } + if (err != RAY_OK) { ray_release(result); return ray_error(ray_err_code_str(err), "concat: cannot mark a null (%s)", ray_err_code_str(err)); } } } } diff --git a/test/rfl/hof/eval_branch_cov.rfl b/test/rfl/hof/eval_branch_cov.rfl index a6c162642..971677a46 100644 --- a/test/rfl/hof/eval_branch_cov.rfl +++ b/test/rfl/hof/eval_branch_cov.rfl @@ -240,9 +240,9 @@ ;; error via op_storeglobal's err != RAY_OK arm (eval.c:1860). (bad_set_fn) !- reserve ;; Trap catches it; a non-raise error hands the handler its code and -;; message (none here: the opcode rebuilds the error from its code), not -;; the error object. -(try (bad_set_fn) (fn [e] e)) -- (dict [code msg] (list 'reserve "")) +;; message (the opcode rebuilds the error from its code and names the +;; binding), not the error object. +(try (bad_set_fn) (fn [e] e)) -- (dict [code msg] (list 'reserve "set: cannot bind '.sys.gc' (reserve)")) ;; (set ) — compile.c:236 special case where set's value ;; uses a slot-bound parameter (regression covered by commit 90cf600). ;; Exercises OP_STOREGLOBAL with a value compiled from a slot ref. diff --git a/test/rfl/system/error_messages_named.rfl b/test/rfl/system/error_messages_named.rfl new file mode 100644 index 000000000..d037eb177 --- /dev/null +++ b/test/rfl/system/error_messages_named.rfl @@ -0,0 +1,77 @@ +;; @requires: posix (fixtures run through a POSIX shell via .sys.exec) +;; An error names the operation and the reason, for a sample of each family +;; that raised one with an empty message (#1886). Codes are as before. +(set em (fn [f] (try (f) (fn [e] (list (get e 'code) (get e 'msg)))))) +;; eval: binding a reserved name, the generic null as an argument +(em (fn [] (set .sys.gc 1))) -- (list 'reserve "set: cannot bind '.sys.gc' (reserve)") +(em (fn [] ((fn [] (set .sys.gc 1))))) -- (list 'reserve "set: cannot bind '.sys.gc' (reserve)") +(em (fn [] (times [.sys.gc 2] 0))) -- (list 'reserve "times: '.sys.gc' is a reserved name") +(em (fn [] (neg null))) -- (list 'type "neg: the generic null is not an argument; only nil?, type and ser take it") +;; query: insert and upsert payloads +(set T (table [k v] (list [1 2] [3 4]))) +(em (fn [] (upsert T 'k (table [v] (list [5]))))) -- (list 'value "upsert: the payload has no key column 'k'") +(em (fn [] (upsert T 'k (table [k z] (list [1] [5]))))) -- (list 'value "upsert: payload column 'z' must appear exactly once in the target and in the payload") +(em (fn [] (insert T {k: 1 zz: 2}))) -- (list 'value "insert: the row's key 'zz' is not a column of the table") +;; graph +(em (fn [] (.graph.build (table [a b] (list [0 1] [1 0])) 'src 'dst))) -- (list 'name "graph.build: the table has no src column 'src'") +;; strings and tables +(em (fn [] (split "abcdef" (til 300)))) -- (list 'limit "split: more than 256 cut positions, got 300") +(em (fn [] (do (set vv [1 2 3]) (alter 'vv set 9 0)))) -- (list 'index "alter: index 9 is out of range for length 3") +;; the same on a value another name shares, read before it is released +(em (fn [] (do (set va [1 2 3]) (set vb va) (alter 'va set 9 0)))) -- (list 'index "alter: index 9 is out of range for length 3") +;; storage +(em (fn [] (.db.parted.get "/tmp/x" 'a/b))) -- (list 'io "parted load: table name 'a/b' must be a plain name (no '/', '..' or leading '.')") +(em (fn [] (.db.splayed.set "/nonexistent/x/" (table [a] (list [1]))))) -- (list 'io ".db.splayed.set \"/nonexistent/x/\": the save failed (io)") +;; a long path is shown by its tail, so the reason fits +(set lm (at (em (fn [] (.db.splayed.set (concat "/nonexistent/" (concat (take "d" 200) "/")) (table [a] (list [1]))))) 1)) +(like lm ".db.splayed.set \"...ddd*d/\": the save failed (io)") -- true +(< (count lm) 256) -- true +;; a column file a table cannot load: the table, the column and then the +;; reader's own reason, as before plus the reason (review of #1887). A +;; path is matched by its tail: a long temp root shows it so. +(.sys.exec "rm -rf /tmp/rftest_emn; mkdir -p /tmp/rftest_emn") -- 0 +(.db.splayed.set "/tmp/rftest_emn/s/" (table [a l] (list [1 2] (list [1 2] [3])))) +(.sys.exec "truncate -s 40 /tmp/rftest_emn/s/l") -- 0 +(at (em (fn [] (.db.splayed.get "/tmp/rftest_emn/s/"))) 0) -- 'corrupt +(like (at (em (fn [] (.db.splayed.get "/tmp/rftest_emn/s/"))) 1) "splayed *emn/s/: column 'l' failed to load: the vector header is truncated") -- true +(.db.splayed.set "/tmp/rftest_emn/p/2024.01.01/t/" (table [a l] (list [1 2] (list [1 2] [3])))) +(.sys.exec "truncate -s 40 /tmp/rftest_emn/p/2024.01.01/t/l") -- 0 +(at (em (fn [] (.db.parted.get "/tmp/rftest_emn/p/" 't))) 0) -- 'corrupt +(like (at (em (fn [] (.db.parted.get "/tmp/rftest_emn/p/" 't))) 1) "splayed *2024.01.01/t: column 'l' failed to load: the vector header is truncated") -- true +(.db.splayed.set "/tmp/rftest_emn/u/" (table [a] (list [1 2]))) +(.sys.exec "truncate -s 10 /tmp/rftest_emn/u/.d") -- 0 +(at (em (fn [] (.db.splayed.get "/tmp/rftest_emn/u/"))) 0) -- 'corrupt +(like (at (em (fn [] (.db.splayed.get "/tmp/rftest_emn/u/"))) 1) "splayed *emn/u/: cannot read .d schema: the file is shorter*") -- true +;; the journal builtins given a path name it +(like (at (em (fn [] (.log.validate "/tmp/rftest_emn/nolog.log"))) 1) ".log.validate \"*/nolog.log\": the journal failed (io)") -- true +(like (at (em (fn [] (.log.open 'async "/tmp/rftest_emn/nodir/x/y"))) 1) ".log.open \"*/nodir/x/y\": the journal failed (io)") -- true +(.sys.exec "rm -rf /tmp/rftest_emn; true") -- 0 +;; under a long directory the loader's reason survives: the message names +;; the directory by its tail and the column once, then the reason, never +;; the loader's own copy of the path (second review of #1887). A +;; truncation's wording differs by the file's format generation. +(set LD (concat "/tmp/rftest_eml/" (concat (take "d" 70) (concat "/" (take "e" 70))))) +(.sys.exec (concat "rm -rf /tmp/rftest_eml; mkdir -p " LD)) -- 0 +(set mk (fn [n] (.db.splayed.set (concat (concat (concat LD "/") n) "/") (table [a l] (list [1 2 3] (list [1 2] [3] [4 5])))))) +(set ld (fn [n] (try (.db.splayed.get (concat (concat (concat LD "/") n) "/")) (fn [e] (get e 'msg))))) +(set cut (fn [n f size] (.sys.exec (concat (concat (concat (concat (concat "truncate -s " size) " ") LD) (concat "/" n)) (concat "/" f))))) +(mk "t1") (cut "t1" "a" "40") -- 0 +(mk "t2") (cut "t2" "a" "10") -- 0 +(mk "t3") (.sys.exec (concat (concat "rm " LD) "/t3/a")) -- 0 +(mk "t4") (cut "t4" "l" "40") -- 0 +(mk "t5") (cut "t5" ".d" "10") -- 0 +(mk "t6") (cut "t6" "a" "0") -- 0 +(mk "t7") (.sys.exec (concat (concat "rm " LD) "/t7/.d")) -- 0 +(like (ld "t1") "splayed ...*/t1/: column 'a' failed to load: *shorter than its*") -- true +(like (ld "t2") "splayed ...*/t2/: column 'a' failed to load: *shorter than its*") -- true +(like (ld "t3") "splayed ...*/t3/: column 'a' failed to load: cannot map the file: No such file*") -- true +(like (ld "t4") "splayed ...*/t4/: column 'l' failed to load: the vector header is truncated") -- true +(like (ld "t5") "splayed ...*/t5/: cannot read .d schema: *shorter than its*") -- true +(like (ld "t6") "splayed ...*/t6/: column 'a' failed to load: cannot map the file: the file is empty") -- true +(like (ld "t7") "splayed ...*/t7/: cannot read .d schema: cannot map the file: No such file*") -- true +(all (map (fn [n] (< (count (ld n)) 256)) ["t1" "t2" "t3" "t4" "t5" "t6" "t7"])) -- true +;; a parted table's partition, the same way +(.db.splayed.set (concat LD "/p/2024.01.01/t/") (table [a l] (list [1 2] (list [1 2] [3])))) +(.sys.exec (concat (concat "truncate -s 40 " LD) "/p/2024.01.01/t/l")) -- 0 +(like (try (.db.parted.get (concat LD "/p/") 't) (fn [e] (get e 'msg))) "splayed ...*2024.01.01/t: column 'l' failed to load: the vector header is truncated") -- true +(.sys.exec "rm -rf /tmp/rftest_eml; true") -- 0 diff --git a/test/test_lang.c b/test/test_lang.c index 6c66f700d..78cc12c3a 100644 --- a/test/test_lang.c +++ b/test/test_lang.c @@ -16668,6 +16668,35 @@ static test_result_t test_csv_import_cause_kept(void) { PASS(); } +/* A column file cut short names what is truncated (#1886); a missing one + * names the file and the OS reason. Codes are as before: corrupt, io. */ +static test_result_t test_col_file_messages(void) { +#if !defined(RAY_OS_WINDOWS) /* the fixture is cut with POSIX truncate */ + const char* path = ray_test_tmp("/tmp/rf_col_msg_v"); + ray_t* v = ray_eval_str("(til 1000)"); + TEST_ASSERT(v && !RAY_IS_ERR(v), "fixture"); + TEST_ASSERT_EQ_I(ray_col_save(v, path), RAY_OK); + ray_release(v); + TEST_ASSERT_EQ_I(truncate(path, 40), 0); + ray_t* r = ray_col_load(path); + bool corrupt = r && RAY_IS_ERR(r) && strcmp(ray_err_code(r), "corrupt") == 0; + char m1[256]; + snprintf(m1, sizeof m1, "%s", corrupt && ray_err_msg(r) ? ray_err_msg(r) : "(none)"); + if (r) { if (RAY_IS_ERR(r)) ray_error_free(r); else ray_release(r); } + (void)unlink(path); + ray_t* r2 = ray_col_load(path); + bool io = r2 && RAY_IS_ERR(r2) && strcmp(ray_err_code(r2), "io") == 0; + char m2[256]; + snprintf(m2, sizeof m2, "%s", io && ray_err_msg(r2) ? ray_err_msg(r2) : "(none)"); + if (r2) { if (RAY_IS_ERR(r2)) ray_error_free(r2); else ray_release(r2); } + TEST_ASSERT_TRUE(corrupt); + TEST_ASSERT_FMT(strstr(m1, "column") && strstr(m1, "shorter than its data"), "truncated: %s", m1); + TEST_ASSERT_TRUE(io); + TEST_ASSERT_FMT(strstr(m2, "column \"") && strstr(m2, strerror(ENOENT)), "missing: %s", m2); +#endif + PASS(); +} + const test_entry_t lang_entries[] = { { "lang/query/group_wide_null_masks", test_group_wide_null_masks, lang_setup, lang_teardown }, { "lang/callprof/error_unwinds", test_callprof_error_unwinds, lang_setup, lang_teardown }, @@ -17223,5 +17252,6 @@ const test_entry_t lang_entries[] = { { "lang/eval/restricted_query_mapped", test_eval_restricted_query_mapped, lang_setup, lang_teardown }, { "lang/read_os_reason", test_read_os_reason, lang_setup, lang_teardown }, { "lang/csv_import_cause_kept", test_csv_import_cause_kept, lang_setup, lang_teardown }, + { "lang/col_file_messages", test_col_file_messages, lang_setup, lang_teardown }, { NULL, NULL, NULL, NULL }, };