Skip to content

Commit 2bcbc8b

Browse files
authored
improve: handle upload errors (#736)
* refactor: defaults to empty emitter * refactor chunk_size * collect stats in upload_finished event * refactor _session_key * remove UploadCancelled * re-raise ExifError from ExifWrite exceptions * clean up exceptions * throw EmptyZipFileError * Capture upload errors and return as results * Handle errors from result generator * fix types * fix types * validate user_items in upload.py * introduce uploader.SequenceError and use it to decide if we should interrupte the overall upload process * raise InvalidMapillaryZipFileError if the zip file does not contain valid metadata * improve history emitter setup * fix tests * tests * raise ex from prev ex
1 parent 1abfe50 commit 2bcbc8b

File tree

10 files changed

+351
-284
lines changed

10 files changed

+351
-284
lines changed

mapillary_tools/exceptions.py

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
from __future__ import annotations
2+
13
import typing as T
24

35

46
class MapillaryUserError(Exception):
57
exit_code: int
68

79

10+
class MapillaryProcessError(MapillaryUserError):
11+
"""
12+
Base exception for process specific errors
13+
"""
14+
15+
exit_code = 6
16+
17+
18+
class MapillaryDescriptionError(Exception):
19+
pass
20+
21+
822
class MapillaryBadParameterError(MapillaryUserError):
923
exit_code = 2
1024

@@ -17,44 +31,35 @@ class MapillaryInvalidDescriptionFile(MapillaryUserError):
1731
exit_code = 4
1832

1933

20-
class MapillaryUnknownFileTypeError(MapillaryUserError):
21-
exit_code = 5
22-
23-
24-
class MapillaryProcessError(MapillaryUserError):
25-
exit_code = 6
26-
27-
2834
class MapillaryVideoError(MapillaryUserError):
2935
exit_code = 7
3036

3137

3238
class MapillaryFFmpegNotFoundError(MapillaryUserError):
3339
exit_code = 8
34-
help = "https://github.com/mapillary/mapillary_tools#video-support"
3540

3641

3742
class MapillaryExiftoolNotFoundError(MapillaryUserError):
3843
exit_code = 8
3944

4045

41-
class MapillaryDescriptionError(Exception):
46+
class MapillaryGeoTaggingError(MapillaryDescriptionError):
4247
pass
4348

4449

45-
class MapillaryGeoTaggingError(MapillaryDescriptionError):
50+
class MapillaryVideoGPSNotFoundError(MapillaryDescriptionError):
4651
pass
4752

4853

49-
class MapillaryGPXEmptyError(MapillaryDescriptionError, MapillaryUserError):
50-
exit_code = 9
54+
class MapillaryGPXEmptyError(MapillaryDescriptionError):
55+
pass
5156

5257

53-
class MapillaryVideoGPSNotFoundError(MapillaryDescriptionError, MapillaryUserError):
54-
exit_code = 9
58+
class MapillaryGPSNoiseError(MapillaryDescriptionError):
59+
pass
5560

5661

57-
class MapillaryGPSNoiseError(MapillaryDescriptionError):
62+
class MapillaryStationaryVideoError(MapillaryDescriptionError):
5863
pass
5964

6065

@@ -68,39 +73,33 @@ def __init__(
6873
self.gpx_end_time = gpx_end_time
6974

7075

71-
class MapillaryStationaryVideoError(MapillaryDescriptionError, MapillaryUserError):
72-
exit_code = 10
73-
74-
75-
class MapillaryInvalidBlackVueVideoError(MapillaryDescriptionError, MapillaryUserError):
76-
exit_code = 11
77-
78-
7976
class MapillaryDuplicationError(MapillaryDescriptionError):
8077
def __init__(
8178
self,
8279
message: str,
8380
desc: T.Mapping[str, T.Any],
8481
distance: float,
85-
angle_diff: T.Optional[float],
82+
angle_diff: float | None,
8683
) -> None:
8784
super().__init__(message)
8885
self.desc = desc
8986
self.distance = distance
9087
self.angle_diff = angle_diff
9188

9289

93-
class MapillaryUploadedAlreadyError(MapillaryDescriptionError):
94-
def __init__(
95-
self,
96-
message: str,
97-
desc: T.Mapping[str, T.Any],
98-
) -> None:
99-
super().__init__(message)
100-
self.desc = desc
90+
class MapillaryEXIFNotFoundError(MapillaryDescriptionError):
91+
pass
10192

10293

103-
class MapillaryEXIFNotFoundError(MapillaryDescriptionError):
94+
class MapillaryFileTooLargeError(MapillaryDescriptionError):
95+
pass
96+
97+
98+
class MapillaryCaptureSpeedTooFastError(MapillaryDescriptionError):
99+
pass
100+
101+
102+
class MapillaryNullIslandError(MapillaryDescriptionError):
104103
pass
105104

106105

@@ -116,17 +115,5 @@ class MapillaryUploadUnauthorizedError(MapillaryUserError):
116115
exit_code = 14
117116

118117

119-
class MapillaryMetadataValidationError(MapillaryUserError, MapillaryDescriptionError):
118+
class MapillaryMetadataValidationError(MapillaryUserError):
120119
exit_code = 15
121-
122-
123-
class MapillaryFileTooLargeError(MapillaryDescriptionError):
124-
pass
125-
126-
127-
class MapillaryCaptureSpeedTooFastError(MapillaryDescriptionError):
128-
pass
129-
130-
131-
class MapillaryNullIslandError(MapillaryDescriptionError):
132-
pass

mapillary_tools/mp4/io_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44

55
class ChainedIO(io.IOBase):
6-
# is the chained stream seekable?
76
_streams: T.Sequence[io.IOBase]
87
# the beginning offset of the current stream
98
_begin_offset: int

mapillary_tools/process_geotag_properties.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,7 @@ def process_finalize(
562562
# skip all exceptions
563563
skipped_process_errors = {Exception}
564564
else:
565-
skipped_process_errors = {
566-
exceptions.MapillaryDuplicationError,
567-
exceptions.MapillaryUploadedAlreadyError,
568-
}
565+
skipped_process_errors = {exceptions.MapillaryDuplicationError}
569566
_show_stats(metadatas, skipped_process_errors=skipped_process_errors)
570567

571568
return metadatas

mapillary_tools/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,19 +456,19 @@ def validate_image_desc(desc: T.Any) -> None:
456456
jsonschema.validate(instance=desc, schema=ImageDescriptionFileSchema)
457457
except jsonschema.ValidationError as ex:
458458
# do not use str(ex) which is more verbose
459-
raise exceptions.MapillaryMetadataValidationError(ex.message)
459+
raise exceptions.MapillaryMetadataValidationError(ex.message) from ex
460460
try:
461461
map_capture_time_to_datetime(desc["MAPCaptureTime"])
462462
except ValueError as ex:
463-
raise exceptions.MapillaryMetadataValidationError(str(ex))
463+
raise exceptions.MapillaryMetadataValidationError(str(ex)) from ex
464464

465465

466466
def validate_video_desc(desc: T.Any) -> None:
467467
try:
468468
jsonschema.validate(instance=desc, schema=VideoDescriptionFileSchema)
469469
except jsonschema.ValidationError as ex:
470470
# do not use str(ex) which is more verbose
471-
raise exceptions.MapillaryMetadataValidationError(ex.message)
471+
raise exceptions.MapillaryMetadataValidationError(ex.message) from ex
472472

473473

474474
def datetime_to_map_capture_time(time: T.Union[datetime.datetime, int, float]) -> str:

0 commit comments

Comments
 (0)