Skip to content

Commit cef8536

Browse files
Depreview gql status (#879)
* fix null list of notifications * Move GQL out of preview and fix broken test * Fix password value in DefaultInstallation to use the correct default * Fix password retrieval in DefaultInstallation to ensure correct environment variable usage
1 parent ef2de30 commit cef8536

File tree

8 files changed

+41
-97
lines changed

8 files changed

+41
-97
lines changed

Neo4j.Driver/Neo4j.Driver.Tests.Integration/Reactive/TransactionIT.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ public void ShouldFailToBeginTxcWithInvalidBookmark()
272272
.AssertEqual(
273273
OnError<IRxTransaction>(
274274
0,
275-
Matches<Exception>(exc => exc.Message.Should().Contain("InvalidBookmark"))));
275+
Matches<Exception>(exc => {
276+
var ne = exc as Neo4jException;
277+
ne.Should().NotBeNull();
278+
ne?.GqlStatus.Should().Be("08N12");
279+
})));
276280
}
277281

278282
[RequireServerFact("4.0.0", GreaterThanOrEqualTo)]

Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Exceptions/ExceptionManager.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
using System.Linq;
2020
using Neo4j.Driver.Internal;
2121
using Neo4j.Driver.Internal.Connector;
22-
using Neo4j.Driver.Preview.GqlErrors;
2322
using Neo4j.Driver.Tests.TestBackend.Protocol;
2423
using Neo4j.Driver.Tests.TestBackend.Types;
2524

@@ -130,9 +129,8 @@ private static Dictionary<string, object> CreateExceptionDictionary(
130129
bool isCause = false)
131130
{
132131
var ne = ex as Neo4jException;
133-
var gqlError = ne?.GetGqlErrorPreview();
134132
var diagnosticRecord =
135-
gqlError?.GqlDiagnosticRecord?.ToDictionary(y => y.Key, y => NativeToCypher.Convert(y.Value));
133+
ne?.GqlDiagnosticRecord?.ToDictionary(y => y.Key, y => NativeToCypher.Convert(y.Value));
136134

137135
var data = new Dictionary<string, object>();
138136

@@ -147,11 +145,11 @@ private static Dictionary<string, object> CreateExceptionDictionary(
147145
data.OverwriteFrom(
148146
null,
149147
("msg", exceptionMessage),
150-
("gqlStatus", gqlError?.GqlStatus),
151-
("statusDescription", gqlError?.GqlStatusDescription),
148+
("gqlStatus", ne?.GqlStatus),
149+
("statusDescription", ne?.GqlStatusDescription),
152150
("diagnosticRecord", diagnosticRecord),
153-
("rawClassification", gqlError?.GqlRawClassification),
154-
("classification", gqlError?.GqlClassification));
151+
("rawClassification", ne?.GqlRawClassification),
152+
("classification", ne?.GqlClassification));
155153

156154
if (ne?.InnerException != null)
157155
{

Neo4j.Driver/Neo4j.Driver.Tests/GqlCompliance/GqlErrorTests.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using Neo4j.Driver.Internal.ExceptionHandling;
1919
using Neo4j.Driver.Internal.IO.MessageSerializers;
2020
using Neo4j.Driver.Internal.Messaging;
21-
using Neo4j.Driver.Preview.GqlErrors;
2221
using Xunit;
2322

2423
namespace Neo4j.Driver.Tests.GqlCompliance;
@@ -109,16 +108,15 @@ public void GetException_ShouldHandleNestedFailureMessages()
109108
result.Code.Should().Be("Neo.ClientError.Transaction.Terminated");
110109
result.Message.Should().Be("Transaction terminated");
111110

112-
var gqlError = result.GetGqlErrorPreview();
113-
gqlError.GqlStatus.Should().Be("GQL_STATUS_OUTER");
114-
gqlError.GqlStatusDescription.Should().Be("Outer status description");
115-
gqlError.GqlDiagnosticRecord.Should().NotBeNull();
116-
gqlError.GqlDiagnosticRecord["outer_key"].Should().Be("outer_value");
117-
gqlError.GqlRawClassification.Should().Be("OUTER_CLASSIFICATION");
118-
gqlError.GqlClassification.Should().Be("DATABASE_ERROR");
111+
result.GqlStatus.Should().Be("GQL_STATUS_OUTER");
112+
result.GqlStatusDescription.Should().Be("Outer status description");
113+
result.GqlDiagnosticRecord.Should().NotBeNull();
114+
result.GqlDiagnosticRecord["outer_key"].Should().Be("outer_value");
115+
result.GqlRawClassification.Should().Be("OUTER_CLASSIFICATION");
116+
result.GqlClassification.Should().Be("DATABASE_ERROR");
119117

120118
var innerException = (Neo4jException)result.InnerException;
121-
gqlError = innerException.GetGqlErrorPreview();
119+
var gqlError = innerException;
122120
innerException.Should().NotBeNull();
123121
innerException.Should().BeOfType<ClientException>();
124122
innerException.Code.Should().Be("Neo.ClientError.Transaction.LockClientStopped");

Neo4j.Driver/Neo4j.Driver.Tests/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotificationsCollectorTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void ShouldCollectEmptyNotifications()
7070

7171
var collected = collector.Collected;
7272
collected.Should().NotBeNull();
73-
collected.Notifications.Should().NotBeNull().And.BeEmpty();
73+
collected.Notifications.Should().BeNull();
7474
collected.GqlStatusObjects.Should().BeNull();
7575
}
7676

@@ -82,8 +82,8 @@ public void ShouldCollectEmptyStatusesAndPolyfillNotifications()
8282

8383
var collected = collector.Collected;
8484
collected.Should().NotBeNull();
85-
collected.GqlStatusObjects.Should().NotBeNull().And.BeEmpty();
86-
collected.Notifications.Should().NotBeNull().And.BeEmpty();
85+
collected.GqlStatusObjects.Should().BeNull();
86+
collected.Notifications.Should().BeNull();
8787
}
8888

8989
[Fact]

Neo4j.Driver/Neo4j.Driver/Internal/IO/PackStreamWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ public void WriteDictionary(IDictionary<string, object> values)
276276
else
277277
{
278278
WriteMapHeader(values.Count);
279-
foreach (var key in values.Keys)
279+
foreach (var (key, value) in values)
280280
{
281281
WriteString(key);
282-
Write(values[key]);
282+
Write(value);
283283
}
284284
}
285285
}

Neo4j.Driver/Neo4j.Driver/Internal/MessageHandling/Metadata/GqlStatusObjectsAndNotificationsCollector.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ private static IList<T> ConvertObjects<T>(
6565
.Where(y => y is not null)
6666
.ToList();
6767

68-
if (!result.Any())
69-
{
70-
return null;
71-
}
68+
return result.Count != 0 ? result : null;
7269
}
7370

7471
return null;

Neo4j.Driver/Neo4j.Driver/Preview/GqlErrors/IGqlErrorPreview.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

Neo4j.Driver/Neo4j.Driver/Public/Exceptions/Neo4jException.cs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,13 @@
1717
using System.Collections.Generic;
1818
using System.Runtime.Serialization;
1919
using Neo4j.Driver.Internal.Messaging;
20-
using Neo4j.Driver.Preview.GqlErrors;
2120

2221
namespace Neo4j.Driver;
2322

2423
/// <summary>The base class for all Neo4j exceptions.</summary>
2524
[DataContract]
26-
public class Neo4jException : Exception, IGqlErrorPreview
25+
public class Neo4jException : Exception
2726
{
28-
private readonly string _gqlClassification;
29-
private readonly Dictionary<string, object> _gqlDiagnosticRecord;
30-
private readonly string _gqlRawClassification;
31-
private readonly string _gqlStatus;
32-
private readonly string _gqlStatusDescription;
33-
3427
/// <summary>Create a new <see cref="Neo4jException"/></summary>
3528
public Neo4jException()
3629
{
@@ -46,11 +39,11 @@ internal Neo4jException(FailureMessage failureMessage, Exception innerException
4639
: base(failureMessage.Message, innerException)
4740
{
4841
Code = failureMessage.Code;
49-
_gqlStatus = failureMessage.GqlStatus;
50-
_gqlStatusDescription = failureMessage.GqlStatusDescription;
51-
_gqlClassification = failureMessage.GqlClassification;
52-
_gqlRawClassification = failureMessage.GqlRawClassification;
53-
_gqlDiagnosticRecord = failureMessage.GqlDiagnosticRecord;
42+
GqlStatus = failureMessage.GqlStatus;
43+
GqlStatusDescription = failureMessage.GqlStatusDescription;
44+
GqlClassification = failureMessage.GqlClassification;
45+
GqlRawClassification = failureMessage.GqlRawClassification;
46+
GqlDiagnosticRecord = failureMessage.GqlDiagnosticRecord;
5447
}
5548

5649
/// <summary>Create a new <see cref="Neo4jException"/> with an error message</summary>
@@ -100,20 +93,22 @@ public Neo4jException(string code, string message, Exception innerException)
10093
/// <summary>Gets or sets the code of a Neo4j exception.</summary>
10194
public string Code { get; set; }
10295

103-
/// <inheritdoc/>
104-
string IGqlErrorPreview.GqlStatus => _gqlStatus;
96+
/// <summary>Gets the GQL status of the exception.</summary>
97+
public string GqlStatus { get; }
10598

106-
/// <inheritdoc/>
107-
string IGqlErrorPreview.GqlStatusDescription => _gqlStatusDescription;
99+
/// <summary>Gets the GQL status description of the exception.</summary>
100+
public string GqlStatusDescription { get; }
108101

109-
/// <inheritdoc/>
110-
string IGqlErrorPreview.GqlClassification => _gqlClassification;
102+
/// <summary>Gets the GQL classification of the exception.</summary>
103+
public string GqlClassification { get; }
111104

112-
/// <inheritdoc/>
113-
string IGqlErrorPreview.GqlRawClassification => _gqlRawClassification;
105+
/// <summary>The raw classification as received from the server.</summary>
106+
public string GqlRawClassification { get; }
114107

115-
/// <inheritdoc/>
116-
Dictionary<string, object> IGqlErrorPreview.GqlDiagnosticRecord => _gqlDiagnosticRecord;
108+
/// <summary>
109+
/// Gets further information about the status for diagnostic purposes.
110+
/// </summary>
111+
public Dictionary<string, object> GqlDiagnosticRecord { get; }
117112

118113
internal static Neo4jException Create(FailureMessage failureMessage)
119114
{

0 commit comments

Comments
 (0)