Error Details
- Data about errors resulted from executing the the method JsonQL.Query.IQueryManager.QueryObject<QueryObject>(…) is stored in property ErrorsAndWarnings in type JsonQL.Query.IObjectQueryResult[TQueryObject].
Note
The property is actually in parent interface JsonQL.Query.IObjectQueryResult
The property ErrorsAndWarnings is of type JsonQL.Query.IQueryResultErrorsAndWarnings
Interface JsonQL.Query.IQueryResultErrorsAndWarnings has the following properties for error details:
CompilationErrors: stores collection of JsonQL.Compilation.ICompilationErrorItem for errors occurred while evaluating queried JSON files and JsonQL expressions (both expressions in queried JSON files as well as JsonQL expressions in query itself). These errors happen before jsonQL attempts to convert resulted JSON value (e.g., simple JSON value, JSON object or JSON array) to a C# type instance.
ConversionErrors: stores a property of type JsonQL.JsonToObjectConversion.IConversionErrors for errors occurred while converting query result to specified C# type instance.
ConversionWarnings: stores a property of type JsonQL.JsonToObjectConversion.IConversionErrors for warnings occurred while converting query result to specified C# type instance.
Note
Properties ConversionErrors and ConversionWarnings are of the same type. The only difference is that errors that do not result in query failure. Classification of some error types (error or warning) can be configured using settings (see Conversion Settings for more details).
Note
Errors are logged by JsonQL.Compilation.ICompilationResultLogger and custom implementation of this interface can be provided.
Couple of examples are demonstrated in sections that follow. For more examples demonstrating errors look at examples in this folder: FailureExamples:
This JSON File with company data is used in queries in these examples: Companies.json
Examples
Compilation error
The code snippet below uses a query that contains an invalid expression (closing brace missing). The list employeesResult.ErrorsAndWarnings.CompilationErrors.Errors will not be empty and will contain one compilation error.
// This query will result in compilation error since closing brace is missing for open brace.
var query = "Companies.Select(c => c.Employees.Where(e => e.Address is null)";
// 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!;
var employeesResult =
queryManager.QueryObject<IReadOnlyList<IEmployee>>(query,
new JsonTextData("Companies",
LoadJsonFileHelpers.LoadJsonFile("Companies.json", ["DocFiles", "QueryingJsonFiles", "JsonFiles"])));
Assert.That(employeesResult.ErrorsAndWarnings.CompilationErrors.Count, Is.GreaterThan(0));
The JSON below stores serialized instance of JsonQL.Query.IQueryResultErrorsAndWarnings for a failed query in example above.
{
"$type": "JsonQL.Query.ObjectQueryResult`1[[System.Collections.Generic.IReadOnlyList`1[[JsonQL.Demos.Examples.IQueryManagerExamples.FailureExamples.ResultAsObject.NonNullablePropertyValueMissing.DataModels.IEmployee, JsonQL.Demos]], System.Private.CoreLib]], JsonQL",
"Value": null,
"ErrorsAndWarnings": {
"$type": "JsonQL.Query.QueryResultErrorsAndWarnings, JsonQL",
"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": 34
},
"ErrorMessage": "Closing brace ')' is missing."
}
]
},
"ConversionErrors": {
"$type": "JsonQL.JsonToObjectConversion.ConversionErrors, JsonQL",
"Errors": {
"$type": "System.Collections.Generic.List`1[[JsonQL.JsonToObjectConversion.IConversionError, JsonQL]], System.Private.CoreLib",
"$values": []
}
},
"ConversionWarnings": {
"$type": "JsonQL.JsonToObjectConversion.ConversionErrors, JsonQL",
"Errors": {
"$type": "System.Collections.Generic.List`1[[JsonQL.JsonToObjectConversion.IConversionError, JsonQL]], System.Private.CoreLib",
"$values": []
}
}
}
}
Running the query above results in the following error log generated by JsonQL.Compilation.ICompilationResultLogger
Conversion error
The code snippet below uses a query that tries to convert the result of a query to list of IEmployee instances, and some JSON objects in query JSON file Companies.json miss Address value for non-nullable property IEmployee.Address. The list employeesResult.ErrorsAndWarnings.ConversionErrors.Errors will not be empty and will contain one compilation error.
// This query will fail since not all values of IEmployee.Age are non-null in a result set.
var query = "Companies.Select(c => c.Employees.Where(e => e.Address is null))";
// 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!;
var employeesResult =
queryManager.QueryObject<IReadOnlyList<IEmployee>>(query,
new JsonTextData("Companies",
LoadJsonFileHelpers.LoadJsonFile("Companies.json", ["DocFiles", "QueryingJsonFiles", "JsonFiles"])),
convertedValueNullability:null,
jsonConversionSettingOverrides:
new JsonConversionSettingsOverrides
{
// NOTE: jsonConversionSettingOverrides parameter of type IJsonConversionSettingsOverrides
// is an optional, and we do not have to provide this parameter of default settings work
// for us (which is most of the cases).
// However, the parameter is specified here as an example
ConversionErrorTypeConfigurations = [
// Note, we only need to provide configurations that we want to override.
// Default configurations will be used for any error type that is not specified in
// ConversionErrorTypeConfigurations collection
new ConversionErrorTypeConfiguration(ConversionErrorType.NonNullablePropertyNotSet,
// The default error reporting type of ConversionErrorType.NonNullablePropertyNotSet is
// ErrorReportingType.ReportAsError.
// This is just a demo how the default configuration can be overridden
ErrorReportingType.ReportAsError)]
});
Assert.That(employeesResult.ErrorsAndWarnings.ConversionErrors.Errors.Count, Is.GreaterThan(0));
The JSON below stores serialized instance of JsonQL.Query.IQueryResultErrorsAndWarnings for a failed query in example above.
{
"$type": "JsonQL.Query.ObjectQueryResult`1[[System.Collections.Generic.IReadOnlyList`1[[JsonQL.Demos.Examples.IQueryManagerExamples.FailureExamples.ResultAsObject.NonNullablePropertyValueMissing.DataModels.IEmployee, JsonQL.Demos]], System.Private.CoreLib]], JsonQL",
"Value": null,
"ErrorsAndWarnings": {
"$type": "JsonQL.Query.QueryResultErrorsAndWarnings, JsonQL",
"CompilationErrors": {
"$type": "JsonQL.Compilation.ICompilationErrorItem[], JsonQL",
"$values": []
},
"ConversionErrors": {
"$type": "JsonQL.JsonToObjectConversion.ConversionErrors, JsonQL",
"Errors": {
"$type": "System.Collections.Generic.List`1[[JsonQL.JsonToObjectConversion.IConversionError, JsonQL]], System.Private.CoreLib",
"$values": [
{
"$type": "JsonQL.JsonToObjectConversion.ConversionError, JsonQL",
"ErrorType": "NonNullablePropertyNotSet",
"JsonPath": {
"$type": "JsonQL.JsonObjects.JsonPath.JsonPath, JsonQL",
"JsonTextIdentifier": "Query_849E0817-3256-483D-8E97-01744EBC3F76",
"Path": {
"$type": "System.Collections.Generic.List`1[[JsonQL.JsonObjects.JsonPath.IJsonPathElement, JsonQL]], System.Private.CoreLib",
"$values": [
{
"$type": "JsonQL.JsonObjects.JsonPath.JsonPropertyNamePathElement, JsonQL",
"Name": "Root"
},
{
"$type": "JsonQL.JsonObjects.JsonPath.JsonPropertyNamePathElement, JsonQL",
"Name": "query"
},
{
"$type": "JsonQL.JsonObjects.JsonPath.JsonArrayIndexesPathElement, JsonQL",
"Indexes": {
"$type": "System.Collections.Generic.List`1[[System.Int32, System.Private.CoreLib]], System.Private.CoreLib",
"$values": [
0
]
}
}
]
}
},
"PathInReferencedJson": {
"$type": "JsonQL.JsonObjects.JsonPath.JsonPath, JsonQL",
"JsonTextIdentifier": "Companies",
"Path": {
"$type": "System.Collections.Generic.List`1[[JsonQL.JsonObjects.JsonPath.IJsonPathElement, JsonQL]], System.Private.CoreLib",
"$values": [
{
"$type": "JsonQL.JsonObjects.JsonPath.JsonPropertyNamePathElement, JsonQL",
"Name": "Root"
},
{
"$type": "JsonQL.JsonObjects.JsonPath.JsonPropertyNamePathElement, JsonQL",
"Name": "Companies"
},
{
"$type": "JsonQL.JsonObjects.JsonPath.JsonArrayIndexesPathElement, JsonQL",
"Indexes": {
"$type": "System.Collections.Generic.List`1[[System.Int32, System.Private.CoreLib]], System.Private.CoreLib",
"$values": [
1
]
}
},
{
"$type": "JsonQL.JsonObjects.JsonPath.JsonPropertyNamePathElement, JsonQL",
"Name": "Employees"
},
{
"$type": "JsonQL.JsonObjects.JsonPath.JsonArrayIndexesPathElement, JsonQL",
"Indexes": {
"$type": "System.Collections.Generic.List`1[[System.Int32, System.Private.CoreLib]], System.Private.CoreLib",
"$values": [
1
]
}
}
]
}
},
"Error": "Failed to retrieve and set the value of non-nullable property [Address] in type [JsonQL.Demos.Examples.IQueryManagerExamples.FailureExamples.ResultAsObject.NonNullablePropertyValueMissing.DataModels.Employee].",
"ConvertedObjectPath": {
"$type": "JsonQL.JsonToObjectConversion.ConvertedObjectPath.ConvertedObjectPath, JsonQL",
"RootConvertedObjectPathElement": {
"$type": "JsonQL.JsonToObjectConversion.ConvertedObjectPath.RootConvertedObjectPathElement, JsonQL",
"Name": "Root",
"ObjectType": "System.Collections.Generic.IReadOnlyList`1[[JsonQL.Demos.Examples.IQueryManagerExamples.FailureExamples.ResultAsObject.NonNullablePropertyValueMissing.DataModels.IEmployee, JsonQL.Demos, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"
},
"Path": {
"$type": "System.Collections.Generic.List`1[[JsonQL.JsonToObjectConversion.ConvertedObjectPath.IConvertedObjectPathValueSelectorElement, JsonQL]], System.Private.CoreLib",
"$values": [
{
"$type": "JsonQL.JsonToObjectConversion.ConvertedObjectPath.IndexConvertedObjectPathElement, JsonQL",
"Name": "0",
"ObjectType": "JsonQL.Demos.Examples.IQueryManagerExamples.FailureExamples.ResultAsObject.NonNullablePropertyValueMissing.DataModels.IEmployee, JsonQL.Demos, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
},
{
"$type": "JsonQL.JsonToObjectConversion.ConvertedObjectPath.PropertyNameConvertedObjectPathElement, JsonQL",
"Name": "Address",
"ObjectType": "JsonQL.Demos.Examples.DataModels.IAddress, JsonQL.Demos, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
}
]
}
}
}
]
}
},
"ConversionWarnings": {
"$type": "JsonQL.JsonToObjectConversion.ConversionErrors, JsonQL",
"Errors": {
"$type": "System.Collections.Generic.List`1[[JsonQL.JsonToObjectConversion.IConversionError, JsonQL]], System.Private.CoreLib",
"$values": []
}
}
}
}
Note
This example stores number of details about an error that help identify the source of the error, but a summary error message is Failed to retrieve and set the value of non-nullable property [Address] in type [JsonQL.Demos.Examples.IQueryManagerExamples.FailureExamples.ResultAsObject.NonNullablePropertyValueMissing.DataModels.Employee]..