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

@@ -10,7 +10,7 @@ GroundValue native_file_read(GroundScope* scope, List args) {
char* path = args.values[0].data.stringVal;
FILE* f = fopen(path, "r");
if (!f) {
return groundCreateValue(NONE);
ERROR("Failed to open file for reading", "FileError");
}
fseek(f, 0, SEEK_END);
@@ -20,7 +20,7 @@ GroundValue native_file_read(GroundScope* scope, List args) {
char* content = malloc(fsize + 1);
if (!content) {
fclose(f);
return groundCreateValue(NONE);
ERROR("Failed to allocate memory for file reading", "FileError");
}
fread(content, 1, fsize, f);
@@ -42,7 +42,7 @@ GroundValue native_file_write(GroundScope* scope, List args) {
FILE* f = fopen(path, "w");
if (!f) {
return groundCreateValue(BOOL, 0);
ERROR("Failed to open file for writing", "FileError");
}
fprintf(f, "%s", content);