Skip to content

Commit 7f457f2

Browse files
committed
🥅 Add error handling for missing emojis.json file in utils.py
from 682377f Signed-off-by: Paillat-dev <[email protected]>
1 parent 2ef0974 commit 7f457f2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

discord/utils/public.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import importlib.resources
66
import itertools
77
import json
8+
import logging
89
import re
910
from collections.abc import Awaitable, Callable, Iterable
1011
from enum import Enum, auto
@@ -16,8 +17,9 @@
1617
from ..commands.options import OptionChoice
1718
from ..permissions import Permissions
1819

19-
T = TypeVar("T")
20+
_log = logging.getLogger(__name__)
2021

22+
T = TypeVar("T")
2123

2224
class Undefined(Enum):
2325
MISSING = auto()
@@ -541,8 +543,13 @@ def find(predicate: Callable[[T], Any], seq: Iterable[T]) -> T | None:
541543
return element
542544
return None
543545

546+
try:
547+
with importlib.resources.files(__package__).joinpath("../emojis.json").open(encoding="utf-8") as f:
548+
EMOJIS_MAP = json.load(f)
549+
except FileNotFoundError:
550+
_log.debug(
551+
"Couldn't find emojis.json. Is the package data missing? Discord emojis names will not work.",
552+
)
544553

545-
with importlib.resources.files(__package__).joinpath("../emojis.json").open(encoding="utf-8") as f:
546-
EMOJIS_MAP = json.load(f)
547-
554+
EMOJIS_MAP = {}
548555
UNICODE_EMOJIS = set(EMOJIS_MAP.values())

0 commit comments

Comments
 (0)