Example #1
0
        private void PublishError(BoltResponseMessageWriter messageWriter, Neo4jError error)
        {
            try
            {
                if (error.Fatal)
                {
                    messageWriter.Write(new FatalFailureMessage(error.Status(), error.Message()));
                }
                else
                {
                    messageWriter.Write(new FailureMessage(error.Status(), error.Message()));
                }
            }
            catch (PackOutputClosedException e)
            {
                // Can't write error to the client, because the connection is closed.
                // Very likely our error is related to the connection being closed.

                // If the error is that the transaction was terminated, then the error is a side-effect of
                // us cleaning up stuff that was running when the client disconnected. Log a warning without
                // stack trace to highlight clients are disconnecting while stuff is running:
                if (_clientMidOpDisconnectErrors.Contains(error.Status()))
                {
                    Log.warn("Client %s disconnected while query was running. Session has been cleaned up. " + "This can be caused by temporary network problems, but if you see this often, " + "ensure your applications are properly waiting for operations to complete before exiting.", e.ClientAddress());
                    return;
                }

                // If the error isn't that the tx was terminated, log it to the console for debugging. It's likely
                // there are other "ok" errors that we can whitelist into the conditional above over time.
                Log.warn("Unable to send error back to the client. " + e.Message, error.Cause());
            }
            catch (Exception t)
            {
                // some unexpected error happened while writing exception back to the client
                // log it together with the original error being suppressed
                t.addSuppressed(error.Cause());
                Log.error("Unable to send error back to the client", t);
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void testLoggingOfWriteErrorAndOriginalErrorWhenUnknownFailure(org.neo4j.bolt.runtime.Neo4jError original) throws Exception
        private static void TestLoggingOfWriteErrorAndOriginalErrorWhenUnknownFailure(Neo4jError original)
        {
            Exception             outputError = new Exception("Output failed");
            AssertableLogProvider logProvider = EmulateFailureWritingError(original, outputError);

            logProvider.AssertExactly(inLog("Test").error(startsWith("Unable to send error back to the client"), both(equalTo(outputError)).and(hasSuppressed(original.Cause()))));
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void testLoggingOfOriginalErrorWhenOutputIsClosed(org.neo4j.bolt.runtime.Neo4jError original) throws Exception
        private static void TestLoggingOfOriginalErrorWhenOutputIsClosed(Neo4jError original)
        {
            PackOutputClosedException outputClosed = new PackOutputClosedException("Output closed", "<client>");
            AssertableLogProvider     logProvider  = EmulateFailureWritingError(original, outputClosed);

            logProvider.AssertExactly(inLog("Test").warn(startsWith("Unable to send error back to the client"), equalTo(original.Cause())));
        }