New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Exception.pm in vendors/lib/FCM/System – NEMO

source: vendors/lib/FCM/System/Exception.pm @ 10669

Last change on this file since 10669 was 10669, checked in by nicolasmartin, 5 years ago

Import latest FCM release from Github into the repository for testing

File size: 14.6 KB
Line 
1# ------------------------------------------------------------------------------
2# (C) British Crown Copyright 2006-17 Met Office.
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# ------------------------------------------------------------------------------
19use strict;
20use warnings;
21
22package FCM::System::Exception;
23use base qw{FCM::Exception};
24use Scalar::Util qw{blessed};
25
26use 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
751;
76__END__
77
78=head1 NAME
79
80FCM::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
102This exception represents an error condition in an FCM sub-system. It is a
103sub-class of L<FCM::Exception|FCM::Exception>.
104
105=head1 CONSTANTS
106
107The following are known error code:
108
109=over 4
110
111=item FCM::System::Exception->BUILD_SOURCE
112
113The 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
118The build sub-system fails because a specified source has a syntax error.
119Expects $e->get_ctx() to return an ARRAY reference containing the source path
120and the line number where the error occurs.
121
122=item FCM::System::Exception->BUILD_TARGET
123
124The build sub-system fails because a target does not exist when it is supposed
125to be updated. Expects $e->get_ctx() to return an instance of
126L<FCM::Context::Make::Build::Target|FCM::Context::Make::Build/FCM::Context::Make::Build::Target>.
127
128=item FCM::System::Exception->BUILD_TARGET_BAD
129
130The build sub-system fails because the user has specified invalid targets.
131Expects $e->get_ctx() to return an ARRAY reference of the bad target keys.
132
133=item FCM::System::Exception->BUILD_TARGET_CYC
134
135The 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
138stack of target keys where the problem is detected.
139
140=item FCM::System::Exception->BUILD_TARGET_DEP
141
142The build sub-system fails because some targets have missing dependencies.
143Expects $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
146stack 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
151The build sub-system fails because there are multiple versions of a build
152target. Expects $e->get_ctx() to return a HASH
153{$key => {'keys' => \@stack, 'values' => \@ns}, ...} where each $key is the ID of a
154problematic target, the @stack is an ARRAY
155reference of a stack of target keys where the problem is detected,
156and @ns contains the name-spaces of the sources that give the same target key.
157
158=item FCM::System::Exception->CACHE_LOAD
159
160The 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()
162to return the original exception that triggers this failure.
163
164=item FCM::System::Exception->CACHE_TYPE
165
166The system loaded a cache into a data structure, but the data structure is not
167the expected object type. Expects $e->get_ctx() to return the path to the cache.
168
169=item FCM::System::Exception->CM_ALREADY_EXIST
170
171Attempt to create a target that already exists. Expects $e->get_ctx() to return the
172target URL.
173
174=item FCM::System::Exception->CM_ARG
175
176Attempt to supply a bad argument. Expects $e->get_ctx() to return the bad value.
177
178=item FCM::System::Exception->CM_BRANCH_NAME
179
180Attempt to create a branch with a bad name. Expects $e->get_ctx() to return the
181bad name.
182
183=item FCM::System::Exception->CM_BRANCH_SOURCE
184
185Attempt to create a branch with an invalid source. Expects $e->get_ctx() to
186return the source.
187
188=item FCM::System::Exception->CM_CHECKOUT
189
190Attempt to checkout to an existing working copy. Expects $e->get_ctx() to return
191an ARRAY containing the target path and the URL it is pointing to.
192
193=item FCM::System::Exception->CM_LOG_EDIT_DELIMITER
194
195The commit message delimiter is modified after an edit.
196
197=item FCM::System::Exception->CM_LOG_EDIT_NULL
198
199The commit message is empty after an edit.
200
201=item FCM::System::Exception->CM_OPT_ARG
202
203Attempt to supply a bad argument to a valid option. Expects $e->get_ctx() to
204return the option key and the bad value.
205
206=item FCM::System::Exception->CM_PROJECT_NAME
207
208Attempt to create a project with a bad name. Expects $e->get_ctx() to return the
209bad name.
210
211=item FCM::System::Exception->CM_REPOSITORY
212
213Attempt to access an invalid repository. Expects $e->get_ctx() to return the
214bad repository.
215
216=item FCM::System::Exception->CONFIG_CONFLICT
217
218In a make configuration file, a declaration attempts to modify a value that is
219inherited from a previous make, and considered read-only. Expects $e->get_ctx()
220to return a L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object.
221
222=item FCM::System::Exception->CONFIG_INHERIT
223
224In a make configuration file, a declaration attempts to inherit from a make that
225is either incomplete or failed. Expects $e->get_ctx() to return a
226L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object.
227
228=item FCM::System::Exception->CONFIG_MODIFIER
229
230In a make configuration file, a modifier of in a declaration is incorrect.
231Expects $e->get_ctx() to return a
232L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object and
233$e->get_exception() to return (if any) the original exception that triggers this
234failure.
235
236=item FCM::System::Exception->CONFIG_NS
237
238In a make configuration file, a declaration is missing a required name-space, or
239the name-space declaration is incorrect. Expects $e->get_ctx() to return a
240L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object and
241$e->get_exception() to return (if any) the original exception that triggers this
242failure.
243
244=item FCM::System::Exception->CONFIG_NS_VALUE
245
246In a make configuration file, the name-space of a declaration is incompatible
247with the value. (E.g. the number of name-space elements does not match with the
248number of words in a value.) Expects $e->get_ctx() to return a
249L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> object and
250$e->get_exception() to return (if any) the original exception that triggers this
251failure.
252
253=item FCM::System::Exception->CONFIG_UNKNOWN
254
255In a make configuration file, the label of a declaration is unrecognised by the
256system. Expects $e->get_ctx() to return a reference to an ARRAY containing
257L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry> objects.
258
259=item FCM::System::Exception->CONFIG_VALUE
260
261In 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>
263object and $e->get_exception() to return (if any) the original exception that
264triggers this failure.
265
266=item FCM::System::Exception->CONFIG_VERSION
267
268A make configuration file requires certain version of FCM. Expects
269$e->get_ctx() to return a L<FCM::Context::ConfigEntry|FCM::Context::ConfigEntry>
270object, and the current FCM version.
271
272=item FCM::System::Exception->COPY
273
274The system fails to perform a file copy. Expects $e->get_ctx() to return a
2752-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
280A destination path cannot be removed. Expects $e->get_ctx() to return the path
281that the system fails to remove, and $e->get_exception() to return the original
282exception that triggers this failure.
283
284=item FCM::System::Exception->DEST_CREATE
285
286The 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()
288to return the original exception that triggers this failure.
289
290=item FCM::System::Exception->DEST_LOCKED
291
292A lock file exists at the destination. Expects $e->get_ctx() to return the
293path to the lock file.
294
295=item FCM::System::Exception->EXPORT_ITEMS_SRC
296
297The system fails because the source location is not specified.
298
299=item FCM::System::Exception->EXTRACT_LOC_BASE
300
301The 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
306The 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
313The FCM::Context::Make::Extract::Target object associated with this failure.
314
315=item output
316
317The path to a file containing the failed merge output.
318
319=item keys_done
320
321The keys of the source trees providing the source files for this target that
322have already been merged.
323
324=item key
325
326The key of the source tree providing the source file for this target that causes
327the merge conflict.
328
329=item keys_left
330
331The keys of the source trees providing the source files for this target that are
332yet to be merged.
333
334=back
335
336=item FCM::System::Exception->EXTRACT_NS
337
338The system fails because there are some extract declarations for the name-spaces
339but the settings are not used. Expects $e->get_ctx() to return an ARRAY of bad
340name-spaces.
341
342=item FCM::System::Exception->MIRROR
343
344The mirror operation failed. Expects $e->get_ctx() to return a reference of a
3452-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
350The mirror step failed because a target is not specified. The $e->get_ctx() is
351undefined.
352
353=item FCM::System::Exception->MIRROR_SOURCE
354
355The mirror step failed because the destination of a completed step in the make
356is not suitable for mirroring. Expects $e->get_ctx() to return an ARRAY
357reference containing the names of the unsuitable steps.
358
359=item FCM::System::Exception->MIRROR_TARGET
360
361The mirror step failed to create the target. Expects $e->get_ctx() to
362return the target of the mirror, and $e->get_exception() to return the original
363exception that triggers this failure.
364
365=item FCM::System::Exception->MAKE
366
367A named step in a make is not implemented. Expects $e->get_ctx() to return the
368name of the step.
369
370=item FCM::System::Exception->MAKE_ARG
371
372A 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
383A make sub-system fails because it can find no configuration.
384
385=item FCM::System::Exception->MAKE_CFG_FILE
386
387A make sub-system fails because it cannot file a named configuration file.
388Expects $e->get_ctx() to return the configuration file name.
389
390=item FCM::System::Exception->MAKE_PROP_NS
391
392A make sub-system fails because a property is specified with an invalid
393name-space. Expects $e->get_ctx() to return an ARRAY reference of something like
394this:
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
404A make sub-system fails because a property is specified with an invalid
405value. Expects $e->get_ctx() to return an ARRAY reference of something like
406this:
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
416A shell command returns an error. Expects $e->get_ctx() to return a HASH
417reference containing {command_list}, an ARRAY reference representing the
418command; {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
420the standard error of the command.
421
422=back
423
424=head1 COPYRIGHT
425
426(C) Crown copyright Met Office. All rights reserved.
427
428=cut
Note: See TracBrowser for help on using the repository browser.