Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context to error messages #1139

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 7 additions & 19 deletions src/core/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,25 +409,13 @@ void MVM_args_assert_nameds_used(MVMThreadContext *tc, MVMArgProcContext *ctx) {
MVMuint16 i;
if (size > 64) {
for (i = 0; i < size; i++)
if (!ctx->named_used.byte_array[i]) {
char *c_param = MVM_string_utf8_encode_C_string(tc,
ctx->args[ctx->num_pos + 2 * i].s);
char *waste[] = { c_param, NULL };
MVM_exception_throw_adhoc_free(tc, waste,
"Unexpected named argument '%s' passed",
c_param);
}
if (!ctx->named_used.byte_array[i])
MVM_args_throw_named_unused_error(tc, ctx->args[ctx->num_pos + 2 * i].s);
}
else {
for (i = 0; i < size; i++)
if (!(ctx->named_used.bit_field & ((MVMuint64)1 << i))) {
char *c_param = MVM_string_utf8_encode_C_string(tc,
ctx->args[ctx->num_pos + 2 * i].s);
char *waste[] = { c_param, NULL };
MVM_exception_throw_adhoc_free(tc, waste,
"Unexpected named argument '%s' passed",
c_param);
}
if (!(ctx->named_used.bit_field & ((MVMuint64)1 << i)))
MVM_args_throw_named_unused_error(tc, ctx->args[ctx->num_pos + 2 * i].s);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In C, please use explicit brackets by default; as a side effect, that would've reduced the scope of the diff to contain only the block; which would've made it easier to review 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm generally a fan of explicit brackets, but the codebase has a lot of ifs without them. I'd almost say without is more common. Should I change all the ones in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant to say is that, if you had used, or rather left, the brackets around the block, the diff would've contained only the actual contents of the block. Which makes it easy to assert that the conditional itself hadn't changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, I see now. Want me to add the braces back?

}
}

Expand Down Expand Up @@ -637,7 +625,7 @@ MVMObject * MVM_args_slurpy_positional(MVMThreadContext *tc, MVMArgProcContext *
break;
}
default:
MVM_exception_throw_adhoc(tc, "arg flag is empty in slurpy positional");
MVM_exception_throw_adhoc(tc, "Arg flag is empty in slurpy_positional");
}

find_pos_arg(ctx, pos, arg_info);
Expand Down Expand Up @@ -727,7 +715,7 @@ MVMObject * MVM_args_slurpy_named(MVMThreadContext *tc, MVMArgProcContext *ctx)
break;
}
default:
MVM_exception_throw_adhoc(tc, "arg flag is empty in slurpy named");
MVM_exception_throw_adhoc(tc, "Arg flag is empty in slurpy_named");
}
}

Expand Down Expand Up @@ -772,7 +760,7 @@ static void flatten_args(MVMThreadContext *tc, MVMArgProcContext *ctx) {
MVMStorageSpec lss = REPR(list)->pos_funcs.get_elem_storage_spec(tc, STABLE(list));

if ((MVMint64)new_arg_pos + count > 0xFFFF) {
MVM_exception_throw_adhoc(tc, "Too many arguments in flattening array.");
MVM_exception_throw_adhoc(tc, "Too many arguments (%"PRId64") in flattening array, only %"PRId32" allowed.", (MVMint64)new_arg_pos + count, 0xFFFF);
}

for (i = 0; i < count; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/bytecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ void MVM_bytecode_finish_frame(MVMThreadContext *tc, MVMCompUnit *cu,

if (lex_idx >= sf->body.num_lexicals) {
MVM_reentrantmutex_unlock(tc, (MVMReentrantMutex *)cu->body.deserialize_frame_mutex);
MVM_exception_throw_adhoc(tc, "Lexical index out of bounds: %d > %d", lex_idx, sf->body.num_lexicals);
MVM_exception_throw_adhoc(tc, "Lexical index out of bounds: %d >= %d", lex_idx, sf->body.num_lexicals);
}

sf->body.static_env_flags[lex_idx] = flags;
Expand Down
14 changes: 7 additions & 7 deletions src/core/coerce.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ MVMString * MVM_coerce_i_s(MVMThreadContext *tc, MVMint64 i) {
return result;
}
else {
MVM_exception_throw_adhoc(tc, "Could not stringify integer");
MVM_exception_throw_adhoc(tc, "Could not stringify integer (%"PRId64")", i);
}
}

Expand All @@ -248,7 +248,7 @@ MVMString * MVM_coerce_u_s(MVMThreadContext *tc, MVMuint64 i) {
return result;
}
else {
MVM_exception_throw_adhoc(tc, "Could not stringify integer");
MVM_exception_throw_adhoc(tc, "Could not stringify integer (%"PRIu64")", i);
}
}

Expand All @@ -265,7 +265,7 @@ MVMString * MVM_coerce_n_s(MVMThreadContext *tc, MVMnum64 n) {
else {
char buf[64];
if (dtoa_grisu3(n, buf, 64) < 0)
MVM_exception_throw_adhoc(tc, "Could not stringify number");
MVM_exception_throw_adhoc(tc, "Could not stringify number (%f)", n);
else {
MVMStringIndex len = strlen(buf);
MVMGrapheme8 *blob = MVM_malloc(len);
Expand Down Expand Up @@ -321,7 +321,7 @@ void MVM_coerce_smart_stringify(MVMThreadContext *tc, MVMObject *obj, MVMRegiste
else if (ss->can_box & MVM_STORAGE_SPEC_CAN_BOX_NUM)
res_reg->s = MVM_coerce_n_s(tc, REPR(obj)->box_funcs.get_num(tc, STABLE(obj), obj, OBJECT_BODY(obj)));
else
MVM_exception_throw_adhoc(tc, "Cannot stringify this type (%s)", MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
MVM_exception_throw_adhoc(tc, "Cannot stringify this object of type %s (%s)", REPR(obj)->name, MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
}
}

Expand Down Expand Up @@ -376,7 +376,7 @@ void MVM_coerce_smart_numify(MVMThreadContext *tc, MVMObject *obj, MVMRegister *
else if (REPR(obj)->ID == MVM_REPR_ID_MVMHash)
res_reg->n64 = (MVMnum64)REPR(obj)->elems(tc, STABLE(obj), obj, OBJECT_BODY(obj));
else
MVM_exception_throw_adhoc(tc, "Cannot numify this type (%s)", MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
MVM_exception_throw_adhoc(tc, "Cannot numify this object of type %s (%s)", REPR(obj)->name, MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
}
}

Expand Down Expand Up @@ -423,7 +423,7 @@ void MVM_coerce_smart_intify(MVMThreadContext *tc, MVMObject *obj, MVMRegister *
else if (REPR(obj)->ID == MVM_REPR_ID_MVMHash)
res_reg->i64 = REPR(obj)->elems(tc, STABLE(obj), obj, OBJECT_BODY(obj));
else
MVM_exception_throw_adhoc(tc, "Cannot intify this type (%s)", MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
MVM_exception_throw_adhoc(tc, "Cannot intify this object of type %s (%s)", REPR(obj)->name, MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
}
}

Expand All @@ -447,7 +447,7 @@ MVMint64 MVM_coerce_simple_intify(MVMThreadContext *tc, MVMObject *obj) {
else if (REPR(obj)->ID == MVM_REPR_ID_MVMHash)
return REPR(obj)->elems(tc, STABLE(obj), obj, OBJECT_BODY(obj));
else
MVM_exception_throw_adhoc(tc, "Cannot intify this type (%s)", MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
MVM_exception_throw_adhoc(tc, "Cannot intify this object of type %s (%s)", REPR(obj)->name, MVM_6model_get_stable_debug_name(tc, STABLE(obj)));
}
}

Expand Down
20 changes: 14 additions & 6 deletions src/core/dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ int MVM_dll_free(MVMThreadContext *tc, MVMString *name) {
MVM_HASH_GET(tc, tc->instance->dll_registry, name, entry);

if (!entry) {
char *c_name = MVM_string_utf8_encode_C_string(tc, name);
char *waste[] = { c_name, NULL };
uv_mutex_unlock(&tc->instance->mutex_dll_registry);
MVM_exception_throw_adhoc(tc, "cannot free non-existent library");
MVM_exception_throw_adhoc_free(tc, waste, "cannot free non-existent library '%s'", c_name);
}

/* already freed */
Expand All @@ -68,8 +70,10 @@ int MVM_dll_free(MVMThreadContext *tc, MVMString *name) {
}

if (entry->refcount > 0) {
char *c_name = MVM_string_utf8_encode_C_string(tc, name);
char *waste[] = { c_name, NULL };
uv_mutex_unlock(&tc->instance->mutex_dll_registry);
MVM_exception_throw_adhoc(tc, "cannot free in-use library");
MVM_exception_throw_adhoc_free(tc, waste, "cannot free in-use library '%s'", c_name);
}

MVM_nativecall_free_lib(entry->lib);
Expand All @@ -92,15 +96,19 @@ MVMObject * MVM_dll_find_symbol(MVMThreadContext *tc, MVMString *lib,
MVM_HASH_GET(tc, tc->instance->dll_registry, lib, entry);

if (!entry) {
char *c_lib = MVM_string_utf8_encode_C_string(tc, lib);
char *waste[] = { c_lib, NULL };
uv_mutex_unlock(&tc->instance->mutex_dll_registry);
MVM_exception_throw_adhoc(tc,
"cannot find symbol in non-existent library");
MVM_exception_throw_adhoc_free(tc, waste,
"cannot find symbol '%s' in non-existent library", c_lib);
}

if (!entry->lib) {
char *c_lib = MVM_string_utf8_encode_C_string(tc, lib);
char *waste[] = { c_lib, NULL };
uv_mutex_unlock(&tc->instance->mutex_dll_registry);
MVM_exception_throw_adhoc(tc,
"cannot find symbol in unloaded library");
MVM_exception_throw_adhoc_free(tc, waste,
"cannot find symbol '%s' in unloaded library", c_lib);
}

csym = MVM_string_utf8_c8_encode_C_string(tc, sym);
Expand Down
4 changes: 3 additions & 1 deletion src/core/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ int MVM_ext_load(MVMThreadContext *tc, MVMString *lib, MVMString *ext) {
sym = (MVMDLLSym *)MVM_dll_find_symbol(tc, lib, ext);
});
if (!sym) {
char *c_name = MVM_string_utf8_encode_C_string(tc, name);
char *waste[] = { c_name, NULL };
uv_mutex_unlock(&tc->instance->mutex_ext_registry);
MVM_exception_throw_adhoc(tc, "extension symbol not found");
MVM_exception_throw_adhoc_free(tc, waste, "extension symbol (%s) not found", c_name);
}

entry = MVM_malloc(sizeof *entry);
Expand Down