/* * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Runtime.CompilerServices; using Python.Runtime; using QuantConnect.Exceptions; namespace QuantConnect { /// /// Provides user-facing message construction methods and static messages for the namespace /// public static partial class Messages { /// /// Provides user-facing messages for the class and its consumers or related classes /// public static class DllNotFoundPythonExceptionInterpreter { /// /// Returns a string message saying the given dynamic-link library could not be found /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string DynamicLinkLibraryNotFound(string dllName, string platform) { return $"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}"; } } /// /// Provides user-facing messages for the class and its consumers or related classes /// public static class InvalidTokenPythonExceptionInterpreter { /// /// String message saying: invalid token /// public static string InvalidTokenExpectedSubstring = "invalid token"; /// /// String message saying: are not permitted /// public static string NotPermittedExpectedSubstring = "are not permitted;"; /// /// Returns a string message saying: Tring to include an invalid token/character in any statement throws s SyntaxError /// exception. It also contains an advice to prevent that exception /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string InterpretException(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 = exception.Message.GetStringBetweenChars('(', ')'); return $"{message}{Environment.NewLine} in {errorLine}{Environment.NewLine}"; } } /// /// Provides user-facing messages for the class and its consumers or related classes /// public static class KeyErrorPythonExceptionInterpreter { /// /// Returns a string message saying the given key does not exists in the collection and the exception that is thrown /// in this case. It also advises the user on how to prevent this exception /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string KeyNotFoundInCollection(string key) { return "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."; } } /// /// Provides user-facing messages for the class and its consumers or related classes /// public static class NoMethodMatchPythonExceptionInterpreter { /// /// String message saying: No method match /// public static string NoMethodMatchExpectedSubstring = "No method match"; /// /// Returns a string message saying the given method does not exists. It also contains the exception /// thrown is this case and an advice on how to prevent it /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string AttemptedToAccessMethodThatDoesNotExist(string methodName) { return "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."; } } /// /// Provides user-facing messages for the class and its consumers or related classes /// public static class ScheduledEventExceptionInterpreter { /// /// Returns a string message with the given event name /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ScheduledEventName(string eventName) { return $"In Scheduled Event '{eventName}',"; } } /// /// Provides user-facing messages for the class and its consumers or related classes /// public static class StackExceptionInterpreter { /// /// Returns a message for a Loaded Exception Interpreter /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string LoadedExceptionInterpreter(IExceptionInterpreter interpreter) { return $"Loaded ExceptionInterpreter: {interpreter.GetType().Name}"; } } /// /// Provides user-facing messages for the class and its consumers or related classes /// public static class UnsupportedOperandPythonExceptionInterpreter { /// /// Unsupported Operand Type Expected substring /// public static string UnsupportedOperandTypeExpectedSubstring = "unsupported operand type"; /// /// Returns a message for invalid object types for operation /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string InvalidObjectTypesForOperation(string types) { return $@"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."; } } } }