From 8ace58049879d5133a2bdd0f3dd333ad9acb05ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Wed, 5 Nov 2025 16:53:19 +0900 Subject: [PATCH] Include context in dobytes' error string --- src/core/run.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/core/run.c b/src/core/run.c index b6a78847..dca0f066 100644 --- a/src/core/run.c +++ b/src/core/run.c @@ -60,7 +60,6 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char done = 1; } } else { - ret = janet_wrap_string(cres.error); int32_t line = (int32_t) parser->line; int32_t col = (int32_t) parser->column; if ((cres.error_mapping.line > 0) && @@ -68,13 +67,17 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char line = cres.error_mapping.line; col = cres.error_mapping.column; } + JanetString ctx = janet_formatc("%s:%d:%d: compile error", + sourcePath, line, col); + JanetString errstr = janet_formatc("%s: %s", + (const char *)ctx, + (const char *)cres.error); + ret = janet_wrap_string(errstr); if (cres.macrofiber) { - janet_eprintf("%s:%d:%d: compile error", sourcePath, - line, col); + janet_eprintf("%s", (const char *)ctx); janet_stacktrace_ext(cres.macrofiber, ret, ""); } else { - janet_eprintf("%s:%d:%d: compile error: %s\n", sourcePath, - line, col, (const char *)cres.error); + janet_eprintf("%s\n", (const char *)errstr); } errflags |= JANET_DO_ERROR_COMPILE; done = 1; @@ -89,12 +92,14 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char done = 1; break; case JANET_PARSE_ERROR: { - const char *e = janet_parser_error(parser); errflags |= JANET_DO_ERROR_PARSE; - ret = janet_cstringv(e); int32_t line = (int32_t) parser->line; int32_t col = (int32_t) parser->column; - janet_eprintf("%s:%d:%d: parse error: %s\n", sourcePath, line, col, e); + JanetString errstr = janet_formatc("%s:%d:%d: parse error: %s", + sourcePath, line, col, + janet_parser_error(parser)); + ret = janet_wrap_string(errstr); + janet_eprintf("%s\n", (const char *)errstr); done = 1; break; }