1 | # ------------------------------------------------------------------------------ |
---|
2 | # Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
3 | # |
---|
4 | # This file is part of FCM, tools for managing and building source code. |
---|
5 | # |
---|
6 | # FCM is free software: you can redistribute it and/or modify |
---|
7 | # it under the terms of the GNU General Public License as published by |
---|
8 | # the Free Software Foundation, either version 3 of the License, or |
---|
9 | # (at your option) any later version. |
---|
10 | # |
---|
11 | # FCM is distributed in the hope that it will be useful, |
---|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | # GNU General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | # ------------------------------------------------------------------------------ |
---|
19 | use strict; |
---|
20 | use warnings; |
---|
21 | # ------------------------------------------------------------------------------ |
---|
22 | |
---|
23 | package FCM::Util::Exception; |
---|
24 | use base qw{FCM::Exception}; |
---|
25 | |
---|
26 | use constant { |
---|
27 | CLASS_LOADER => 'CLASS_LOADER', |
---|
28 | CONFIG_CONT_EOF => 'CONFIG_CONT_EOF', |
---|
29 | CONFIG_CYCLIC => 'CONFIG_CYCLIC', |
---|
30 | CONFIG_LOAD => 'CONFIG_LOAD', |
---|
31 | CONFIG_SYNTAX => 'CONFIG_SYNTAX', |
---|
32 | CONFIG_USAGE => 'CONFIG_USAGE', |
---|
33 | CONFIG_VAR_UNDEF => 'CONFIG_VAR_UNDEF', |
---|
34 | IO => 'IO', |
---|
35 | LOCATOR_AS_INVARIANT => 'LOCATOR_AS_INVARIANT', |
---|
36 | LOCATOR_BROWSER_URL => 'LOCATOR_BROWSER_URL', |
---|
37 | LOCATOR_FIND => 'LOCATOR_FIND', |
---|
38 | LOCATOR_KEYWORD_LOC => 'LOCATOR_KEYWORD_LOC', |
---|
39 | LOCATOR_KEYWORD_REV => 'LOCATOR_KEYWORD_REV', |
---|
40 | LOCATOR_READER => 'LOCATOR_READER', |
---|
41 | LOCATOR_TYPE => 'LOCATOR_TYPE', |
---|
42 | SHELL_OPEN3 => 'SHELL_OPEN3', |
---|
43 | SHELL_OS => 'SHELL_OS', |
---|
44 | SHELL_SIGNAL => 'SHELL_SIGNAL', |
---|
45 | SHELL_WHICH => 'SHELL_WHICH', |
---|
46 | }; |
---|
47 | |
---|
48 | # ------------------------------------------------------------------------------ |
---|
49 | 1; |
---|
50 | __END__ |
---|
51 | |
---|
52 | =head1 NAME |
---|
53 | |
---|
54 | FCM::Util::Exception |
---|
55 | |
---|
56 | =head1 SYNOPSIS |
---|
57 | |
---|
58 | use FCM::Util::Exception; |
---|
59 | eval { |
---|
60 | # something does not work ... |
---|
61 | FCM::Util::Exception->throw($code, $ctx, $exception); |
---|
62 | }; |
---|
63 | if (my $e = $@) { |
---|
64 | if (FCM::Util::Exception->caught($e)) { |
---|
65 | # do something ... |
---|
66 | } |
---|
67 | else { |
---|
68 | # do something else ... |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | =head1 DESCRIPTION |
---|
73 | |
---|
74 | This exception represents an error condition in an FCM utility. It is a |
---|
75 | sub-class of L<FCM::Exception|FCM::Exception>. |
---|
76 | |
---|
77 | =head1 CONSTANTS |
---|
78 | |
---|
79 | The following are known error code: |
---|
80 | |
---|
81 | =over 4 |
---|
82 | |
---|
83 | =item CLASS_LOADER |
---|
84 | |
---|
85 | L<FCM::Util::ClassLoader|FCM::Util::ClassLoader>: The utility fails to load the |
---|
86 | specified class. The $e->get_ctx() method returns the name of the class it fails |
---|
87 | to load. |
---|
88 | |
---|
89 | =item CONFIG_CONT_EOF |
---|
90 | |
---|
91 | L<FCM::Util::ConfigReader|FCM::Util::ConfigReader>: The last line of the |
---|
92 | configuration file has a continuation marker. Expects the $e->get_ctx() method |
---|
93 | to return the L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object that |
---|
94 | represents the problem entry. |
---|
95 | |
---|
96 | =item CONFIG_CYCLIC |
---|
97 | |
---|
98 | L<FCM::Util::ConfigReader|FCM::Util::ConfigReader>: There is a cyclic dependency |
---|
99 | in the include hierarchy. Expects the $e->get_ctx() method to return an ARRAY |
---|
100 | reference of the locator stack. (The last element of the ARRAY is the top of the |
---|
101 | stack, and each element is a 2-element ARRAY reference, where the first element |
---|
102 | is a L<FCM::Context::Locator|FCM::Context::Locator> object and the second |
---|
103 | element is the line number.) |
---|
104 | |
---|
105 | =item CONFIG_LOAD |
---|
106 | |
---|
107 | L<FCM::Util::ConfigReader|FCM::Util::ConfigReader>: An error occurs when loading |
---|
108 | a configuration file. Expects the $e->get_ctx() method to return an ARRAY |
---|
109 | reference of the locator stack. (The last element of the ARRAY is the top of the |
---|
110 | stack, and each element is a 2-element ARRAY reference, where the first element |
---|
111 | is a L<FCM::Context::Locator|FCM::Context::Locator> object and the second |
---|
112 | element is the line number.) |
---|
113 | |
---|
114 | =item CONFIG_SYNTAX |
---|
115 | |
---|
116 | L<FCM::Util::ConfigReader|FCM::Util::ConfigReader>: A syntax error in the |
---|
117 | declaration. Expects the $e->get_ctx() method to return the |
---|
118 | L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object that represents |
---|
119 | the problem entry. |
---|
120 | |
---|
121 | =item CONFIG_USAGE |
---|
122 | |
---|
123 | L<FCM::Util::ConfigReader|FCM::Util::ConfigReader>: An attempt to assign a value |
---|
124 | to a reserved variable. Expects the $e->get_ctx() method to return the |
---|
125 | L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object that represents |
---|
126 | the problem entry. |
---|
127 | |
---|
128 | =item CONFIG_VAR_UNDEF |
---|
129 | |
---|
130 | L<FCM::Util::ConfigReader|FCM::Util::ConfigReader>: References to an undefined |
---|
131 | variable. Expects the $e->get_ctx() method to return the |
---|
132 | L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object that represents |
---|
133 | the problem entry, and $e->get_exception() to return a string that looks like |
---|
134 | "undef($symbol)" where $symbol is the symbol that references the variable. |
---|
135 | |
---|
136 | =item IO |
---|
137 | |
---|
138 | L<FCM::Util::IO|FCM::Util::IO>: I/O exception. Expects $e->get_ctx() to return |
---|
139 | the path that triggers the exception, and the $e->get_exception() to return the |
---|
140 | $! string. |
---|
141 | |
---|
142 | =item LOCATOR_AS_INVARIANT |
---|
143 | |
---|
144 | L<FCM::Util::Locator|FCM::Util::Locator>: The invariant value of the locator |
---|
145 | cannot be determined. Expects $e->get_ctx() method to return the associated |
---|
146 | L<FCM::Context::Locator|FCM::Context::Locator> object. |
---|
147 | |
---|
148 | =item LOCATOR_BROWSER_URL |
---|
149 | |
---|
150 | L<FCM::Util::Locator|FCM::Util::Locator>: The locator cannot be mapped to a |
---|
151 | browser URL. Expects $e->get_ctx() method to return the associated |
---|
152 | L<FCM::Context::Locator|FCM::Context::Locator> object. |
---|
153 | |
---|
154 | =item LOCATOR_FIND |
---|
155 | |
---|
156 | L<FCM::Util::Locator|FCM::Util::Locator>: The locator does not exist. Expects |
---|
157 | $e->get_ctx() method to return the associated |
---|
158 | L<FCM::Context::Locator|FCM::Context::Locator> object. |
---|
159 | |
---|
160 | =item LOCATOR_KEYWORD_LOC |
---|
161 | |
---|
162 | L<FCM::Util::Locator|FCM::Util::Locator>: The location keyword as specified in |
---|
163 | the locator is not defined. Expects $e->get_ctx() method to return the |
---|
164 | associated L<FCM::Context::Locator|FCM::Context::Locator> object. |
---|
165 | |
---|
166 | =item LOCATOR_KEYWORD_REV |
---|
167 | |
---|
168 | L<FCM::Util::Locator|FCM::Util::Locator>: The revision keyword as specified in |
---|
169 | the locator is not defined. Expects $e->get_ctx() method to return the |
---|
170 | associated L<FCM::Context::Locator|FCM::Context::Locator> object. |
---|
171 | |
---|
172 | =item LOCATOR_READER |
---|
173 | |
---|
174 | L<FCM::Util::Locator|FCM::Util::Locator>: The locator cannot be read. Expects |
---|
175 | $e->get_ctx() method to return the associated |
---|
176 | L<FCM::Context::Locator|FCM::Context::Locator> object. |
---|
177 | |
---|
178 | =item LOCATOR_TYPE |
---|
179 | |
---|
180 | L<FCM::Util::Locator|FCM::Util::Locator>: The locator type cannot be determined |
---|
181 | or cannot be supported. Expects $e->get_ctx() method to return the associated |
---|
182 | L<FCM::Context::Locator|FCM::Context::Locator> object. |
---|
183 | |
---|
184 | =item LOCATOR_WHEN |
---|
185 | |
---|
186 | L<FCM::Util::Locator|FCM::Util::Locator>: The last modified date and revision of |
---|
187 | the locator cannot be determined. Expects $e->get_ctx() method to return the |
---|
188 | associated L<FCM::Context::Locator|FCM::Context::Locator> object. |
---|
189 | |
---|
190 | =item SHELL_OPEN3 |
---|
191 | |
---|
192 | L<FCM::Util::Shell|FCM::Util::Shell>: The utility fails to invoke |
---|
193 | IPC::Open3::open3(). Expects $e->get_ctx() to return an ARRAY reference of the |
---|
194 | command line, and $e->get_exception() to return the error from open3(). |
---|
195 | |
---|
196 | =item SHELL_OS |
---|
197 | |
---|
198 | L<FCM::Util::Shell|FCM::Util::Shell>: An OS error occurs when invoking a shell |
---|
199 | command. Expects $e->get_ctx() to return an ARRAY reference of the |
---|
200 | command line, and $e->get_exception() to return $!. |
---|
201 | |
---|
202 | =item SHELL_SIGNAL |
---|
203 | |
---|
204 | L<FCM::Util::Shell|FCM::Util::Shell>: The system receives a signal when invoking |
---|
205 | a shell command. Expects $e->get_ctx() to return an ARRAY reference of the |
---|
206 | command line, and $e->get_exception() to return the signal number. |
---|
207 | |
---|
208 | =item SHELL_WHICH |
---|
209 | |
---|
210 | L<FCM::Util::Shell|FCM::Util::Shell>: The shell command does not exist in the |
---|
211 | PATH. Expects $e->get_ctx() to return an ARRAY reference of the command line. |
---|
212 | |
---|
213 | =back |
---|
214 | |
---|
215 | =head1 COPYRIGHT |
---|
216 | |
---|
217 | Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
218 | |
---|
219 | =cut |
---|