/// <summary> /// Interprets the specified exception into a new exception /// </summary> /// <param name="exception">The exception to be interpreted</param> /// <param name="innerInterpreter">An interpreter that should be applied to the inner exception. /// <returns>The interpreted exception</returns> public Exception Interpret(Exception exception, IExceptionInterpreter innerInterpreter) { var pe = (PythonException)exception; var message = pe.Message + PythonUtil.PythonExceptionStackParser(pe.StackTrace); return(new Exception(message, pe)); }
public void ParsesPythonExceptionStackTrace(string expected, string original, int shift) { var originalShiftValue = PythonUtil.ExceptionLineShift; PythonUtil.ExceptionLineShift = shift; var result = PythonUtil.PythonExceptionStackParser(original); PythonUtil.ExceptionLineShift = originalShiftValue; Assert.AreEqual(expected, result); }
/// <summary> /// Interprets the specified exception into a new exception /// </summary> /// <param name="exception">The exception to be interpreted</param> /// <param name="innerInterpreter">An interpreter that should be applied to the inner exception.</param> /// <returns>The interpreted exception</returns> public override Exception Interpret(Exception exception, IExceptionInterpreter innerInterpreter) { var pe = (PythonException)exception; var types = pe.Message.Split(':')[2].Trim(); var message = $"Trying to perform a summation, subtraction, multiplication or division between {types} objects throws a TypeError exception. To prevent the exception, ensure that both values share the same type."; message += PythonUtil.PythonExceptionStackParser(pe.StackTrace); return(new Exception(message, pe)); }
/// <summary> /// Interprets the specified exception into a new exception /// </summary> /// <param name="exception">The exception to be interpreted</param> /// <param name="innerInterpreter">An interpreter that should be applied to the inner exception.</param> /// <returns>The interpreted exception</returns> public override Exception Interpret(Exception exception, IExceptionInterpreter innerInterpreter) { var pe = (PythonException)exception; var startIndex = pe.Message.LastIndexOfInvariant(" "); var methodName = pe.Message.Substring(startIndex).Trim(); var message = $"Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the {methodName} method. Please checkout the API documentation."; message += PythonUtil.PythonExceptionStackParser(pe.StackTrace); return(new MissingMethodException(message, pe)); }
/// <summary> /// Interprets the specified exception into a new exception /// </summary> /// <param name="exception">The exception to be interpreted</param> /// <param name="innerInterpreter">An interpreter that should be applied to the inner exception.</param> /// <returns>The interpreted exception</returns> public override Exception Interpret(Exception exception, IExceptionInterpreter innerInterpreter) { var pe = (PythonException)exception; var key = string.Empty; if (pe.Message.Contains("[")) { key = pe.Message.GetStringBetweenChars('[', ']'); } else if (pe.Message.Contains("\'")) { key = pe.Message.GetStringBetweenChars('\'', '\''); } var message = $"Trying to retrieve an element from a collection using a key that does not exist in that collection throws a KeyError exception. To prevent the exception, ensure that the {key} key exist in the collection and/or that collection is not empty."; message += PythonUtil.PythonExceptionStackParser(pe.StackTrace); return(new KeyNotFoundException(message, pe)); }