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  Copyright (c) 2002-2003 Marc Mutz <[email protected]>
7 
8  KSieve is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License, version 2, as
10  published by the Free Software Foundation.
11 
12  KSieve is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include <ksieve/error.h>
34 
35 #include <KLocalizedString> // i18n
36 
37 #include <climits> // UINT_MAX
38 
39 namespace KSieve {
40 const char *Error::typeToString(Type t)
41 {
42  switch (t) {
43 #define CASE(x) case x: \
44  return #x
45  CASE(None);
46  CASE(Custom);
47 
48  CASE(CRWithoutLF);
49  CASE(SlashWithoutAsterisk);
50  CASE(IllegalCharacter);
51  CASE(UnexpectedCharacter);
52  CASE(NoLeadingDigits);
53  CASE(NonCWSAfterTextColon);
54 
55  CASE(NumberOutOfRange);
56  CASE(InvalidUTF8);
57 
58  CASE(UnfinishedBracketComment);
59  CASE(PrematureEndOfMultiLine);
60  CASE(PrematureEndOfQuotedString);
61  CASE(PrematureEndOfStringList);
62  CASE(PrematureEndOfTestList);
63  CASE(PrematureEndOfBlock);
64  CASE(MissingWhitespace);
65  CASE(MissingSemicolonOrBlock);
66 
67  CASE(ExpectedBlockOrSemicolon);
68  CASE(ExpectedCommand);
69  CASE(ConsecutiveCommasInStringList);
70  CASE(ConsecutiveCommasInTestList);
71  CASE(MissingCommaInTestList);
72  CASE(MissingCommaInStringList);
73  CASE(NonStringInStringList);
74  CASE(NonCommandInCommandList);
75  CASE(NonTestInTestList);
76 
77  CASE(RequireNotFirst);
78  CASE(RequireMissingForCommand);
79  CASE(RequireMissingForTest);
80  CASE(RequireMissingForComparator);
81  CASE(UnsupportedCommand);
82  CASE(UnsupportedTest);
83  CASE(UnsupportedComparator);
84  CASE(TestNestingTooDeep);
85  CASE(BlockNestingTooDeep);
86  CASE(InvalidArgument);
87  CASE(ConflictingArguments);
88  CASE(ArgumentsRepeated);
89  CASE(CommandOrderingConstraintViolation);
90 
91  CASE(IncompatibleActionsRequested);
92  CASE(MailLoopDetected);
93  CASE(TooManyActions);
94 #undef CASE
95  default:
96  return "<unknown>";
97  }
98 }
99 
100 QString Error::asString() const
101 {
102  QString err;
103  switch (type()) {
104  case None:
105  return QString();
106  case Custom:
107  return mStringOne;
108 
109  // Parse errors:
110  case CRWithoutLF:
111  err = i18n("Parse error: Carriage Return (CR) without Line Feed (LF)");
112  break;
113  case SlashWithoutAsterisk:
114  err = i18n("Parse error: Unquoted Slash ('/') without Asterisk ('*'). "
115  "Broken Comment?");
116  break;
117  case IllegalCharacter:
118  err = i18n("Parse error: Illegal Character");
119  break;
120  case UnexpectedCharacter:
121  err = i18n("Parse error: Unexpected Character, probably a missing space?");
122  break;
123  case NoLeadingDigits:
124  err = i18n("Parse error: Tag Name has leading Digits");
125  break;
126  case NonCWSAfterTextColon:
127  err = i18n("Parse error: Only whitespace and #comments may "
128  "follow \"text:\" on the same line");
129  break;
130  case NumberOutOfRange:
131  err = i18n("Parse error: Number out of Range (must be smaller than %1)", UINT_MAX);
132  break;
133  case InvalidUTF8:
134  err = i18n("Parse error: Invalid UTF-8 sequence");
135  break;
136  case PrematureEndOfMultiLine:
137  err = i18n("Parse error: Premature end of Multiline String (did you forget the '.'?)");
138  break;
139  case PrematureEndOfQuotedString:
140  err = i18n("Parse error: Premature end of Quoted String (missing closing '\"')");
141  break;
142  case PrematureEndOfStringList:
143  err = i18n("Parse error: Premature end of String List (missing closing ']')");
144  break;
145  case PrematureEndOfTestList:
146  err = i18n("Parse error: Premature end of Test List (missing closing ')')");
147  break;
148  case PrematureEndOfBlock:
149  err = i18n("Parse error: Premature end of Block (missing closing '}')");
150  break;
151  case MissingWhitespace:
152  err = i18n("Parse error: Missing Whitespace");
153  break;
154  case MissingSemicolonOrBlock:
155  err = i18n("Parse error: Missing ';' or Block");
156  break;
157  case ExpectedBlockOrSemicolon:
158  err = i18n("Parse error: Expected ';' or '{', got something else");
159  break;
160  case ExpectedCommand:
161  err = i18n("Parse error: Expected Command, got something else");
162  break;
163  case ConsecutiveCommasInStringList:
164  err = i18n("Parse error: Trailing, Leading or Duplicate Commas in String List");
165  break;
166  case ConsecutiveCommasInTestList:
167  err = i18n("Parse error: Trailing, Leading or Duplicate Commas in Test List");
168  break;
169  case MissingCommaInStringList:
170  err = i18n("Parse error: Missing ',' between Strings in String List");
171  break;
172  case MissingCommaInTestList:
173  err = i18n("Parse error: Missing ',' between Tests in Test List");
174  break;
175  case NonCommandInCommandList:
176  err = i18n("Parse error: Expected Command, got something else");
177  break;
178  case NonStringInStringList:
179  err = i18n("Parse error: Only Strings allowed in String Lists");
180  break;
181  case NonTestInTestList:
182  err = i18n("Parse error: Only Tests allowed in Test Lists");
183  break;
184 
185  // validity errors:
186  case RequireNotFirst:
187  err = i18n("\"require\" must be first command");
188  break;
189  case RequireMissingForCommand:
190  err = i18n("\"require\" missing for command \"%1\"", mStringOne);
191  break;
192  case RequireMissingForTest:
193  err = i18n("\"require\" missing for test \"%1\"", mStringOne);
194  break;
195  case RequireMissingForComparator:
196  err = i18n("\"require\" missing for comparator \"%1\"", mStringOne);
197  break;
198  case UnsupportedCommand:
199  err = i18n("Command \"%1\" not supported", mStringOne);
200  break;
201  case UnsupportedTest:
202  err = i18n("Test \"%1\" not supported", mStringOne);
203  break;
204  case UnsupportedComparator:
205  err = i18n("Comparator \"%1\" not supported", mStringOne);
206  break;
207  case TestNestingTooDeep:
208  err = i18n("Site Policy Limit Violation: Test nesting too deep (max. %1)", mStringOne.toUInt());
209  break;
210  case BlockNestingTooDeep:
211  err = i18n("Site Policy Limit Violation: Block nesting too deep (max. %1)", mStringOne.toUInt());
212  break;
213  case InvalidArgument:
214  err = i18n("Invalid Argument \"%1\" to \"%2\"", mStringOne, mStringTwo);
215  break;
216  case ConflictingArguments:
217  err = i18n("Conflicting Arguments: \"%1\" and \"%2\"", mStringOne, mStringTwo);
218  break;
219  case ArgumentsRepeated:
220  err = i18n("Argument \"%1\" Repeated", mStringOne);
221  break;
222  case CommandOrderingConstraintViolation:
223  err = i18n("Command \"%1\" violates command ordering constraints", mStringOne);
224  break;
225 
226  // runtime errors:
227  case IncompatibleActionsRequested:
228  err = i18n("Incompatible Actions \"%1\" and \"%2\" requested", mStringOne, mStringTwo);
229  break;
230  case MailLoopDetected:
231  err = i18n("Mail Loop detected");
232  break;
233  case TooManyActions:
234  err = i18n("Site Policy Limit Violation: Too many Actions requested (max. %1)", mStringOne.toUInt());
235  break;
236  default:
237  err = i18n("Unknown error");
238  break;
239  }
240 
241  return err;
242 }
243 } // 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-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:07:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.