From 19008e5e497939b7d55a8215c20889ed1034de62 Mon Sep 17 00:00:00 2001 From: freya02 <41875020+freya022@users.noreply.github.com> Date: Thu, 9 May 2024 20:42:37 +0200 Subject: [PATCH] Add LocalizationException --- .../api/exceptions/LocalizationException.java | 35 +++++++++++++++++++ .../localization/LocalizationMapper.java | 3 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/dv8tion/jda/api/exceptions/LocalizationException.java diff --git a/src/main/java/net/dv8tion/jda/api/exceptions/LocalizationException.java b/src/main/java/net/dv8tion/jda/api/exceptions/LocalizationException.java new file mode 100644 index 0000000000..298ca914ca --- /dev/null +++ b/src/main/java/net/dv8tion/jda/api/exceptions/LocalizationException.java @@ -0,0 +1,35 @@ +/* + * Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.dv8tion.jda.api.exceptions; + +import net.dv8tion.jda.api.interactions.commands.localization.LocalizationFunction; + +/** + * Exception indicating that an error occurred while localizing an application command. + * + *
They are usually caused by invalid strings, + * or exceptions in a {@link net.dv8tion.jda.api.interactions.commands.localization.LocalizationFunction LocalizationFunction}. + * + * @see net.dv8tion.jda.api.interactions.commands.build.CommandData#setLocalizationFunction(LocalizationFunction) CommandData.setLocalizationFunction(LocalizationFunction) + */ +public class LocalizationException extends RuntimeException +{ + public LocalizationException(String message, Throwable cause) + { + super(message, cause); + } +} diff --git a/src/main/java/net/dv8tion/jda/internal/interactions/command/localization/LocalizationMapper.java b/src/main/java/net/dv8tion/jda/internal/interactions/command/localization/LocalizationMapper.java index f28536a17b..57d78e2b35 100644 --- a/src/main/java/net/dv8tion/jda/internal/interactions/command/localization/LocalizationMapper.java +++ b/src/main/java/net/dv8tion/jda/internal/interactions/command/localization/LocalizationMapper.java @@ -16,6 +16,7 @@ package net.dv8tion.jda.internal.interactions.command.localization; +import net.dv8tion.jda.api.exceptions.LocalizationException; import net.dv8tion.jda.api.interactions.DiscordLocale; import net.dv8tion.jda.api.interactions.commands.Command; import net.dv8tion.jda.api.interactions.commands.build.*; @@ -155,7 +156,7 @@ private void trySetTranslation(LocalizationMap localizationMap, String finalComp } catch (Exception e) { - throw new RuntimeException("Unable to set translations from '" + localizationFunction.getClass().getName() + "' with key '" + key + "'", e); + throw new LocalizationException("Unable to set translations from '" + localizationFunction.getClass().getName() + "' with key '" + key + "'", e); } } }