Internal Error Exception when an N1QL error request is sent



I have seen a little bug in the current implementation of the client, when sending a query to N1QL containing an error of syntax, the response contains no result. But in the main function ToQueryResult:
internal QueryResult ToQueryResult()
return new QueryResult
RequestId = requestID,
ClientContextId = clientContextID,
Signature = signature,
Rows = results.ToList(),
Status = status,
Errors = errors != null ? errors.Select(e => e.ToError()).ToList() : null,
Warnings = warnings != null ? warnings.Select(w => w.ToWarning()).ToList() : null,
Metrics = metrics != null ? metrics.ToMetrics() : null,

results.ToList() is failing because results is null… must be replaced by results?.ToList();





The constructor above that initializes the results member, so it’s never null:

public QueryResultData()
    results = new List<T>();
    errors = new List<ErrorData>();
    warnings = new List<WarningData>();
    metrics = new MetricsData();

If there is a syntax error, I would expect the Rows member to be empty. Instead, there should be error messages in the Errors member.



Hi Brant,

Unfortunatly after creating the object you deserialized the response to that object. And in this case the results become null in case of errors:





In my testing of the client that wasn’t happening, I wonder what the difference is. I’m using 2.4.0 of the client and 4.6.0 of Couchbase Server. What are you using?

I’m wondering if the server version you’re running against is actually returning “results: null”, in my testing the results attribute was just missing on an error.



I think this must depend of the settings of the deserializer. In the goal of reducing the size of the document, we are using those settings:
NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.IgnoreAndPopulate;

I m using the client 2.4.0 (Master branch) and Couchbase 4.6



@david.allaigre -

Thanks for the additional information, we’ll look deeper into this.




I’ve confirm the bug is related to using the setting DefaultValueHandling.IgnoreAndPopulate. I’ve filed a bug report and I’m working on the fix:

In the interim, using DefaultValueHandling.Ignore instead of IgnoreAndPopulate avoids the bug. Based on the documentation, this only affects deserialization and not serialization, so it should still keep your document size down.

That said, from my personal experience I don’t recommend using a blanket setting like that on your documents. I find that it makes writing queries and reading data in the query workbench more difficult. I just exclude specific properties that I feel like can be excluded when null/default using [JsonProperty()] attributes on those properties.