added tlibc error handling everywhere
This commit is contained in:
@@ -5,15 +5,16 @@
|
||||
#include "toml_internal.h"
|
||||
|
||||
|
||||
TomlTable* toml_walk_table_path(TomlParser* parser, TomlTable* table,
|
||||
TomlArray* key_path, i32 is_array, i32 create_if_not_exist)
|
||||
Result(Table*) toml_walk_table_path(TomlParser* parser, TomlTable* table,
|
||||
TomlArray* key_path, bool is_array, bool create_if_not_exist)
|
||||
{
|
||||
Deferral(1);
|
||||
TomlTable* real_table = table;
|
||||
|
||||
if (is_array) {
|
||||
u64 i = 0;
|
||||
for (; i < key_path->len - 1; i++) {
|
||||
str part = key_path->elements[i].value.s;
|
||||
str part = *key_path->elements[i].value.s;
|
||||
TomlValue* t = TomlTable_get(real_table, part);
|
||||
if (t == NULL) {
|
||||
if (create_if_not_exist) {
|
||||
@@ -21,15 +22,16 @@ TomlTable* toml_walk_table_path(TomlParser* parser, TomlTable* table,
|
||||
TomlTable_set(real_table, part, new_table_value);
|
||||
real_table = new_table_value.value.table;
|
||||
} else {
|
||||
real_table = NULL;
|
||||
break;
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
"%s:%d:%d: not found key '" FMT_str "'",
|
||||
parser->filename, parser->lineno, parser->colno, part.len, part.data);
|
||||
}
|
||||
} else {
|
||||
real_table = t->value.table;
|
||||
}
|
||||
}
|
||||
|
||||
str part = key_path->elements[i].value.s;
|
||||
str part = *key_path->elements[i].value.s;
|
||||
TomlValue* t = TomlTable_get(real_table, part);
|
||||
if (t == NULL) {
|
||||
if (create_if_not_exist) {
|
||||
@@ -39,13 +41,15 @@ TomlTable* toml_walk_table_path(TomlParser* parser, TomlTable* table,
|
||||
TomlTable_set(real_table, part, array_value);
|
||||
real_table = new_table_value.value.table;
|
||||
} else {
|
||||
real_table = NULL;
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
"%s:%d:%d: not found key '" FMT_str "'",
|
||||
parser->filename, parser->lineno, parser->colno, part.len, part.data);
|
||||
}
|
||||
} else {
|
||||
if (t->type != TLIBTOML_ARRAY) {
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX, "%s:%d:%d: this key was not an array",
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
"%s:%d:%d: this key was not an array",
|
||||
parser->filename, parser->lineno, parser->colno);
|
||||
goto error;
|
||||
}
|
||||
|
||||
TomlValue new_table_value = TomlValue_new_table();
|
||||
@@ -54,7 +58,7 @@ TomlTable* toml_walk_table_path(TomlParser* parser, TomlTable* table,
|
||||
}
|
||||
} else {
|
||||
for (u64 i = 0; i < key_path->len; i++) {
|
||||
str part = key_path->elements[i].value.s;
|
||||
str part = *key_path->elements[i].value.s;
|
||||
TomlValue* t = TomlTable_get(real_table, part);
|
||||
if (t == NULL) {
|
||||
if (create_if_not_exist) {
|
||||
@@ -62,8 +66,9 @@ TomlTable* toml_walk_table_path(TomlParser* parser, TomlTable* table,
|
||||
TomlTable_set(real_table, part, new_table_value);
|
||||
real_table = new_table_value.value.table;
|
||||
} else {
|
||||
real_table = NULL;
|
||||
break;
|
||||
Return RESULT_ERROR_CODE_FMT(TLIBTOML, TLIBTOML_ERR_SYNTAX,
|
||||
"%s:%d:%d: not found key '" FMT_str "'",
|
||||
parser->filename, parser->lineno, parser->colno, part.len, part.data);
|
||||
}
|
||||
} else {
|
||||
if (t->type == TLIBTOML_ARRAY) {
|
||||
@@ -75,13 +80,5 @@ TomlTable* toml_walk_table_path(TomlParser* parser, TomlTable* table,
|
||||
}
|
||||
}
|
||||
|
||||
goto end;
|
||||
|
||||
error:
|
||||
real_table = NULL;
|
||||
//TODO: error handling
|
||||
assert(false && "TODO error handling");
|
||||
|
||||
end:
|
||||
return real_table;
|
||||
Return RESULT_VALUE(p, real_table);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user