blob: 32580577ef707a8dc40771a5e0a811133af6798c [file] [log] [blame]
Srikanth Vavilapalli1725e492014-12-01 17:50:52 -08001#
2# Copyright (c) 2013 Big Switch Networks, Inc.
3#
4# Licensed under the Eclipse Public License, Version 1.0 (the
5# "License"); you may not use this file except in compliance with the
6# License. You may obtain a copy of the License at
7#
8# http://www.eclipse.org/legal/epl-v10.html
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied. See the License for the specific language governing
14# permissions and limitations under the License.
15#
16
17class CommandError(Exception):
18 """
19 Base class for exceptions thrown by the CLI command module
20 """
21 def __init__(self, kind, message = None):
22 if kind:
23 message = kind + ': ' + message
24 super(CommandError, self).__init__(message)
25
26class ArgumentValidationError(CommandError):
27 def __init__(self, message=None, expected_tokens=None):
28 kind = "Invalid argument"
29 super(ArgumentValidationError, self).__init__(kind, message)
30 self.expected_tokens = expected_tokens
31
32
33class CommandSyntaxError(CommandError):
34 def __init__(self, message):
35 #kind = 'Error'
36 kind = None
37 super(CommandSyntaxError,self).__init__(kind, message)
38
39
40class RangeSyntaxError(CommandError):
41 def __init__(self, message):
42 kind = "Value outside length/range"
43 super(RangeSyntaxError,self).__init__(kind, message)
44
45
46class CommandDescriptionError(CommandError):
47 def __init__(self, message, command = None):
48 self.command = None
49 kind = "Bad command description"
50 if command:
51 self.command = command
52 message += ': ' + command['self']
53 super(CommandDescriptionError,self).__init__(kind, message)
54
55
56class CommandCompletionError(CommandError):
57 def __init__(self, message):
58 kind = "Command completion"
59 super(CommandCompletionError,self).__init__(kind, message)
60
61
62class CommandAmbiguousError(CommandError):
63 def __init__(self, message):
64 kind = "Ambiguous command"
65 super(CommandAmbiguousError,self).__init__(kind, message)
66
67
68class CommandMissingError(CommandError):
69 def __init__(self, message):
70 kind = "No such command"
71 super(CommandMissingError,self).__init__(kind, message)
72
73
74class CommandInvocationError(CommandError):
75 def __init__(self, message):
76 kind = "Invalid command invocation"
77 super(CommandInvocationError,self).__init__(kind, message)
78
79
80class CommandSemanticError(CommandError):
81 def __init__(self, message):
82 kind = "Invalid Use"
83 super(CommandSemanticError,self).__init__(kind, message)
84
85
86class CommandInternalError(CommandError):
87 def __init__(self, message):
88 kind = "Internal (bug)"
89 super(CommandInternalError,self).__init__(kind, message)
90
91
92class CommandRestError(CommandError):
93 def __init__(self, rest_info=None, message=None):
94 s = 'Error: REST API'
95 if rest_info:
96 error_type = rest_info.get('error_type')
97 if error_type:
98 s += '; type = ' + error_type
99 description = rest_info.get('description')
100 if description:
101 s += '; ' + description
102 if message:
103 s += ': ' + message
104 super(CommandRestError,self).__init__("REST", s)
105