Skip to content

Commit

Permalink
Stop on errors without an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
machinewrapped committed Jun 2, 2024
1 parent 257494f commit b7e4627
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions PySubtitle/SubtitleScene.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(self, dct = None):
self.number = dct.get('scene') or dct.get('number')
self.context = dct.get('context', {})
self._batches = dct.get('batches', [])
self.errors = dct.get('errors', [])

def __str__(self) -> str:
return f"SubtitleScene {self.number} with {self.size} batches and {self.linecount} lines"
Expand Down
9 changes: 7 additions & 2 deletions PySubtitle/SubtitleTranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ def TranslateSubtitles(self, subtitles : SubtitleFile):

self.TranslateScene(subtitles, scene, batch_numbers=batch_numbers)

if scene.errors and self.stop_on_error:
logging.error(f"Failed to translate scene {scene.number}... stopping translation")
return

if self.aborted:
logging.info("Translation aborted")
return
Expand Down Expand Up @@ -163,9 +167,10 @@ def TranslateScene(self, subtitles : SubtitleFile, scene : SubtitleScene, batch_
self.events.batch_translated(batch)

if batch.errors:
logging.warning(f"Failed to translate scene {batch.scene} batch {batch.number}")
logging.warning(f"Errors encountered translating scene {batch.scene} batch {batch.number}")
scene.errors.extend(batch.errors)
if self.stop_on_error:
raise TranslationImpossibleError("Stopping translation because of error")
return

if self.max_lines and self.lines_processed >= self.max_lines:
logging.info(f"Reached max_lines limit of ({self.max_lines} lines)... finishing")
Expand Down

0 comments on commit b7e4627

Please sign in to comment.