1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 """
22 CLI error handling helper functions
23 """
24
25 import os.path
26 import signal
27 import sys
28
29 from ClusterShell.Engine.Engine import EngineNotSupportedError
30 from ClusterShell.CLI.Utils import GroupResolverConfigError
31 from ClusterShell.NodeUtils import GroupResolverIllegalCharError
32 from ClusterShell.NodeUtils import GroupResolverSourceError
33 from ClusterShell.NodeUtils import GroupSourceError
34 from ClusterShell.NodeUtils import GroupSourceNoUpcall
35 from ClusterShell.NodeSet import NodeSetExternalError, NodeSetParseError
36 from ClusterShell.NodeSet import RangeSetParseError
37 from ClusterShell.Topology import TopologyError
38 from ClusterShell.Worker.EngineClient import EngineClientError
39 from ClusterShell.Worker.Worker import WorkerError
40
41 GENERIC_ERRORS = (EngineNotSupportedError,
42 EngineClientError,
43 NodeSetExternalError,
44 NodeSetParseError,
45 RangeSetParseError,
46 GroupResolverIllegalCharError,
47 GroupResolverSourceError,
48 GroupSourceError,
49 GroupSourceNoUpcall,
50 TopologyError,
51 TypeError,
52 IOError,
53 KeyboardInterrupt,
54 WorkerError)
55
57 """handle error given `excobj' generic script exception"""
58 try:
59 raise excobj
60 except EngineNotSupportedError, exc:
61 msgfmt = "%s: I/O events engine '%s' not supported on this host"
62 print >> sys.stderr, msgfmt % (prog, exc.engineid)
63 except EngineClientError, exc:
64 print >> sys.stderr, "%s: EngineClientError: %s" % (prog, exc)
65 except NodeSetExternalError, exc:
66 print >> sys.stderr, "%s: External error:" % prog, exc
67 except (NodeSetParseError, RangeSetParseError), exc:
68 print >> sys.stderr, "%s: Parse error:" % prog, exc
69 except GroupResolverIllegalCharError, exc:
70 print >> sys.stderr, '%s: Illegal group character: "%s"' % (prog, exc)
71 except GroupResolverSourceError, exc:
72 print >> sys.stderr, '%s: Unknown group source: "%s"' % (prog, exc)
73 except GroupSourceNoUpcall, exc:
74 msgfmt = '%s: No %s upcall defined for group source "%s"'
75 print >> sys.stderr, msgfmt % (prog, exc, exc.group_source.name)
76 except GroupSourceError, exc:
77 print >> sys.stderr, "%s: Group error:" % prog, exc
78 except TopologyError, exc:
79 print >> sys.stderr, "%s: TREE MODE:" % prog, exc
80 except (TypeError, WorkerError), exc:
81 print >> sys.stderr, "%s: %s" % (prog, exc)
82 except IOError:
83
84 pass
85 except KeyboardInterrupt, exc:
86 return 128 + signal.SIGINT
87 except:
88 assert False, "wrong GENERIC_ERRORS"
89
90
91 return 1
92