• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

johntruckenbrodt / pyroSAR / 22909320619

10 Mar 2026 03:08PM UTC coverage: 55.132% (-0.03%) from 55.161%
22909320619

Pull #413

github

web-flow
Merge be3e550d9 into 54a60e792
Pull Request #413: Bugfix/gamma shellscript

2 of 18 new or added lines in 3 files covered. (11.11%)

1 existing line in 1 file now uncovered.

4190 of 7600 relevant lines covered (55.13%)

0.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

20.0
/pyroSAR/gamma/error.py
1
###############################################################################
2
# interface for translating GAMMA errors messages into Python error types
3

4
# Copyright (c) 2015-2026, the pyroSAR Developers.
5

6
# This file is part of the pyroSAR Project. It is subject to the
7
# license terms in the LICENSE.txt file found in the top-level
8
# directory of this distribution and at
9
# https://github.com/johntruckenbrodt/pyroSAR/blob/master/LICENSE.txt.
10
# No part of the pyroSAR project, including this file, may be
11
# copied, modified, propagated, or distributed except according
12
# to the terms contained in the LICENSE.txt file.
13
###############################################################################
14

15
import re
1✔
16
import signal
1✔
17

18

19
def gammaErrorHandler(returncode: int, out: str, err: str) -> None:
1✔
20
    """
21
    Function to raise errors in Python. This function is not intended
22
    for direct use but as part of function :func:`pyroSAR.gamma.auxil.process`.
23
    
24
    Parameters
25
    ----------
26
    returncode:
27
        the subprocess return code
28
    out:
29
        the stdout message returned by a subprocess call of a gamma command
30
    err:
31
        the stderr message returned by a subprocess call of a gamma command
32

33
    Raises: IOError | ValueError | RuntimeError
34

35
    """
36
    
37
    # scan stdout and stdin messages for lines starting with 'ERROR'
38
    messages = out.split('\n') if out else []
×
39
    messages.extend(err.strip().split('\n'))
×
40
    errormessages = [x for x in messages if x.startswith('ERROR')]
×
41
    
42
    # registry of known gamma error messages and corresponding Python error types
43
    # do not change the Python error types of specific messages! This will change the behavior of several functions
44
    # in case no error is to be thrown define None as error type
45
    knownErrors = {'image data formats differ': IOError,
×
46
                   'cannot open': IOError,
47
                   r'no coverage of SAR image by DEM(?: \(in (?:latitude/northing|longitude/easting)\)|)': RuntimeError,
48
                   'libgdal.so.1: no version information available': None,
49
                   'line outside of image': ValueError,
50
                   'no offsets found above SNR threshold': ValueError,
51
                   'window size < 4': ValueError,
52
                   'MLI oversampling factor must be 1, 2, 4, 8': ValueError,
53
                   'no points available for determining average intensity': ValueError,
54
                   'p_interp(): time outside of range': RuntimeError,
55
                   'no overlap with lookup table': RuntimeError,
56
                   'insufficient offset points to determine offset model parameters': RuntimeError,
57
                   'insufficient offset points left after culling to determine offset model parameters': RuntimeError,
58
                   'calloc_1d: number of elements <= 0': ValueError,
59
                   'multi-look output line:': RuntimeError,
60
                   'no OPOD state vector found with the required start time!': RuntimeError,
61
                   'gc_map operates only with slant range geometry, image geometry in SLC_par: GROUND_RANGE': RuntimeError,
62
                   'OPOD state vector data ends before start of the state vector time window': RuntimeError,
63
                   'non-zero exit status': RuntimeError,
64
                   'unsupported DEM projection': RuntimeError,
65
                   'tiffWriteProc:No space left on device': RuntimeError,
66
                   'in subroutine julday: there is no year zero!': RuntimeError,
67
                   'cannot create ISP image parameter file': OSError}
68
    
69
    # check if the error message is known and throw the mapped error from knownErrors accordingly.
70
    # Otherwise raise a RuntimeError if killed by a signal and a GammaUnknownError in all other cases.
71
    # The actual message is passed to the error and thus visible for backtracing.
72
    if returncode != 0:
×
73
        if len(errormessages) > 0:
×
74
            errormessage = errormessages[-1]
×
75
            err_out = '\n\n'.join([re.sub('ERROR[: ]*', '', x) for x in errormessages])
×
76
            for error in knownErrors:
×
77
                if re.search(error, errormessage):
×
78
                    errortype = knownErrors[error]
×
79
                    if errortype:
×
80
                        raise errortype(err_out)
×
81
                    else:
82
                        return
×
83
        else:
NEW
84
            err_out = f'{err}\nfailed with return code {returncode}'
×
85
            if returncode < 0:
×
86
                # handle signal kills like SIGSEGV (segmentation fault)
87
                sig = signal.Signals(-returncode)
×
88
                raise RuntimeError(err_out + f' ({sig.name})')
×
89
        raise GammaUnknownError(err_out)
×
90

91

92
class GammaUnknownError(Exception):
1✔
93
    """
94
    This is a general error, which is raised if the error message is not yet integrated
95
    into the known errors of function :func:`gammaErrorHandler`.
96
    If this error occurs, the message should be included in this function.
97
    """
98
    
99
    def __init__(self, errormessage):
1✔
100
        Exception.__init__(self, errormessage)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc