Update error handling inside extlibs

This commit is contained in:
2026-01-18 21:37:46 +11:00
parent 72162a7410
commit 754b63fb75
5 changed files with 42 additions and 112 deletions

View File

@@ -90,7 +90,7 @@ bool isMainScopeGlobal = true;
printGroundInstruction(error->where);
printf("\n");
}
if (error->line > -1) {
if (error->hasLine) {
printf(" ErrorLine: %zu\n", error->line + 1);
}
exit(1);
@@ -1762,6 +1762,9 @@ GroundValue interpretGroundInstruction(GroundInstruction inst, GroundScope* scop
if (function->nativeFn) {
GroundValue returnValue = function->nativeFn(scope, argsList);
if (returnValue.type == ERROR) {
returnValue.data.errorVal.line = currentInstruction;
returnValue.data.errorVal.hasLine = true;
returnValue.data.errorVal.where = in;
if (scope->isMainScope) {
throwError(&returnValue.data.errorVal);
}

View File

@@ -562,7 +562,8 @@ GroundError createGroundError(char* what, char* type, GroundInstruction* where,
ge.type = malloc(strlen(type) + 1);
strcpy(ge.type, type);
} else {
ge.type = "GenericError";
ge.type = malloc(strlen("GenericError") + 1);
strcpy(ge.type, "GenericError");
}
if (where != NULL) {
@@ -575,7 +576,8 @@ GroundError createGroundError(char* what, char* type, GroundInstruction* where,
if (line != NULL) {
ge.line = *line;
} else {
ge.line = -1;
ge.line = 0;
ge.hasLine = false;
}
return ge;

View File

@@ -51,6 +51,7 @@ typedef struct GroundError {
char* type;
struct GroundInstruction* where;
size_t line;
bool hasLine;
} GroundError;
/*