From 8bca6946b4771a0d438fe1239ca8cc0a8604efca Mon Sep 17 00:00:00 2001 From: David Steele Date: Fri, 30 Jul 2021 17:51:56 -0400 Subject: [PATCH] Add line and column to build yaml error messages. This makes it much easier to debug errors in the yaml files. --- src/build/common/yaml.c | 13 +++++++++++-- src/build/common/yaml.h | 2 ++ test/src/module/build/commonTest.c | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/build/common/yaml.c b/src/build/common/yaml.c index 4a106ae53..b3d38c6bc 100644 --- a/src/build/common/yaml.c +++ b/src/build/common/yaml.c @@ -143,7 +143,12 @@ yamlEventNext(Yaml *this) (unsigned long)this->parser.problem_mark.line + 1, (unsigned long)this->parser.problem_mark.column + 1); } - YamlEvent result = {.type = yamlEventType(event.type)}; + YamlEvent result = + { + .type = yamlEventType(event.type), + .line = event.start_mark.line + 1, + .column = event.start_mark.column + 1, + }; if (result.type == yamlEventTypeScalar) result.value = strNewZ((const char *)event.data.scalar.value); @@ -178,7 +183,11 @@ yamlEventCheck(YamlEvent event, YamlEventType type) FUNCTION_TEST_END(); if (event.type != type) - THROW_FMT(FormatError, "expected event type '%s' but got '%s'", strZ(strIdToStr(type)), strZ(strIdToStr(event.type))); + { + THROW_FMT( + FormatError, "expected event type '%s' but got '%s' at line %zu, column %zu", strZ(strIdToStr(type)), + strZ(strIdToStr(event.type)), event.line, event.column); + } FUNCTION_TEST_RETURN_VOID(); } diff --git a/src/build/common/yaml.h b/src/build/common/yaml.h index 7a9ecd4cb..48fa69d26 100644 --- a/src/build/common/yaml.h +++ b/src/build/common/yaml.h @@ -41,6 +41,8 @@ typedef struct YamlEvent { YamlEventType type; // Type (e.g. scalar) const String *value; // Value, when type is scalar + size_t line; // Parse line + size_t column; // Parse column } YamlEvent; /*********************************************************************************************************************************** diff --git a/test/src/module/build/commonTest.c b/test/src/module/build/commonTest.c index 906ddba6a..cfb2256e8 100644 --- a/test/src/module/build/commonTest.c +++ b/test/src/module/build/commonTest.c @@ -44,7 +44,7 @@ testRun(void) TEST_ERROR(yamlBoolParse((YamlEvent){.value = STRDEF("ack")}), FormatError, "invalid boolean 'ack'"); // ------------------------------------------------------------------------------------------------------------------------- - TEST_TITLE("type map (remaning types)"); + TEST_TITLE("type map (remaining types)"); TEST_RESULT_UINT(yamlEventType(YAML_STREAM_END_EVENT), yamlEventTypeStreamEnd, "stream end"); TEST_RESULT_UINT(yamlEventType(YAML_DOCUMENT_END_EVENT), yamlEventTypeDocEnd, "doc end"); @@ -53,7 +53,7 @@ testRun(void) TEST_ERROR( yamlEventCheck((YamlEvent){.type = yamlEventTypeAlias}, yamlEventTypeScalar), FormatError, - "expected event type 'scalar' but got 'alias'"); + "expected event type 'scalar' but got 'alias' at line 0, column 0"); } FUNCTION_HARNESS_RETURN_VOID();