From afb9fc8a4f9c363f82406c0e71513fd3d626e24a Mon Sep 17 00:00:00 2001 From: itismadness Date: Sun, 24 May 2020 06:22:03 +0100 Subject: [PATCH] wrap getLanguage call with try/catch and fallback to en default --- src/Logchecker.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Logchecker.php b/src/Logchecker.php index a58c891..2ee3ce3 100644 --- a/src/Logchecker.php +++ b/src/Logchecker.php @@ -3,6 +3,7 @@ namespace OrpheusNET\Logchecker; use OrpheusNET\Logchecker\Check\Ripper; +use OrpheusNET\Logchecker\Exception\UnknownLanguageException; use OrpheusNET\Logchecker\Exception\UnknownRipperException; use OrpheusNET\Logchecker\Parser\EAC\Translator; use Symfony\Component\Yaml\Yaml; @@ -366,17 +367,22 @@ class Logchecker { if ($this->ripper === Ripper::EAC) { $translator = new Translator(); - $lang = $translator->getLanguage($this->log); - if ($lang['code'] !== 'en') { - $this->language = $lang['code']; - $this->account( - "Translated log from {$lang['name']} ({$lang['name_english']}) to English.", - false, - false, - false, - true - ); - $this->log = $translator->translate($this->log, $lang['code']); + try { + $lang = $translator->getLanguage($this->log); + if ($lang['code'] !== 'en') { + $this->language = $lang['code']; + $this->account( + "Translated log from {$lang['name']} ({$lang['name_english']}) to English.", + false, + false, + false, + true + ); + $this->log = $translator->translate($this->log, $lang['code']); + } + } catch (UnknownLanguageException $exc) { + $this->language = 'en'; + $this->account('Could not determine language. Assuming English.', false, false, false, true); } }