File indexing completed on 2024-11-24 04:49:50

0001 /*  -*- c++ -*-
0002     ksieve/error.h
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 #pragma once
0012 
0013 #include "ksieve_export.h"
0014 
0015 #include <QString>
0016 
0017 #ifdef None // X headers
0018 #undef None
0019 #endif
0020 
0021 namespace KSieve
0022 {
0023 class KSIEVE_EXPORT Error
0024 {
0025 public:
0026     enum Type {
0027         None = 0,
0028         Custom,
0029         // parse (well-formedness in XML speak) errors:
0030         FirstParseError,
0031 
0032         CRWithoutLF = FirstParseError,
0033         SlashWithoutAsterisk,
0034         IllegalCharacter,
0035         UnexpectedCharacter,
0036         NoLeadingDigits,
0037         NonCWSAfterTextColon,
0038 
0039         NumberOutOfRange,
0040         InvalidUTF8,
0041 
0042         UnfinishedBracketComment,
0043         PrematureEndOfMultiLine,
0044         PrematureEndOfQuotedString,
0045         PrematureEndOfStringList,
0046         PrematureEndOfTestList,
0047         PrematureEndOfBlock,
0048         MissingWhitespace,
0049         MissingSemicolonOrBlock,
0050 
0051         ExpectedBlockOrSemicolon,
0052         ExpectedCommand,
0053         ConsecutiveCommasInStringList,
0054         ConsecutiveCommasInTestList,
0055         MissingCommaInTestList,
0056         MissingCommaInStringList,
0057         NonStringInStringList,
0058         NonCommandInCommandList,
0059         NonTestInTestList,
0060         LastParseError = NonTestInTestList,
0061         // validity errors:
0062         FirstValidityError,
0063         RequireNotFirst = FirstValidityError, // rfc3028, 3.2
0064         RequireMissingForCommand,
0065         RequireMissingForTest,
0066         RequireMissingForComparator,
0067         UnsupportedCommand,
0068         UnsupportedTest,
0069         UnsupportedComparator,
0070         TestNestingTooDeep, // site policy
0071         BlockNestingTooDeep, // site policy
0072         InvalidArgument,
0073         ConflictingArguments, // e.g. rfc3028, 2.7.{1,3}
0074         ArgumentsRepeated, // similar to ConflictingArguments, e.g. :is :is
0075         CommandOrderingConstraintViolation, // e.g. else w/o if, rfc3028, 3.1
0076         LastValidityError = CommandOrderingConstraintViolation,
0077         // runtime errors:
0078         FirstRuntimeError,
0079         IncompatibleActionsRequested = FirstRuntimeError,
0080         MailLoopDetected,
0081         TooManyActions,
0082         LastRuntimeError = TooManyActions
0083     };
0084 
0085     static const char *typeToString(Type type);
0086 
0087     Error(Type type = None, const QString &s1 = QString(), const QString &s2 = QString(), int line = -1, int col = -1)
0088         : mType(type)
0089         , mLine(line)
0090         , mCol(col)
0091         , mStringOne(s1)
0092         , mStringTwo(s2)
0093     {
0094     }
0095 
0096     Error(Type type, int line, int col)
0097         : mType(type)
0098         , mLine(line)
0099         , mCol(col)
0100     {
0101     }
0102 
0103     QString asString() const;
0104 
0105     /** So you can write <pre>if ( error() )</pre> with e.g. @ref Lexer */
0106     operator bool() const
0107     {
0108         return type() != None;
0109     }
0110 
0111     Type type() const
0112     {
0113         return mType;
0114     }
0115 
0116     int line() const
0117     {
0118         return mLine;
0119     }
0120 
0121     int column() const
0122     {
0123         return mCol;
0124     }
0125 
0126     QString firstString() const
0127     {
0128         return mStringOne;
0129     }
0130 
0131     QString secondString() const
0132     {
0133         return mStringTwo;
0134     }
0135 
0136 protected:
0137     Type mType;
0138     int mLine;
0139     int mCol;
0140     QString mStringOne, mStringTwo;
0141 };
0142 } // namespace KSieve