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 | package FCM::System::Exception; |
---|
23 | use base qw{FCM::Exception}; |
---|
24 | use Scalar::Util qw{blessed}; |
---|
25 | |
---|
26 | use constant { |
---|
27 | BUILD_SOURCE => 'BUILD_SOURCE', |
---|
28 | BUILD_SOURCE_SYN => 'BUILD_SOURCE_SYN', |
---|
29 | BUILD_TARGET => 'BUILD_TARGET', |
---|
30 | BUILD_TARGET_BAD => 'BUILD_TARGET_BAD', |
---|
31 | BUILD_TARGET_CYC => 'BUILD_TARGET_CYC', |
---|
32 | BUILD_TARGET_DEP => 'BUILD_TARGET_DEP', |
---|
33 | BUILD_TARGET_DUP => 'BUILD_TARGET_DUP', |
---|
34 | CACHE_LOAD => 'CACHE_LOAD', |
---|
35 | CACHE_TYPE => 'CACHE_TYPE', |
---|
36 | CM_ALREADY_EXIST => 'CM_ALREADY_EXIST', |
---|
37 | CM_ARG => 'CM_ARG', |
---|
38 | CM_BRANCH_NAME => 'CM_BRANCH_NAME', |
---|
39 | CM_BRANCH_SOURCE => 'CM_BRANCH_SOURCE', |
---|
40 | CM_CHECKOUT => 'CM_CHECKOUT', |
---|
41 | CM_LOG_EDIT_DELIMITER => 'CM_LOG_EDIT_DELIMITER', |
---|
42 | CM_LOG_EDIT_NULL => 'CM_LOG_EDIT_NULL', |
---|
43 | CM_OPT_ARG => 'CM_OPT_ARG', |
---|
44 | CM_PROJECT_NAME => 'CM_PROJECT_NAME', |
---|
45 | CM_REPOSITORY => 'CM_REPOSITORY', |
---|
46 | CONFIG_CONFLICT => 'CONFIG_CONFLICT', |
---|
47 | CONFIG_INHERIT => 'CONFIG_INHERIT', |
---|
48 | CONFIG_MODIFIER => 'CONFIG_MODIFIER', |
---|
49 | CONFIG_NS => 'CONFIG_NS', |
---|
50 | CONFIG_NS_VALUE => 'CONFIG_NS_VALUE', |
---|
51 | CONFIG_UNKNOWN => 'CONFIG_UNKNOWN', |
---|
52 | CONFIG_VALUE => 'CONFIG_VALUE', |
---|
53 | CONFIG_VERSION => 'CONFIG_VERSION', |
---|
54 | COPY => 'COPY', |
---|
55 | DEST_CLEAN => 'DEST_CLEAN', |
---|
56 | DEST_CREATE => 'DEST_CREATE', |
---|
57 | DEST_LOCKED => 'DEST_LOCKED', |
---|
58 | EXPORT_ITEMS_SRC => 'EXPORT_ITEMS_SRC', |
---|
59 | EXTRACT_LOC_BASE => 'EXTRACT_LOC_BASE', |
---|
60 | EXTRACT_MERGE => 'EXTRACT_MERGE', |
---|
61 | EXTRACT_NS => 'EXTRACT_NS', |
---|
62 | MIRROR => 'MIRROR', |
---|
63 | MIRROR_NULL => 'MIRROR_NULL', |
---|
64 | MIRROR_SOURCE => 'MIRROR_SOURCE', |
---|
65 | MIRROR_TARGET => 'MIRROR_TARGET', |
---|
66 | MAKE => 'MAKE', |
---|
67 | MAKE_ARG => 'MAKE_ARG', |
---|
68 | MAKE_CFG => 'MAKE_CFG', |
---|
69 | MAKE_CFG_FILE => 'MAKE_CFG_FILE', |
---|
70 | MAKE_PROP_NS => 'MAKE_PROP_NS', |
---|
71 | MAKE_PROP_VALUE => 'MAKE_PROP_VALUE', |
---|
72 | SHELL => 'SHELL', |
---|
73 | }; |
---|
74 | |
---|
75 | 1; |
---|
76 | __END__ |
---|
77 | |
---|
78 | =head1 NAME |
---|
79 | |
---|
80 | FCM::System::Exception |
---|
81 | |
---|
82 | =head1 SYNOPSIS |
---|
83 | |
---|
84 | eval { |
---|
85 | # ... |
---|
86 | FCM::System::Exception->throw($code, $ctx); |
---|
87 | # ... |
---|
88 | FCM::System::Exception->throw($code, $ctx, {exception => $e}); |
---|
89 | # ... |
---|
90 | }; |
---|
91 | if (my $e = $@) { |
---|
92 | if (FCM::System::Exception->caught($e)) { |
---|
93 | # do something ... |
---|
94 | } |
---|
95 | else { |
---|
96 | # do something else ... |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | =head1 DESCRIPTION |
---|
101 | |
---|
102 | This exception represents an error condition in an FCM sub-system. It is a |
---|
103 | sub-class of L<FCM::Exception|FCM::Exception>. |
---|
104 | |
---|
105 | =head1 CONSTANTS |
---|
106 | |
---|
107 | The following are known error code: |
---|
108 | |
---|
109 | =over 4 |
---|
110 | |
---|
111 | =item FCM::System::Exception->BUILD_SOURCE |
---|
112 | |
---|
113 | The build sub-system fails because a specified source does not exist. Expects |
---|
114 | $e->get_ctx() to return the source path. |
---|
115 | |
---|
116 | =item FCM::System::Exception->BUILD_SOURCE_SYN |
---|
117 | |
---|
118 | The build sub-system fails because a specified source has a syntax error. |
---|
119 | Expects $e->get_ctx() to return an ARRAY reference containing the source path |
---|
120 | and the line number where the error occurs. |
---|
121 | |
---|
122 | =item FCM::System::Exception->BUILD_TARGET |
---|
123 | |
---|
124 | The build sub-system fails because a target does not exist when it is supposed |
---|
125 | to be updated. Expects $e->get_ctx() to return an instance of |
---|
126 | L<FCM::Context::Make::Build::Target|FCM::Context::Make::Build/FCM::Context::Make::Build::Target>. |
---|
127 | |
---|
128 | =item FCM::System::Exception->BUILD_TARGET_BAD |
---|
129 | |
---|
130 | The build sub-system fails because the user has specified invalid targets. |
---|
131 | Expects $e->get_ctx() to return an ARRAY reference of the bad target keys. |
---|
132 | |
---|
133 | =item FCM::System::Exception->BUILD_TARGET_CYC |
---|
134 | |
---|
135 | The build sub-system fails due to cyclic dependency in a target. Expects |
---|
136 | $e->get_ctx() to return a HASH {$key => {'keys' => \@stack}, ...}, where each |
---|
137 | $key is the ID of a problematic target and the @stack is an ARRAY reference of a |
---|
138 | stack of target keys where the problem is detected. |
---|
139 | |
---|
140 | =item FCM::System::Exception->BUILD_TARGET_DEP |
---|
141 | |
---|
142 | The build sub-system fails because some targets have missing dependencies. |
---|
143 | Expects $e->get_ctx() to return a HASH |
---|
144 | {$key => {'keys' => \@stack, 'values' => [$dep_key, $dep_type]}, ...}, where each |
---|
145 | $key is the ID of a problematic target, the @stack is an ARRAY reference of a |
---|
146 | stack of target keys where the problem is detected, and the |
---|
147 | [$dep_key, $dep_type] ARRAY contains the key and type of the dependency. |
---|
148 | |
---|
149 | =item FCM::System::Exception->BUILD_TARGET_DUP |
---|
150 | |
---|
151 | The build sub-system fails because there are multiple versions of a build |
---|
152 | target. Expects $e->get_ctx() to return a HASH |
---|
153 | {$key => {'keys' => \@stack, 'values' => \@ns}, ...} where each $key is the ID of a |
---|
154 | problematic target, the @stack is an ARRAY |
---|
155 | reference of a stack of target keys where the problem is detected, |
---|
156 | and @ns contains the name-spaces of the sources that give the same target key. |
---|
157 | |
---|
158 | =item FCM::System::Exception->CACHE_LOAD |
---|
159 | |
---|
160 | The system is unable to load a cache from a make destination. Expects |
---|
161 | $e->get_ctx() to return the path it fails to load; and the $e->get_exception() |
---|
162 | to return the original exception that triggers this failure. |
---|
163 | |
---|
164 | =item FCM::System::Exception->CACHE_TYPE |
---|
165 | |
---|
166 | The system loaded a cache into a data structure, but the data structure is not |
---|
167 | the expected object type. Expects $e->get_ctx() to return the path to the cache. |
---|
168 | |
---|
169 | =item FCM::System::Exception->CM_ALREADY_EXIST |
---|
170 | |
---|
171 | Attempt to create a target that already exists. Expects $e->get_ctx() to return the |
---|
172 | target URL. |
---|
173 | |
---|
174 | =item FCM::System::Exception->CM_ARG |
---|
175 | |
---|
176 | Attempt to supply a bad argument. Expects $e->get_ctx() to return the bad value. |
---|
177 | |
---|
178 | =item FCM::System::Exception->CM_BRANCH_NAME |
---|
179 | |
---|
180 | Attempt to create a branch with a bad name. Expects $e->get_ctx() to return the |
---|
181 | bad name. |
---|
182 | |
---|
183 | =item FCM::System::Exception->CM_BRANCH_SOURCE |
---|
184 | |
---|
185 | Attempt to create a branch with an invalid source. Expects $e->get_ctx() to |
---|
186 | return the source. |
---|
187 | |
---|
188 | =item FCM::System::Exception->CM_CHECKOUT |
---|
189 | |
---|
190 | Attempt to checkout to an existing working copy. Expects $e->get_ctx() to return |
---|
191 | an ARRAY containing the target path and the URL it is pointing to. |
---|
192 | |
---|
193 | =item FCM::System::Exception->CM_LOG_EDIT_DELIMITER |
---|
194 | |
---|
195 | The commit message delimiter is modified after an edit. |
---|
196 | |
---|
197 | =item FCM::System::Exception->CM_LOG_EDIT_NULL |
---|
198 | |
---|
199 | The commit message is empty after an edit. |
---|
200 | |
---|
201 | =item FCM::System::Exception->CM_OPT_ARG |
---|
202 | |
---|
203 | Attempt to supply a bad argument to a valid option. Expects $e->get_ctx() to |
---|
204 | return the option key and the bad value. |
---|
205 | |
---|
206 | =item FCM::System::Exception->CM_PROJECT_NAME |
---|
207 | |
---|
208 | Attempt to create a project with a bad name. Expects $e->get_ctx() to return the |
---|
209 | bad name. |
---|
210 | |
---|
211 | =item FCM::System::Exception->CM_REPOSITORY |
---|
212 | |
---|
213 | Attempt to access an invalid repository. Expects $e->get_ctx() to return the |
---|
214 | bad repository. |
---|
215 | |
---|
216 | =item FCM::System::Exception->CONFIG_CONFLICT |
---|
217 | |
---|
218 | In a make configuration file, a declaration attempts to modify a value that is |
---|
219 | inherited from a previous make, and considered read-only. Expects $e->get_ctx() |
---|
220 | to return a L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object. |
---|
221 | |
---|
222 | =item FCM::System::Exception->CONFIG_INHERIT |
---|
223 | |
---|
224 | In a make configuration file, a declaration attempts to inherit from a make that |
---|
225 | is either incomplete or failed. Expects $e->get_ctx() to return a |
---|
226 | L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object. |
---|
227 | |
---|
228 | =item FCM::System::Exception->CONFIG_MODIFIER |
---|
229 | |
---|
230 | In a make configuration file, a modifier of in a declaration is incorrect. |
---|
231 | Expects $e->get_ctx() to return a |
---|
232 | L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object and |
---|
233 | $e->get_exception() to return (if any) the original exception that triggers this |
---|
234 | failure. |
---|
235 | |
---|
236 | =item FCM::System::Exception->CONFIG_NS |
---|
237 | |
---|
238 | In a make configuration file, a declaration is missing a required name-space, or |
---|
239 | the name-space declaration is incorrect. Expects $e->get_ctx() to return a |
---|
240 | L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object and |
---|
241 | $e->get_exception() to return (if any) the original exception that triggers this |
---|
242 | failure. |
---|
243 | |
---|
244 | =item FCM::System::Exception->CONFIG_NS_VALUE |
---|
245 | |
---|
246 | In a make configuration file, the name-space of a declaration is incompatible |
---|
247 | with the value. (E.g. the number of name-space elements does not match with the |
---|
248 | number of words in a value.) Expects $e->get_ctx() to return a |
---|
249 | L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object and |
---|
250 | $e->get_exception() to return (if any) the original exception that triggers this |
---|
251 | failure. |
---|
252 | |
---|
253 | =item FCM::System::Exception->CONFIG_UNKNOWN |
---|
254 | |
---|
255 | In a make configuration file, the label of a declaration is unrecognised by the |
---|
256 | system. Expects $e->get_ctx() to return a reference to an ARRAY containing |
---|
257 | L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> objects. |
---|
258 | |
---|
259 | =item FCM::System::Exception->CONFIG_VALUE |
---|
260 | |
---|
261 | In a make configuration file, the value of a declaration is incorrect. Expects |
---|
262 | $e->get_ctx() to return a L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> |
---|
263 | object and $e->get_exception() to return (if any) the original exception that |
---|
264 | triggers this failure. |
---|
265 | |
---|
266 | =item FCM::System::Exception->CONFIG_VERSION |
---|
267 | |
---|
268 | A make configuration file requires certain version of FCM. Expects |
---|
269 | $e->get_ctx() to return a L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> |
---|
270 | object, and the current FCM version. |
---|
271 | |
---|
272 | =item FCM::System::Exception->COPY |
---|
273 | |
---|
274 | The system fails to perform a file copy. Expects $e->get_ctx() to return a |
---|
275 | 2-element ARRAY reference to represent the source and the target, and the |
---|
276 | $e->get_exception() to return the original exception that triggers this failure. |
---|
277 | |
---|
278 | =item FCM::System::Exception->DEST_CLEAN |
---|
279 | |
---|
280 | A destination path cannot be removed. Expects $e->get_ctx() to return the path |
---|
281 | that the system fails to remove, and $e->get_exception() to return the original |
---|
282 | exception that triggers this failure. |
---|
283 | |
---|
284 | =item FCM::System::Exception->DEST_CREATE |
---|
285 | |
---|
286 | The system is unable to create a path at a make destination. Expects |
---|
287 | $e->get_ctx() to return the path it fails to create; and the $e->get_exception() |
---|
288 | to return the original exception that triggers this failure. |
---|
289 | |
---|
290 | =item FCM::System::Exception->DEST_LOCKED |
---|
291 | |
---|
292 | A lock file exists at the destination. Expects $e->get_ctx() to return the |
---|
293 | path to the lock file. |
---|
294 | |
---|
295 | =item FCM::System::Exception->EXPORT_ITEMS_SRC |
---|
296 | |
---|
297 | The system fails because the source location is not specified. |
---|
298 | |
---|
299 | =item FCM::System::Exception->EXTRACT_LOC_BASE |
---|
300 | |
---|
301 | The system fails to determine the location of a base tree of a project. Expects |
---|
302 | $e->get_ctx() to return the name-space of the project. |
---|
303 | |
---|
304 | =item FCM::System::Exception->EXTRACT_MERGE |
---|
305 | |
---|
306 | The system fails to merge the sources of an extract target. Expects |
---|
307 | $e->get_ctx() to return a HASH reference with the following keys: |
---|
308 | |
---|
309 | =over 4 |
---|
310 | |
---|
311 | =item target |
---|
312 | |
---|
313 | The FCM::Context::Make::Extract::Target object associated with this failure. |
---|
314 | |
---|
315 | =item output |
---|
316 | |
---|
317 | The path to a file containing the failed merge output. |
---|
318 | |
---|
319 | =item keys_done |
---|
320 | |
---|
321 | The keys of the source trees providing the source files for this target that |
---|
322 | have already been merged. |
---|
323 | |
---|
324 | =item key |
---|
325 | |
---|
326 | The key of the source tree providing the source file for this target that causes |
---|
327 | the merge conflict. |
---|
328 | |
---|
329 | =item keys_left |
---|
330 | |
---|
331 | The keys of the source trees providing the source files for this target that are |
---|
332 | yet to be merged. |
---|
333 | |
---|
334 | =back |
---|
335 | |
---|
336 | =item FCM::System::Exception->EXTRACT_NS |
---|
337 | |
---|
338 | The system fails because there are some extract declarations for the name-spaces |
---|
339 | but the settings are not used. Expects $e->get_ctx() to return an ARRAY of bad |
---|
340 | name-spaces. |
---|
341 | |
---|
342 | =item FCM::System::Exception->MIRROR |
---|
343 | |
---|
344 | The mirror operation failed. Expects $e->get_ctx() to return a reference of a |
---|
345 | 2-element ARRAY containing the source and the target of the mirror, and |
---|
346 | $e->get_exception() to return the original exception that triggers this failure. |
---|
347 | |
---|
348 | =item FCM::System::Exception->MIRROR_NULL |
---|
349 | |
---|
350 | The mirror step failed because a target is not specified. The $e->get_ctx() is |
---|
351 | undefined. |
---|
352 | |
---|
353 | =item FCM::System::Exception->MIRROR_SOURCE |
---|
354 | |
---|
355 | The mirror step failed because the destination of a completed step in the make |
---|
356 | is not suitable for mirroring. Expects $e->get_ctx() to return an ARRAY |
---|
357 | reference containing the names of the unsuitable steps. |
---|
358 | |
---|
359 | =item FCM::System::Exception->MIRROR_TARGET |
---|
360 | |
---|
361 | The mirror step failed to create the target. Expects $e->get_ctx() to |
---|
362 | return the target of the mirror, and $e->get_exception() to return the original |
---|
363 | exception that triggers this failure. |
---|
364 | |
---|
365 | =item FCM::System::Exception->MAKE |
---|
366 | |
---|
367 | A named step in a make is not implemented. Expects $e->get_ctx() to return the |
---|
368 | name of the step. |
---|
369 | |
---|
370 | =item FCM::System::Exception->MAKE_ARG |
---|
371 | |
---|
372 | A make sub-system fails because of bad command line arguments. Expects |
---|
373 | $e->get_ctx() to return an ARRAY reference of something like this: |
---|
374 | |
---|
375 | my @list = @{$e->get_ctx()}; |
---|
376 | for (@list) { |
---|
377 | my ($arg_index, $arg) = @{$_}; |
---|
378 | warn("Argument $arg_index ($arg) is invalid\n"); |
---|
379 | } |
---|
380 | |
---|
381 | =item FCM::System::Exception->MAKE_CFG |
---|
382 | |
---|
383 | A make sub-system fails because it can find no configuration. |
---|
384 | |
---|
385 | =item FCM::System::Exception->MAKE_CFG_FILE |
---|
386 | |
---|
387 | A make sub-system fails because it cannot file a named configuration file. |
---|
388 | Expects $e->get_ctx() to return the configuration file name. |
---|
389 | |
---|
390 | =item FCM::System::Exception->MAKE_PROP_NS |
---|
391 | |
---|
392 | A make sub-system fails because a property is specified with an invalid |
---|
393 | name-space. Expects $e->get_ctx() to return an ARRAY reference of something like |
---|
394 | this: |
---|
395 | |
---|
396 | my @list = @{$e->get_ctx()}; |
---|
397 | for (@list) { |
---|
398 | my ($step_name, $prop_name, $ns, $value) = @{$_}; |
---|
399 | warn("{$prop_name}[$ns]: prop ns is invalid\n"); |
---|
400 | } |
---|
401 | |
---|
402 | =item FCM::System::Exception->MAKE_PROP_VALUE |
---|
403 | |
---|
404 | A make sub-system fails because a property is specified with an invalid |
---|
405 | value. Expects $e->get_ctx() to return an ARRAY reference of something like |
---|
406 | this: |
---|
407 | |
---|
408 | my @list = @{$e->get_ctx()}; |
---|
409 | for (@list) { |
---|
410 | my ($step_name, $prop_name, $ns, $value) = @{$_}; |
---|
411 | warn("{$prop_name}[$ns] = $value: prop value is bad\n"); |
---|
412 | } |
---|
413 | |
---|
414 | =item FCM::System::Exception->SHELL |
---|
415 | |
---|
416 | A shell command returns an error. Expects $e->get_ctx() to return a HASH |
---|
417 | reference containing {command_list}, an ARRAY reference representing the |
---|
418 | command; {rc}, the return code; {out}, the standard output of the command and |
---|
419 | {err}, the standard error of the command. Expects $e->get_exception() to return |
---|
420 | the standard error of the command. |
---|
421 | |
---|
422 | =back |
---|
423 | |
---|
424 | =head1 COPYRIGHT |
---|
425 | |
---|
426 | Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. |
---|
427 | |
---|
428 | =cut |
---|