From 6d262a94bb44cdc409238e618b8308ac87ac9e1d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Janis=20Daniel=20Da=CC=88hne?=
 <janis.daehne2@student.uni-halle.de>
Date: Sat, 16 Nov 2019 15:24:31 +0100
Subject: [PATCH] - reduces error message spamming when the connection to the
 test server timed out

---
 src/ClientServer/Config/Constants.cs          |  2 +-
 .../Controllers/ControllerWithDb.cs           |  2 +-
 .../Core/Testing/TestingController.cs         | 80 +++++++++++--------
 3 files changed, 50 insertions(+), 34 deletions(-)

diff --git a/src/ClientServer/Config/Constants.cs b/src/ClientServer/Config/Constants.cs
index ad463b6..f331451 100644
--- a/src/ClientServer/Config/Constants.cs
+++ b/src/ClientServer/Config/Constants.cs
@@ -13,7 +13,7 @@ namespace ClientServer.Helpers
     /// </summary>
     public static class Constants
     {
-        public static string VersionString = "2.5.11";
+        public static string VersionString = "2.5.12";
 
         /// <summary>
         /// this is only set once at program.cs!!
diff --git a/src/ClientServer/Controllers/ControllerWithDb.cs b/src/ClientServer/Controllers/ControllerWithDb.cs
index 5e6b0d0..ff2bc63 100644
--- a/src/ClientServer/Controllers/ControllerWithDb.cs
+++ b/src/ClientServer/Controllers/ControllerWithDb.cs
@@ -37,7 +37,7 @@ namespace ClientServer.Controllers
             if (AppConfiguration.IsDebugMode)
             {
                 return
-                    Response.WriteAsync(Jc.Serialize(new BasicResponse(ResponseCode.ServerError, ex.ToString())));
+                    Response.WriteAsync(Jc.Serialize(new BasicResponse(ResponseCode.ServerError, ex.Message)));
             }
 
             return
diff --git a/src/ClientServer/Controllers/Core/Testing/TestingController.cs b/src/ClientServer/Controllers/Core/Testing/TestingController.cs
index e9d623b..657ca4d 100644
--- a/src/ClientServer/Controllers/Core/Testing/TestingController.cs
+++ b/src/ClientServer/Controllers/Core/Testing/TestingController.cs
@@ -210,12 +210,13 @@ namespace ClientServer.Controllers.Core.Testing
             }
             catch (Exception ex)
             {
+                //all request related errors should be caught in _RunTestOnTestServer ... so we should not get here 
                 Console.WriteLine("ERROR: test server timeout hit?: " + ex);
                 //probably timeout hit (not from the test program but the request
                 string reason = "";
                 if (AppConfiguration.IsDebugMode)
                 {
-                    reason = ", error: " + ex;
+                    reason = ", error: " + ex.Message; //only show msg to frontend not the full trace...
                 }
 
                 await
@@ -356,12 +357,13 @@ namespace ClientServer.Controllers.Core.Testing
             }
             catch (Exception ex)
             {
+                //all request related errors should be caught in _RunTestOnTestServer ... so we should not get here 
                 Console.WriteLine("ERROR: test server timeout hit?: " + ex);
                 //probably timeout hit (not from the test program but the request
                 string reason = "";
                 if (AppConfiguration.IsDebugMode)
                 {
-                    reason = ", error: " + ex;
+                    reason = ", error: " + ex.Message;
                 }
 
                 await
@@ -527,12 +529,13 @@ namespace ClientServer.Controllers.Core.Testing
             }
             catch (Exception ex)
             {
+                //all request related errors should be caught in _RunTestOnTestServer ... so we should not get here 
                 Console.WriteLine("ERROR: test server timeout hit?: " + ex);
                 //probably timeout hit (not from the test program but the request
                 string reason = "";
                 if (AppConfiguration.IsDebugMode)
                 {
-                    reason = ", error: " + ex;
+                    reason = ", error: " + ex.Message;
                 }
 
                 await
@@ -1417,13 +1420,13 @@ namespace ClientServer.Controllers.Core.Testing
             {
                 allTests = tests.Select(p => AllTest.CreateFrom(p, testFilesDict)).ToList();
             }
-            catch (Exception e)
+            catch (Exception ex)
             {
                 //we create this exception so it should be ok to send just the message...
-                Console.WriteLine("ERROR " + e);
+                Console.WriteLine("ERROR creating tests with test files: " + ex);
                 await
                     Response.WriteAsync(
-                        Jc.Serialize(new BasicResponse(ResponseCode.NotFound, e.Message)));
+                        Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message)));
                 return;
             }
 
@@ -1539,8 +1542,8 @@ namespace ClientServer.Controllers.Core.Testing
                     oldResult.TimeForUserProgram = testResult.TimeForUserProgram;
                     oldResult.TimeoutInMsUsed = testResult.TimeoutInMsUsed;
                     oldResult.CompileTimeoutInMsUsed = testResult.CompileTimeoutInMsUsed;
-                   oldResult.CharacterLimitExceeded = testResult.CharacterLimitExceeded;
-                   oldResult.CharacterLimitUsed = testResult.CharacterLimitUsed;
+                    oldResult.CharacterLimitExceeded = testResult.CharacterLimitExceeded;
+                    oldResult.CharacterLimitUsed = testResult.CharacterLimitUsed;
                 }
 
                 try
@@ -1550,7 +1553,7 @@ namespace ClientServer.Controllers.Core.Testing
                 catch (Exception ex)
                 {
                    await base.HandleDbError(ex);
-                    return;
+                   return;
                 }
             }
 
@@ -1793,13 +1796,13 @@ namespace ClientServer.Controllers.Core.Testing
                 {
                     allTests = tests.Select(p => AllTest.CreateFrom(p, testFilesDict)).ToList();
                 }
-                catch (Exception e)
+                catch (Exception ex)
                 {
                     //we create this exception so it should be ok to send just the message...
-                    Console.WriteLine("ERROR " + e);
+                    Console.WriteLine("ERROR creating tests with test files: " + e);
                     await
                         Response.WriteAsync(
-                            Jc.Serialize(new BasicResponse(ResponseCode.NotFound, e.Message)));
+                            Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message)));
                     return;
                 }
                 
@@ -1974,13 +1977,13 @@ namespace ClientServer.Controllers.Core.Testing
                 {
                     allTests = tests.Select(p => AllTest.CreateFrom(p, defaultCustomTestSettings, testFilesDict)).ToList();
                 }
-                catch (Exception e)
+                catch (Exception ex)
                 {
                     //we create this exception so it should be ok to send just the message...
-                    Console.WriteLine("ERROR " + e);
+                    Console.WriteLine("ERROR creating tests with test files: " + e);
                     await
                         Response.WriteAsync(
-                            Jc.Serialize(new BasicResponse(ResponseCode.NotFound, e.Message)));
+                            Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message)));
                     return;
                 }
 
@@ -2211,13 +2214,13 @@ namespace ClientServer.Controllers.Core.Testing
             {
                 allTests = tests.Select(p => AllTest.CreateFrom(p, defaultCustomTestSettings, testFilesDict)).ToList();
             }
-            catch (Exception e)
+            catch (Exception ex)
             {
                 //we create this exception so it should be ok to send just the message...
-                Console.WriteLine("ERROR " + e);
+                Console.WriteLine("ERROR creating tests with test files: " + e);
                 await
                     Response.WriteAsync(
-                        Jc.Serialize(new BasicResponse(ResponseCode.NotFound, e.Message)));
+                        Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message)));
                 return;
             }
 
@@ -2404,13 +2407,13 @@ namespace ClientServer.Controllers.Core.Testing
             {
                 allTests = tests.Select(p => AllTest.CreateFrom(p, testFilesDict)).ToList();
             }
-            catch (Exception e)
+            catch (Exception ex)
             {
                 //we create this exception so it should be ok to send just the message...
-                Console.WriteLine("ERROR " + e);
+                Console.WriteLine("ERROR creating tests with test files: " + e);
                 await
                     Response.WriteAsync(
-                        Jc.Serialize(new BasicResponse(ResponseCode.NotFound, e.Message)));
+                        Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message)));
                 return;
             }
             
@@ -2784,13 +2787,13 @@ namespace ClientServer.Controllers.Core.Testing
             {
                 allTests = tests.Select(p => AllTest.CreateFrom(p, testFilesDict)).ToList();
             }
-            catch (Exception e)
+            catch (Exception ex)
             {
                 //we create this exception so it should be ok to send just the message...
-                Console.WriteLine("ERROR " + e);
+                Console.WriteLine("ERROR creating tests with test files: " + e);
                 await
                     Response.WriteAsync(
-                        Jc.Serialize(new BasicResponse(ResponseCode.NotFound, e.Message)));
+                        Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message)));
                 return;
             }
 
@@ -2924,12 +2927,13 @@ namespace ClientServer.Controllers.Core.Testing
             }
             catch (Exception ex)
             {
+                //all request related errors should be caught in _RunTestOnTestServer ... so we should not get here 
                 Console.WriteLine("ERROR: test server timeout hit?: " + ex);
                 //probably timeout hit (not from the test program but the request
                 string reason = "";
                 if (AppConfiguration.IsDebugMode)
                 {
-                    reason = ", error: " + ex;
+                    reason = ", error: " + ex.Message;
                 }
 
                 await
@@ -3170,18 +3174,30 @@ namespace ClientServer.Controllers.Core.Testing
                 }
                 catch (Exception ex)
                 {
-                    Console.WriteLine("ERROR getting test server result: " + ex);
-                    //throw;
+                    
                     errorDuringRequest = true;
-
-                    if (AppConfiguration.IsDebugMode)
+                    errorMessageDuringRequest = "error during connecting to test server";
+                    
+                    if (ex is TaskCanceledException)
                     {
-                        errorMessageDuringRequest = "error during connection to test server: " + ex;
+                        //timeout hit...
+                        Console.WriteLine("ERROR getting test server result: timeout was hit (task was canceled)");
+
+                        if (AppConfiguration.IsDebugMode)
+                        {
+                            errorMessageDuringRequest = "error during connecting to test server: timeout was hit";
+                        }
                     }
                     else
                     {
-                        errorMessageDuringRequest = "error during connection to test server";
-                    }                   
+                        //not a task timeout exception... get some more info 
+                        Console.WriteLine("ERROR getting test server result: " + ex);
+
+                        if (AppConfiguration.IsDebugMode)
+                        {
+                            errorMessageDuringRequest = "error during connecting to test server: " + ex;
+                        }
+                    }                 
                 }
             }
 
-- 
GitLab