File indexing completed on 2024-11-24 04:49:50
0001 /* -*- c++ -*- 0002 error.cpp 0003 0004 This file is part of KSieve, 0005 the KDE internet mail/usenet news message filtering library. 0006 SPDX-FileCopyrightText: 2002-2003 Marc Mutz <mutz@kde.org> 0007 0008 SPDX-License-Identifier: GPL-2.0-only 0009 */ 0010 0011 #include "error.h" 0012 0013 #include <KLocalizedString> // i18n 0014 0015 #include <climits> // UINT_MAX 0016 0017 namespace KSieve 0018 { 0019 const char *Error::typeToString(Type t) 0020 { 0021 switch (t) { 0022 #define CASE(x) \ 0023 case x: \ 0024 return #x 0025 CASE(None); 0026 CASE(Custom); 0027 0028 CASE(CRWithoutLF); 0029 CASE(SlashWithoutAsterisk); 0030 CASE(IllegalCharacter); 0031 CASE(UnexpectedCharacter); 0032 CASE(NoLeadingDigits); 0033 CASE(NonCWSAfterTextColon); 0034 0035 CASE(NumberOutOfRange); 0036 CASE(InvalidUTF8); 0037 0038 CASE(UnfinishedBracketComment); 0039 CASE(PrematureEndOfMultiLine); 0040 CASE(PrematureEndOfQuotedString); 0041 CASE(PrematureEndOfStringList); 0042 CASE(PrematureEndOfTestList); 0043 CASE(PrematureEndOfBlock); 0044 CASE(MissingWhitespace); 0045 CASE(MissingSemicolonOrBlock); 0046 0047 CASE(ExpectedBlockOrSemicolon); 0048 CASE(ExpectedCommand); 0049 CASE(ConsecutiveCommasInStringList); 0050 CASE(ConsecutiveCommasInTestList); 0051 CASE(MissingCommaInTestList); 0052 CASE(MissingCommaInStringList); 0053 CASE(NonStringInStringList); 0054 CASE(NonCommandInCommandList); 0055 CASE(NonTestInTestList); 0056 0057 CASE(RequireNotFirst); 0058 CASE(RequireMissingForCommand); 0059 CASE(RequireMissingForTest); 0060 CASE(RequireMissingForComparator); 0061 CASE(UnsupportedCommand); 0062 CASE(UnsupportedTest); 0063 CASE(UnsupportedComparator); 0064 CASE(TestNestingTooDeep); 0065 CASE(BlockNestingTooDeep); 0066 CASE(InvalidArgument); 0067 CASE(ConflictingArguments); 0068 CASE(ArgumentsRepeated); 0069 CASE(CommandOrderingConstraintViolation); 0070 0071 CASE(IncompatibleActionsRequested); 0072 CASE(MailLoopDetected); 0073 CASE(TooManyActions); 0074 #undef CASE 0075 default: 0076 return "<unknown>"; 0077 } 0078 } 0079 0080 QString Error::asString() const 0081 { 0082 QString err; 0083 switch (type()) { 0084 case None: 0085 return {}; 0086 case Custom: 0087 return mStringOne; 0088 0089 // Parse errors: 0090 case CRWithoutLF: 0091 err = i18n("Parse error: Carriage Return (CR) without Line Feed (LF)"); 0092 break; 0093 case SlashWithoutAsterisk: 0094 err = i18n( 0095 "Parse error: Unquoted Slash ('/') without Asterisk ('*'). " 0096 "Broken Comment?"); 0097 break; 0098 case IllegalCharacter: 0099 err = i18n("Parse error: Illegal Character"); 0100 break; 0101 case UnexpectedCharacter: 0102 err = i18n("Parse error: Unexpected Character, probably a missing space?"); 0103 break; 0104 case NoLeadingDigits: 0105 err = i18n("Parse error: Tag Name has leading Digits"); 0106 break; 0107 case NonCWSAfterTextColon: 0108 err = i18n( 0109 "Parse error: Only whitespace and #comments may " 0110 "follow \"text:\" on the same line"); 0111 break; 0112 case NumberOutOfRange: 0113 err = i18n("Parse error: Number out of Range (must be smaller than %1)", UINT_MAX); 0114 break; 0115 case InvalidUTF8: 0116 err = i18n("Parse error: Invalid UTF-8 sequence"); 0117 break; 0118 case PrematureEndOfMultiLine: 0119 err = i18n("Parse error: Premature end of Multiline String (did you forget the '.'?)"); 0120 break; 0121 case PrematureEndOfQuotedString: 0122 err = i18n("Parse error: Premature end of Quoted String (missing closing '\"')"); 0123 break; 0124 case PrematureEndOfStringList: 0125 err = i18n("Parse error: Premature end of String List (missing closing ']')"); 0126 break; 0127 case PrematureEndOfTestList: 0128 err = i18n("Parse error: Premature end of Test List (missing closing ')')"); 0129 break; 0130 case PrematureEndOfBlock: 0131 err = i18n("Parse error: Premature end of Block (missing closing '}')"); 0132 break; 0133 case MissingWhitespace: 0134 err = i18n("Parse error: Missing Whitespace"); 0135 break; 0136 case MissingSemicolonOrBlock: 0137 err = i18n("Parse error: Missing ';' or Block"); 0138 break; 0139 case ExpectedBlockOrSemicolon: 0140 err = i18n("Parse error: Expected ';' or '{', got something else"); 0141 break; 0142 case ExpectedCommand: 0143 err = i18n("Parse error: Expected Command, got something else"); 0144 break; 0145 case ConsecutiveCommasInStringList: 0146 err = i18n("Parse error: Trailing, Leading or Duplicate Commas in String List"); 0147 break; 0148 case ConsecutiveCommasInTestList: 0149 err = i18n("Parse error: Trailing, Leading or Duplicate Commas in Test List"); 0150 break; 0151 case MissingCommaInStringList: 0152 err = i18n("Parse error: Missing ',' between Strings in String List"); 0153 break; 0154 case MissingCommaInTestList: 0155 err = i18n("Parse error: Missing ',' between Tests in Test List"); 0156 break; 0157 case NonCommandInCommandList: 0158 err = i18n("Parse error: Expected Command, got something else"); 0159 break; 0160 case NonStringInStringList: 0161 err = i18n("Parse error: Only Strings allowed in String Lists"); 0162 break; 0163 case NonTestInTestList: 0164 err = i18n("Parse error: Only Tests allowed in Test Lists"); 0165 break; 0166 0167 // validity errors: 0168 case RequireNotFirst: 0169 err = i18n("\"require\" must be first command"); 0170 break; 0171 case RequireMissingForCommand: 0172 err = i18n("\"require\" missing for command \"%1\"", mStringOne); 0173 break; 0174 case RequireMissingForTest: 0175 err = i18n("\"require\" missing for test \"%1\"", mStringOne); 0176 break; 0177 case RequireMissingForComparator: 0178 err = i18n("\"require\" missing for comparator \"%1\"", mStringOne); 0179 break; 0180 case UnsupportedCommand: 0181 err = i18n("Command \"%1\" not supported", mStringOne); 0182 break; 0183 case UnsupportedTest: 0184 err = i18n("Test \"%1\" not supported", mStringOne); 0185 break; 0186 case UnsupportedComparator: 0187 err = i18n("Comparator \"%1\" not supported", mStringOne); 0188 break; 0189 case TestNestingTooDeep: 0190 err = i18n("Site Policy Limit Violation: Test nesting too deep (max. %1)", mStringOne.toUInt()); 0191 break; 0192 case BlockNestingTooDeep: 0193 err = i18n("Site Policy Limit Violation: Block nesting too deep (max. %1)", mStringOne.toUInt()); 0194 break; 0195 case InvalidArgument: 0196 err = i18n("Invalid Argument \"%1\" to \"%2\"", mStringOne, mStringTwo); 0197 break; 0198 case ConflictingArguments: 0199 err = i18n("Conflicting Arguments: \"%1\" and \"%2\"", mStringOne, mStringTwo); 0200 break; 0201 case ArgumentsRepeated: 0202 err = i18n("Argument \"%1\" Repeated", mStringOne); 0203 break; 0204 case CommandOrderingConstraintViolation: 0205 err = i18n("Command \"%1\" violates command ordering constraints", mStringOne); 0206 break; 0207 0208 // runtime errors: 0209 case IncompatibleActionsRequested: 0210 err = i18n("Incompatible Actions \"%1\" and \"%2\" requested", mStringOne, mStringTwo); 0211 break; 0212 case MailLoopDetected: 0213 err = i18n("Mail Loop detected"); 0214 break; 0215 case TooManyActions: 0216 err = i18n("Site Policy Limit Violation: Too many Actions requested (max. %1)", mStringOne.toUInt()); 0217 break; 0218 default: 0219 err = i18n("Unknown error"); 0220 break; 0221 } 0222 0223 return err; 0224 } 0225 } // namespace KSieve