forked from adrianaisemberg/CLAP
/
Exceptions.cs
285 lines (246 loc) · 10.9 KB
/
Exceptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
using System;
using System.Collections.Generic;
using System.Reflection;
namespace CLAP
{
[Serializable]
public abstract class CommandLineException : Exception
{
public CommandLineException() { }
public CommandLineException(string message) : base(message) { }
public CommandLineException(string message, Exception inner) : base(message, inner) { }
protected CommandLineException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public abstract class ParserException : Exception
{
public ParserException() { }
public ParserException(string message) : base(message) { }
public ParserException(string message, Exception inner) : base(message, inner) { }
protected ParserException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class MissingDefaultVerbException : CommandLineException
{
public MissingDefaultVerbException()
: this("No default verb was found")
{
}
public MissingDefaultVerbException(string message) : base(message) { }
public MissingDefaultVerbException(string message, Exception inner) : base(message, inner) { }
protected MissingDefaultVerbException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class MissingVerbException : CommandLineException
{
public string Verb { get; private set; }
public MissingVerbException(string verb)
: base("Verb '{0}' was not found".FormatWith(verb))
{
Verb = verb;
}
public MissingVerbException(string message, Exception inner) : base(message, inner) { }
protected MissingVerbException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class MissingRequiredArgumentException : CommandLineException
{
public string ParameterName { get; private set; }
public string Verb { get; private set; }
public MissingRequiredArgumentException(string verb, string parameter)
: base("Missing argument for required parameter '{0}'".FormatWith(parameter))
{
Verb = verb;
ParameterName = parameter;
}
public MissingRequiredArgumentException(string message, Exception inner) : base(message, inner) { }
protected MissingRequiredArgumentException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class MissingArgumentValueException : CommandLineException
{
public string ParameterName { get; private set; }
public MissingArgumentValueException(string parameter)
: base("Parameter {0} has no input and is not a switch".FormatWith(parameter))
{
ParameterName = parameter;
}
public MissingArgumentValueException(string message, Exception inner) : base(message, inner) { }
protected MissingArgumentValueException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class MissingArgumentPrefixException : CommandLineException
{
public string ParameterName { get; private set; }
public MissingArgumentPrefixException(string parameter, string prefixes)
: base("'{0}' should be prefixed with one of '{1}'".FormatWith(parameter, prefixes))
{
ParameterName = parameter;
}
public MissingArgumentPrefixException(string message, Exception inner) : base(message, inner) { }
protected MissingArgumentPrefixException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class ValidationException : CommandLineException
{
public ValidationException(string message) : base(message) { }
public ValidationException(string message, Exception inner) : base(message, inner) { }
protected ValidationException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class TypeConvertionException : CommandLineException
{
public string Value { get; private set; }
public Type Type { get; private set; }
public TypeConvertionException(string value, Type type, Exception inner)
: base("'{0}' cannot be converted to {1}".FormatWith(value, type), inner)
{
Value = value;
Type = type;
}
protected TypeConvertionException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class MoreThanOneEmptyHandlerException : CommandLineException
{
public MoreThanOneEmptyHandlerException()
: base("More than one empty handler was defined. Only a single method can be marked with [Empty] in a type and only a single action can be registered as an empty handler.")
{
}
protected MoreThanOneEmptyHandlerException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class MoreThanOneErrorHandlerException : CommandLineException
{
public MoreThanOneErrorHandlerException()
: base("More than one error handler was defined. Only a single method can be marked with [Error] in a type and only a single action can be registered as an error handler.")
{
}
protected MoreThanOneErrorHandlerException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class MoreThanOnePreVerbInterceptorException : CommandLineException
{
public MoreThanOnePreVerbInterceptorException()
: base("More than one pre-verb interceptor was defined. Only a single method can be marked with [PreVerbExecutionAttribute] in a type and only a single action can be registered as a pre-interceptor.")
{
}
protected MoreThanOnePreVerbInterceptorException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class MoreThanOnePostVerbInterceptorException : CommandLineException
{
public MoreThanOnePostVerbInterceptorException()
: base("More than one post-verb interceptor was defined. Only a single method can be marked with [PostVerbExecutionAttribute] in a type and only a single action can be registered as a post-interceptor.")
{
}
protected MoreThanOnePostVerbInterceptorException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class ArgumentMismatchException : CommandLineException
{
public ArgumentMismatchException() { }
public ArgumentMismatchException(string message) : base(message) { }
public ArgumentMismatchException(string message, Exception inner) : base(message, inner) { }
protected ArgumentMismatchException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class ParserExecutionTargetException : ParserException
{
public ParserExecutionTargetException() { }
public ParserExecutionTargetException(string message) : base(message) { }
public ParserExecutionTargetException(string message, Exception inner) : base(message, inner) { }
protected ParserExecutionTargetException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class UnhandledParametersException : CommandLineException
{
public Dictionary<string, string> UnhandledParameters { get; private set; }
public UnhandledParametersException(Dictionary<string, string> unhandledParameters)
: base("Unhandled parameters: '{0}'".FormatWith(unhandledParameters.Keys.StringJoin(", ")))
{
UnhandledParameters = unhandledParameters;
}
protected UnhandledParametersException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class MoreThanOneDefaultVerbException : CommandLineException
{
public IEnumerable<string> Verbs { get; private set; }
public MoreThanOneDefaultVerbException(IEnumerable<string> verbs)
: base("More than one default verb was defined: '{0}'".FormatWith(verbs.StringJoin(", ")))
{
Verbs = verbs;
}
protected MoreThanOneDefaultVerbException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
[Serializable]
public class InvalidHelpHandlerException : CommandLineException
{
public MethodInfo Method { get; private set; }
public InvalidHelpHandlerException(MethodInfo method)
: this(method, null)
{
}
public InvalidHelpHandlerException(MethodInfo method, Exception ex)
: base("Method '{0}' is marked as [Help] but it does not have a single string parameter".FormatWith(method.Name), ex)
{
Method = method;
}
protected InvalidHelpHandlerException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
}