/// <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.
        /// This provides a link back allowing the inner exceptions to be interpreted using the intepretators
        /// configured in the <see cref="StackExceptionInterpreter"/>. Individual implementations *may* ignore
        /// this value if required.</param>
        /// <returns>The interpreted exception</returns>
        public Exception Interpret(Exception exception, IExceptionInterpreter innerInterpreter)
        {
            if (exception == null)
            {
                return(null);
            }

            foreach (var interpreter in _interpreters)
            {
                try
                {
                    if (interpreter.CanInterpret(exception))
                    {
                        // use this instance to interpret inner exceptions as well, unless one was specified
                        return(interpreter.Interpret(exception, innerInterpreter ?? this));
                    }
                }
                catch (Exception err)
                {
                    Log.Error(err);
                }
            }

            return(exception);
        }
Example #2
0
 /// <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 Exception Interpret(Exception exception, IExceptionInterpreter innerInterpreter)
 {
     if (!TryGetLineAndFile(exception.StackTrace, out var fileAndLine))
     {
         return(exception);
     }
     return(new Exception(exception.Message + fileAndLine, exception));
 }
        /// <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));
        }
Example #4
0
        /// <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   = "Trying to include an invalid token/character in any statement throws a SyntaxError exception. To prevent the exception, ensure no invalid token are mistakenly included (e.g: leading zero).";
            var errorLine = pe.Message.GetStringBetweenChars('(', ')');

            return(new Exception($"{message}{Environment.NewLine}  in {errorLine}{Environment.NewLine}", 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.
        /// <returns>The interpreted exception</returns>
        public Exception Interpret(Exception exception, IExceptionInterpreter innerInterpreter)
        {
            var dnfe = (DllNotFoundException)exception;

            var dllName  = dnfe.Message.GetStringBetweenChars('\'', '\'');
            var platform = Environment.OSVersion.Platform.ToString();
            var message  = $"The dynamic-link library for {dllName} could not be found. Please visit https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/readme.md for instructions on how to enable python support in {platform}";

            return(new DllNotFoundException(message, dnfe));
        }
Example #6
0
        /// <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));
        }
Example #7
0
        /// <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.
        /// This provides a link back allowing the inner exceptions to be interpreted using the intepretators
        /// configured in the <see cref="Interpreter"/>. Individual implementations *may* ignore
        /// this value if required.</param>
        /// <returns>The interpreted exception</returns>
        public Exception Interpret(Exception exception, IExceptionInterpreter innerInterpreter)
        {
            var see = (ScheduledEventException)exception;

            var inner = innerInterpreter.Interpret(see.InnerException, innerInterpreter);

            // prepend the scheduled event name
            var message = exception.Message;

            if (!message.Contains(see.ScheduledEventName))
            {
                message = $"In Scheduled Event '{see.ScheduledEventName}',";
            }

            return(new ScheduledEventException(see.ScheduledEventName, message, inner));
        }
        /// <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 Exception Interpret(Exception exception, IExceptionInterpreter innerInterpreter)
        {
            var dnfe = (DllNotFoundException)exception;

            var startIndex = dnfe.Message.IndexOfInvariant("python");
            var length     = Math.Min(dnfe.Message.Length - startIndex, 10);
            var dllName    = dnfe.Message.Substring(startIndex, length);

            length = dllName.IndexOfInvariant('\'');
            if (length > 0)
            {
                dllName = dllName.Substring(0, length);
            }

            var platform = Environment.OSVersion.Platform.ToString();
            var message  = $"The dynamic-link library for {dllName} could not be found. Please visit https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/readme.md for instructions on how to enable python support in {platform}";

            return(new DllNotFoundException(message, dnfe));
        }
        /// <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));
        }
 public Exception Interpret(Exception exception, IExceptionInterpreter innerInterpreter)
 {
     return(_interpret(exception));
 }
        /// <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 virtual Exception Interpret(Exception exception, IExceptionInterpreter innerInterpreter)
        {
            var pe = (PythonException)exception;

            return(new Exception(PythonUtil.PythonExceptionParser(pe), pe));
        }