string-desc: Fix undefined behaviour.
[gnulib.git] / pygnulib / GLError.py
blobe57a50301fd35aab1911b19e24960fa0f1fc0656
1 # Copyright (C) 2002-2024 Free Software Foundation, Inc.
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 from __future__ import annotations
18 #===============================================================================
19 # Define global imports
20 #===============================================================================
21 import os
22 from typing import Any
25 #===============================================================================
26 # Define GLError class
27 #===============================================================================
28 class GLError(Exception):
29 '''Exception handler for pygnulib classes.'''
31 errno: int
32 errinfo: Any
33 args: tuple[int, Any]
35 def __init__(self, errno: int, errinfo: Any = None) -> None:
36 '''Each error has following parameters:
37 errno: code of error; used to catch error type
38 1: file does not exist in GLFileSystem: <file>
39 2: cannot patch file inside GLFileSystem: <file>
40 3: configure file does not exist: <configure.ac>
41 4: minimum supported autoconf version is 2.64, not <version>
42 5: <gnulib-comp.m4> is expected to contain gl_M4_BASE([<m4base>])
43 6: missing sourcebase argument
44 7: missing docbase argument
45 8: missing testsbase argument
46 9: missing libname argument
47 11: incompatible licenses on modules: <modules>
48 12: cannot process empty filelist
49 13: cannot create the given directory: <directory>
50 14: cannot delete the given file: <file>
51 15: cannot create the given file: <file>
52 16: cannot transform the given file: <file>
53 17: cannot update the given file: <file>
54 18: module lacks a license: <module>
55 19: could not create destination directory: <directory>
56 20: could not patch test-driver script
57 21: Option --automake-subdir is only supported if the definition of AUTOMAKE_OPTIONS in Makefile.am contains 'subdir-objects'.
58 22: not overwriting destination directory: <directory>
59 23: module <module> doesn't exist
60 24: module <module> cannot be used in a testdir
61 errinfo: additional information'''
62 self.errno = errno
63 self.errinfo = errinfo
64 self.args = (self.errno, self.errinfo)
66 def __repr__(self) -> str:
67 errno = self.errno
68 errinfo = self.errinfo
69 if self.message == None:
70 message = None
71 if errno == 1:
72 message = 'file does not exist in GLFileSystem: %s' % repr(errinfo)
73 elif errno == 2:
74 message = 'cannot patch file inside GLFileSystem: %s' % repr(errinfo)
75 elif errno == 3:
76 message = 'configure file does not exist: %s' % repr(errinfo)
77 elif errno == 4:
78 message = 'minimum supported autoconf version is 2.64, not %s' % repr(errinfo)
79 elif errno == 5:
80 message = '%s is expected to contain gl_M4_BASE([%s])' % (repr(os.path.join(errinfo, 'gnulib-comp.m4')), repr(errinfo))
81 elif errno == 6:
82 message = "missing sourcebase argument; cache file doesn't contain it, so you might have to set this argument"
83 elif errno == 7:
84 message = 'missing docbase argument; you might have to create GLImport instance with mode 0 and docbase argument'
85 elif errno == 8:
86 message = "missing testsbase argument; cache file doesn't contain it, so you might have to set this argument"
87 elif errno == 9:
88 message = "missing libname argument; cache file doesn't contain it, so you might have to set this argument"
89 elif errno == 11:
90 message = 'incompatible licenses on modules: %s' % repr(errinfo)
91 elif errno == 12:
92 message = 'cannot process empty filelist'
93 elif errno == 13:
94 message = 'cannot create the given directory: %s' % repr(errinfo)
95 elif errno == 14:
96 message = 'cannot remove the given file: %s' % repr(errinfo)
97 elif errno == 15:
98 message = 'cannot create the given file: %s' % repr(errinfo)
99 elif errno == 16:
100 message = 'cannot transform the given file: %s' % repr(errinfo)
101 elif errno == 17:
102 message = 'cannot update/replace the given file: %s' % repr(errinfo)
103 elif errno == 18:
104 message = 'module lacks a license: %s' % repr(errinfo)
105 elif errno == 19:
106 message = 'error when running subprocess: %s' % repr(errinfo)
107 elif errno == 20:
108 message = 'could not patch test-driver script'
109 elif errno == 21:
110 message = ('Option --automake-subdir/--automake-subdir-tests are only '
111 'supported if the definition of AUTOMAKE_OPTIONS in '
112 'Makefile.am contains \'subdir-objects\'.')
113 elif errno == 22:
114 message = 'not overwriting destination directory: %s' % repr(errinfo)
115 elif errno == 23:
116 message = "module %s doesn't exist" % repr(errinfo)
117 elif errno == 24:
118 message = 'module %s cannot be used in a testdir' % repr(errinfo)
119 self.message = '[Errno %d] %s' % (errno, message)
120 return self.message