Error Details
- If evaluated query or referenced JSON files have errors, the error details are stored in property CompilationErrors of interface JsonQL.Query.IJsonValueQueryResult.
Note
See Query Result Data Structure: JsonQL.Query.IJsonValueQueryResult for more details on data structure used for the result.
- Each item in property CompilationErrors in JsonQL.Query.IJsonValueQueryResult is of type JsonQL.Compilation.ICompilationErrorItem which has details on an error such as:
JSON file identifier that resulted in error.
Position in JSON file or query for the error.
Error message.
- Errors can happen for number of reasons, some of which are listed here:
Missing or extra closing braces for functions or arrays.
Unknown symbols used in JsonQL expressions.
‘assert’ functions failing the evaluated expressions.
JsonQL uses JsonQL.Compilation.ICompilationResultLogger to log the error details. The implementation of this interface can be replaced if necessary.
Examples
Below are couple of examples showing errors in queried files as well as in query itself.
Note
For more examples demonstrating errors look at examples in this folder: FailureExamples
Missing closing brace in queried JSON file:
The C# code snippet below queries JSON file Data.json below. The query results in errors since the referenced file has a JsonQL function with missing closing braces.
Queried Data.json file:
{
"TestData": [ 1, 3, 4, "5", "TEST", 7 ],
"JsonQlExpressionWithMissinClosingBraces": "$value(ToInt(TestData[3]) + 1"
}
// Set the value of queryManager to an instance of JsonQL.Query.IQueryManager here.
// The value of JsonQL.Query.IQueryManager is normally created by Dependency Injection container
// and it is normally configured as a singleton.
JsonQL.Query.IQueryManager queryManager = null!;
// This query will fail since the value of JSON key "JsonQlExpressionWithMissingClosingBraces"
// is a JsonQL "$value(ToInt(TestData[3]) + 1" that has no closing brace for
// "$value(" function.
var query = "JsonQlExpressionWithMissingClosingBraces";
var queryResult =
queryManager.QueryJsonValue(query,
new JsonTextData("Data",
this.LoadExampleJsonFile("Data.json")));
The result (an instance of JsonQL.Query.IJsonValueQueryResult) is serialized to a Result.json file below.
Click to expand the result of the query in example above (i.e., instance of JsonQL.Query.IJsonValueQueryResult<IReadOnlyList<IEmployee>>) serialized into Result.json
{
"ParsedValue": null,
"CompilationErrors":
{
"$type": "System.Collections.Generic.List`1[[JsonQL.Compilation.ICompilationErrorItem, JsonQL]], System.Private.CoreLib",
"$values": [
{
"$type": "JsonQL.Compilation.CompilationErrorItem, JsonQL",
"JsonTextIdentifier": "Data",
"LineInfo": {
"$type": "JsonQL.JsonObjects.JsonLineInfo, JsonQL",
"LineNumber": 3,
"LinePosition": 53
},
"ErrorMessage": "Closing brace ')' is missing."
}
]
}
}
The screenshot below shows the error details logged using the data in property CompilationErrors in JsonQL.Query.IJsonValueQueryResult.
Invalid parameters in query
The C# code snippet below queries JSON file Data.json. The query results in errors since the query uses invalid number of parameter in a call to a JsonQL function.
Queried Data.json file:
{
"TestData": [ 1, 3, 4, "TEST", 7 ]
}
var query = "Lower(TestData[3])";
// Set the value of queryManager to an instance of JsonQL.Query.IQueryManager here.
// The value of JsonQL.Query.IQueryManager is normally created by Dependency Injection container
// and it is normally configured as a singleton.
JsonQL.Query.IQueryManager queryManager = null!;
// This query will succeed.
var queryResult =
queryManager.QueryJsonValue(query,
new JsonTextData("Data",
this.LoadExampleJsonFile("Data.json")));
Assert.That(queryResult.ParsedValue is IParsedSimpleValue {Value: "test"});
// This query will fail as it has extra parameter.
query = "Lower(TestData[3], 7)";
queryResult =
queryManager.QueryJsonValue(query,
new JsonTextData("Data",
this.LoadExampleJsonFile("Data.json")));
The result (an instance of JsonQL.Query.IJsonValueQueryResult) is serialized to a Result.json file below.
Click to expand the result of the query in example above (i.e., instance of JsonQL.Query.IJsonValueQueryResult<IReadOnlyList<IEmployee>>) serialized into Result.json
{
"ParsedValue": null,
"CompilationErrors":
{
"$type": "System.Collections.Generic.List`1[[JsonQL.Compilation.ICompilationErrorItem, JsonQL]], System.Private.CoreLib",
"$values": [
{
"$type": "JsonQL.Compilation.CompilationErrorItem, JsonQL",
"JsonTextIdentifier": "Query_849E0817-3256-483D-8E97-01744EBC3F76",
"LineInfo": {
"$type": "JsonQL.JsonObjects.JsonLineInfo, JsonQL",
"LineNumber": 2,
"LinePosition": 18
},
"ErrorMessage": "Too many parameters provided for function [Lower]. Expected at most 1 parameters."
}
]
}
}
The screenshot below shows the error details logged using the data in property CompilationErrors in JsonQL.Query.IJsonValueQueryResult.