Libksieve

error.cpp
1 /* -*- c++ -*-
2  error.cpp
3 
4  This file is part of KSieve,
5  the KDE internet mail/usenet news message filtering library.
6  SPDX-FileCopyrightText: 2002-2003 Marc Mutz <[email protected]>
7 
8  SPDX-License-Identifier: GPL-2.0-only
9 */
10 
11 #include <ksieve/error.h>
12 
13 #include <KLocalizedString> // i18n
14 
15 #include <climits> // UINT_MAX
16 
17 namespace KSieve
18 {
19 const char *Error::typeToString(Type t)
20 {
21  switch (t) {
22 #define CASE(x) \
23  case x: \
24  return #x
25  CASE(None);
26  CASE(Custom);
27 
28  CASE(CRWithoutLF);
29  CASE(SlashWithoutAsterisk);
30  CASE(IllegalCharacter);
31  CASE(UnexpectedCharacter);
32  CASE(NoLeadingDigits);
33  CASE(NonCWSAfterTextColon);
34 
35  CASE(NumberOutOfRange);
36  CASE(InvalidUTF8);
37 
38  CASE(UnfinishedBracketComment);
39  CASE(PrematureEndOfMultiLine);
40  CASE(PrematureEndOfQuotedString);
41  CASE(PrematureEndOfStringList);
42  CASE(PrematureEndOfTestList);
43  CASE(PrematureEndOfBlock);
44  CASE(MissingWhitespace);
45  CASE(MissingSemicolonOrBlock);
46 
47  CASE(ExpectedBlockOrSemicolon);
48  CASE(ExpectedCommand);
49  CASE(ConsecutiveCommasInStringList);
50  CASE(ConsecutiveCommasInTestList);
51  CASE(MissingCommaInTestList);
52  CASE(MissingCommaInStringList);
53  CASE(NonStringInStringList);
54  CASE(NonCommandInCommandList);
55  CASE(NonTestInTestList);
56 
57  CASE(RequireNotFirst);
58  CASE(RequireMissingForCommand);
59  CASE(RequireMissingForTest);
60  CASE(RequireMissingForComparator);
61  CASE(UnsupportedCommand);
62  CASE(UnsupportedTest);
63  CASE(UnsupportedComparator);
64  CASE(TestNestingTooDeep);
65  CASE(BlockNestingTooDeep);
66  CASE(InvalidArgument);
67  CASE(ConflictingArguments);
68  CASE(ArgumentsRepeated);
69  CASE(CommandOrderingConstraintViolation);
70 
71  CASE(IncompatibleActionsRequested);
72  CASE(MailLoopDetected);
73  CASE(TooManyActions);
74 #undef CASE
75  default:
76  return "<unknown>";
77  }
78 }
79 
80 QString Error::asString() const
81 {
82  QString err;
83  switch (type()) {
84  case None:
85  return QString();
86  case Custom:
87  return mStringOne;
88 
89  // Parse errors:
90  case CRWithoutLF:
91  err = i18n("Parse error: Carriage Return (CR) without Line Feed (LF)");
92  break;
93  case SlashWithoutAsterisk:
94  err = i18n(
95  "Parse error: Unquoted Slash ('/') without Asterisk ('*'). "
96  "Broken Comment?");
97  break;
98  case IllegalCharacter:
99  err = i18n("Parse error: Illegal Character");
100  break;
101  case UnexpectedCharacter:
102  err = i18n("Parse error: Unexpected Character, probably a missing space?");
103  break;
104  case NoLeadingDigits:
105  err = i18n("Parse error: Tag Name has leading Digits");
106  break;
107  case NonCWSAfterTextColon:
108  err = i18n(
109  "Parse error: Only whitespace and #comments may "
110  "follow \"text:\" on the same line");
111  break;
112  case NumberOutOfRange:
113  err = i18n("Parse error: Number out of Range (must be smaller than %1)", UINT_MAX);
114  break;
115  case InvalidUTF8:
116  err = i18n("Parse error: Invalid UTF-8 sequence");
117  break;
118  case PrematureEndOfMultiLine:
119  err = i18n("Parse error: Premature end of Multiline String (did you forget the '.'?)");
120  break;
121  case PrematureEndOfQuotedString:
122  err = i18n("Parse error: Premature end of Quoted String (missing closing '\"')");
123  break;
124  case PrematureEndOfStringList:
125  err = i18n("Parse error: Premature end of String List (missing closing ']')");
126  break;
127  case PrematureEndOfTestList:
128  err = i18n("Parse error: Premature end of Test List (missing closing ')')");
129  break;
130  case PrematureEndOfBlock:
131  err = i18n("Parse error: Premature end of Block (missing closing '}')");
132  break;
133  case MissingWhitespace:
134  err = i18n("Parse error: Missing Whitespace");
135  break;
136  case MissingSemicolonOrBlock:
137  err = i18n("Parse error: Missing ';' or Block");
138  break;
139  case ExpectedBlockOrSemicolon:
140  err = i18n("Parse error: Expected ';' or '{', got something else");
141  break;
142  case ExpectedCommand:
143  err = i18n("Parse error: Expected Command, got something else");
144  break;
145  case ConsecutiveCommasInStringList:
146  err = i18n("Parse error: Trailing, Leading or Duplicate Commas in String List");
147  break;
148  case ConsecutiveCommasInTestList:
149  err = i18n("Parse error: Trailing, Leading or Duplicate Commas in Test List");
150  break;
151  case MissingCommaInStringList:
152  err = i18n("Parse error: Missing ',' between Strings in String List");
153  break;
154  case MissingCommaInTestList:
155  err = i18n("Parse error: Missing ',' between Tests in Test List");
156  break;
157  case NonCommandInCommandList:
158  err = i18n("Parse error: Expected Command, got something else");
159  break;
160  case NonStringInStringList:
161  err = i18n("Parse error: Only Strings allowed in String Lists");
162  break;
163  case NonTestInTestList:
164  err = i18n("Parse error: Only Tests allowed in Test Lists");
165  break;
166 
167  // validity errors:
168  case RequireNotFirst:
169  err = i18n("\"require\" must be first command");
170  break;
171  case RequireMissingForCommand:
172  err = i18n("\"require\" missing for command \"%1\"", mStringOne);
173  break;
174  case RequireMissingForTest:
175  err = i18n("\"require\" missing for test \"%1\"", mStringOne);
176  break;
177  case RequireMissingForComparator:
178  err = i18n("\"require\" missing for comparator \"%1\"", mStringOne);
179  break;
180  case UnsupportedCommand:
181  err = i18n("Command \"%1\" not supported", mStringOne);
182  break;
183  case UnsupportedTest:
184  err = i18n("Test \"%1\" not supported", mStringOne);
185  break;
186  case UnsupportedComparator:
187  err = i18n("Comparator \"%1\" not supported", mStringOne);
188  break;
189  case TestNestingTooDeep:
190  err = i18n("Site Policy Limit Violation: Test nesting too deep (max. %1)", mStringOne.toUInt());
191  break;
192  case BlockNestingTooDeep:
193  err = i18n("Site Policy Limit Violation: Block nesting too deep (max. %1)", mStringOne.toUInt());
194  break;
195  case InvalidArgument:
196  err = i18n("Invalid Argument \"%1\" to \"%2\"", mStringOne, mStringTwo);
197  break;
198  case ConflictingArguments:
199  err = i18n("Conflicting Arguments: \"%1\" and \"%2\"", mStringOne, mStringTwo);
200  break;
201  case ArgumentsRepeated:
202  err = i18n("Argument \"%1\" Repeated", mStringOne);
203  break;
204  case CommandOrderingConstraintViolation:
205  err = i18n("Command \"%1\" violates command ordering constraints", mStringOne);
206  break;
207 
208  // runtime errors:
209  case IncompatibleActionsRequested:
210  err = i18n("Incompatible Actions \"%1\" and \"%2\" requested", mStringOne, mStringTwo);
211  break;
212  case MailLoopDetected:
213  err = i18n("Mail Loop detected");
214  break;
215  case TooManyActions:
216  err = i18n("Site Policy Limit Violation: Too many Actions requested (max. %1)", mStringOne.toUInt());
217  break;
218  default:
219  err = i18n("Unknown error");
220  break;
221  }
222 
223  return err;
224 }
225 } // namespace KSieve
Type type(const QSqlDatabase &db)
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:09:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.