forked from ground/cground
Update error handling inside extlibs
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -51,6 +51,7 @@ typedef struct GroundError {
|
||||
char* type;
|
||||
struct GroundInstruction* where;
|
||||
size_t line;
|
||||
bool hasLine;
|
||||
} GroundError;
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user