1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Add line and column to build yaml error messages.

This makes it much easier to debug errors in the yaml files.
This commit is contained in:
David Steele 2021-07-30 17:51:56 -04:00
parent b47a07b8b9
commit 8bca6946b4
3 changed files with 15 additions and 4 deletions

View File

@ -143,7 +143,12 @@ yamlEventNext(Yaml *this)
(unsigned long)this->parser.problem_mark.line + 1, (unsigned long)this->parser.problem_mark.column + 1); (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) if (result.type == yamlEventTypeScalar)
result.value = strNewZ((const char *)event.data.scalar.value); result.value = strNewZ((const char *)event.data.scalar.value);
@ -178,7 +183,11 @@ yamlEventCheck(YamlEvent event, YamlEventType type)
FUNCTION_TEST_END(); FUNCTION_TEST_END();
if (event.type != type) 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(); FUNCTION_TEST_RETURN_VOID();
} }

View File

@ -41,6 +41,8 @@ typedef struct YamlEvent
{ {
YamlEventType type; // Type (e.g. scalar) YamlEventType type; // Type (e.g. scalar)
const String *value; // Value, when type is scalar const String *value; // Value, when type is scalar
size_t line; // Parse line
size_t column; // Parse column
} YamlEvent; } YamlEvent;
/*********************************************************************************************************************************** /***********************************************************************************************************************************

View File

@ -44,7 +44,7 @@ testRun(void)
TEST_ERROR(yamlBoolParse((YamlEvent){.value = STRDEF("ack")}), FormatError, "invalid boolean 'ack'"); 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_STREAM_END_EVENT), yamlEventTypeStreamEnd, "stream end");
TEST_RESULT_UINT(yamlEventType(YAML_DOCUMENT_END_EVENT), yamlEventTypeDocEnd, "doc end"); TEST_RESULT_UINT(yamlEventType(YAML_DOCUMENT_END_EVENT), yamlEventTypeDocEnd, "doc end");
@ -53,7 +53,7 @@ testRun(void)
TEST_ERROR( TEST_ERROR(
yamlEventCheck((YamlEvent){.type = yamlEventTypeAlias}, yamlEventTypeScalar), FormatError, 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(); FUNCTION_HARNESS_RETURN_VOID();