From 8f0f94c32bcf60102e1d9deedb76f8689f6eded4 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Fri, 16 Sep 2022 17:27:50 +0200 Subject: [PATCH] Add a more helpful error for a messed up default translation --- translate.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/translate.py b/translate.py index 4029f16..ba71224 100644 --- a/translate.py +++ b/translate.py @@ -3,6 +3,7 @@ from __future__ import annotations from collections import abc from typing import Any, TypedDict, TYPE_CHECKING +from exceptions import MinerException from utils import json_load, json_save from constants import IS_PACKAGED, LANG_PATH, DEFAULT_LANG @@ -431,8 +432,14 @@ class Translator: if not path: raise ValueError("Language path expected") v: Any = self._translation - for key in path: - v = v[key] + try: + for key in path: + v = v[key] + except KeyError: + # this can only really happen for the default translation + raise MinerException( + f"{self.current} translation is missing the '{' -> '.join(path)}' translation key" + ) return v