diff --git a/src/ClientServer/Config/Constants.cs b/src/ClientServer/Config/Constants.cs index d1aae06d1f757df43e22d11149b8abecf1fe5d51..518010953bff43194d85901727ebd94672a91c40 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.6.0"; + public static string VersionString = "2.6.1"; /// <summary> /// this is only set once at program.cs!! diff --git a/src/ClientServer/Controllers/ControllerWithDb.cs b/src/ClientServer/Controllers/ControllerWithDb.cs index ff2bc632de9135d8d1169f04508922a9d3d9a4b3..706801ba1ee2ecba319431358db3f240e61580ad 100644 --- a/src/ClientServer/Controllers/ControllerWithDb.cs +++ b/src/ClientServer/Controllers/ControllerWithDb.cs @@ -32,12 +32,12 @@ namespace ClientServer.Controllers public Task HandleDbError(Exception ex) { //Exception.toString() is more verbose than just the exception + inner... - Console.WriteLine("[DB ERROR]: " + ex); + string errorMsg = ExceptionHelper.GetAndLogException(ex, "server db error"); if (AppConfiguration.IsDebugMode) { return - Response.WriteAsync(Jc.Serialize(new BasicResponse(ResponseCode.ServerError, ex.Message))); + Response.WriteAsync(Jc.Serialize(new BasicResponse(ResponseCode.ServerError, errorMsg))); } return diff --git a/src/ClientServer/Controllers/Core/Exercises/SubmissionController.cs b/src/ClientServer/Controllers/Core/Exercises/SubmissionController.cs index c2fb0585eee2ca23fef6ae1440491dbf40d42810..8bcb719ffdb0857256fa192ad2309c09e338d59b 100644 --- a/src/ClientServer/Controllers/Core/Exercises/SubmissionController.cs +++ b/src/ClientServer/Controllers/Core/Exercises/SubmissionController.cs @@ -1037,12 +1037,14 @@ namespace ClientServer.Controllers.Core.Exercises catch (System.Exception ex) { + string errorMessage = + ExceptionHelper.GetAndLogException(ex, "could not process line " + lineCount + ", error: "); + if (AppConfiguration.IsDebugMode) { await Response.WriteAsync( - Jc.Serialize(new BasicResponse(ResponseCode.InvalidRequest, - "could not process line " + lineCount + ", error: " + ex))); + Jc.Serialize(new BasicResponse(ResponseCode.InvalidRequest, errorMessage))); } else { diff --git a/src/ClientServer/Controllers/Core/Testing/TestingController.cs b/src/ClientServer/Controllers/Core/Testing/TestingController.cs index 83483bc2368ceb7c537797f93174eb4a4e9d10e9..36b12ee1102bbd28879b25983fcf24d999843d49 100644 --- a/src/ClientServer/Controllers/Core/Testing/TestingController.cs +++ b/src/ClientServer/Controllers/Core/Testing/TestingController.cs @@ -228,7 +228,6 @@ namespace ClientServer.Controllers.Core.Testing return; } - await _WriteCompileTestResult(answerFromTestServer); } @@ -551,7 +550,6 @@ namespace ClientServer.Controllers.Core.Testing return; } - await _WriteCompileTestResult(answerFromTestServer); } @@ -1442,10 +1440,12 @@ namespace ClientServer.Controllers.Core.Testing catch (Exception ex) { //we create this exception so it should be ok to send just the message... - Console.WriteLine("ERROR creating tests with test files: " + ex); + + string errorMessage = ExceptionHelper.GetAndLogException(ex, "ERROR creating tests with test files"); + await Response.WriteAsync( - Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message))); + Jc.Serialize(new BasicResponse(ResponseCode.NotFound, errorMessage))); return; } @@ -1823,10 +1823,10 @@ namespace ClientServer.Controllers.Core.Testing catch (Exception ex) { //we create this exception so it should be ok to send just the message... - Console.WriteLine("ERROR creating tests with test files: " + ex); + string errorMessage = ExceptionHelper.GetAndLogException(ex, "ERROR creating tests with test files"); await Response.WriteAsync( - Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message))); + Jc.Serialize(new BasicResponse(ResponseCode.NotFound, errorMessage))); return; } @@ -2009,10 +2009,10 @@ namespace ClientServer.Controllers.Core.Testing catch (Exception ex) { //we create this exception so it should be ok to send just the message... - Console.WriteLine("ERROR creating tests with test files: " + ex); + string errorMessage = ExceptionHelper.GetAndLogException(ex, "ERROR creating tests with test files"); await Response.WriteAsync( - Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message))); + Jc.Serialize(new BasicResponse(ResponseCode.NotFound, errorMessage))); return; } @@ -2251,10 +2251,10 @@ namespace ClientServer.Controllers.Core.Testing catch (Exception ex) { //we create this exception so it should be ok to send just the message... - Console.WriteLine("ERROR creating tests with test files: " + ex); + string errorMessage = ExceptionHelper.GetAndLogException(ex, "ERROR creating tests with test files"); await Response.WriteAsync( - Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message))); + Jc.Serialize(new BasicResponse(ResponseCode.NotFound, errorMessage))); return; } @@ -2448,10 +2448,10 @@ namespace ClientServer.Controllers.Core.Testing catch (Exception ex) { //we create this exception so it should be ok to send just the message... - Console.WriteLine("ERROR creating tests with test files: " + ex); + string errorMessage = ExceptionHelper.GetAndLogException(ex, "ERROR creating tests with test files"); await Response.WriteAsync( - Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message))); + Jc.Serialize(new BasicResponse(ResponseCode.NotFound, errorMessage))); return; } @@ -2832,10 +2832,10 @@ namespace ClientServer.Controllers.Core.Testing catch (Exception ex) { //we create this exception so it should be ok to send just the message... - Console.WriteLine("ERROR creating tests with test files: " + ex); + string errorMessage = ExceptionHelper.GetAndLogException(ex, "ERROR creating tests with test files"); await Response.WriteAsync( - Jc.Serialize(new BasicResponse(ResponseCode.NotFound, ex.Message))); + Jc.Serialize(new BasicResponse(ResponseCode.NotFound, errorMessage))); return; } @@ -3246,11 +3246,16 @@ namespace ClientServer.Controllers.Core.Testing else { //not a task timeout exception... get some more info - Console.WriteLine("ERROR getting test server result: " + ex); + + string errorDescription = "error during connecting to test server"; + string errorMessage = + ExceptionHelper.GetAndLogException(ex, errorDescription); + + errorMessageDuringRequest = errorDescription; if (AppConfiguration.IsDebugMode) { - errorMessageDuringRequest = "error during connecting to test server: " + ex; + errorMessageDuringRequest = errorMessage; } } } diff --git a/src/ClientServer/Helpers/ExceptionHelper.cs b/src/ClientServer/Helpers/ExceptionHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..515195e1be54cbf6b351dddbf615ca78617708d5 --- /dev/null +++ b/src/ClientServer/Helpers/ExceptionHelper.cs @@ -0,0 +1,25 @@ +using System; + +namespace ClientServer.Helpers +{ + public static class ExceptionHelper + { + /// <summary> + /// a full stack trace might be too much for debug mode... just return exception message and first inner exception + /// the full stack trace should be logged to the console + /// + /// this should be only called if <see cref="AppConfiguration.IsDebugMode"/> is true! else a generic error string should be returned e.g. only db server error + /// </summary> + /// <param name="ex"></param> + /// <param name="errorDescription">some description e.g. db error or the file name to be logged to the console</param> + /// <returns></returns> + public static string GetAndLogException(Exception ex, string errorDescription) + { + + var exceptionGuid = Guid.NewGuid().ToString(); + Console.WriteLine($"[{errorDescription}] - {exceptionGuid} - " + ex); + + return "[" + errorDescription + "] - guid: " + exceptionGuid + " - " + ex.Message + " | " + (ex.InnerException != null ? ex.InnerException.Message : ""); + } + } +}