(err: int, io: bool = False)
| 33 | |
| 34 | |
| 35 | def check_error(err: int, io: bool = False) -> None: |
| 36 | if err >= 0: |
| 37 | return |
| 38 | |
| 39 | # These are special error codes, they should never reach here |
| 40 | test = err != C.GIT_EUSER and err != C.GIT_PASSTHROUGH |
| 41 | assert test, f'Unexpected error code {err}' |
| 42 | |
| 43 | # Error message |
| 44 | giterr = C.git_error_last() |
| 45 | if giterr != ffi.NULL: |
| 46 | message = ffi.string(giterr.message).decode('utf8', errors='surrogateescape') |
| 47 | else: |
| 48 | message = f'err {err} (no message provided)' |
| 49 | |
| 50 | # Translate to Python errors |
| 51 | if err in value_errors: |
| 52 | raise ValueError(message) |
| 53 | |
| 54 | if err == C.GIT_ENOTFOUND: |
| 55 | if io: |
| 56 | raise IOError(message) |
| 57 | |
| 58 | raise KeyError(message) |
| 59 | |
| 60 | if err == C.GIT_EINVALIDSPEC: |
| 61 | raise ValueError(message) |
| 62 | |
| 63 | if err == C.GIT_ITEROVER: |
| 64 | raise StopIteration() |
| 65 | |
| 66 | # Generic Git error |
| 67 | raise GitError(message) |
| 68 | |
| 69 | |
| 70 | # Indicate that we want libgit2 to pretend a function was not set |
no test coverage detected
searching dependent graphs…