Log the name of the calculator when an exception is thrown

This commit is contained in:
Luck
2018-01-23 16:52:50 +00:00
Unverified
parent 0eba5f1cbc
commit 6923c4e247
4 changed files with 63 additions and 9 deletions
@@ -186,7 +186,7 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
}
accumulator = ret;
} catch (Exception e) {
AbstractContextManager.this.plugin.getLog().warn("An exception was thrown whilst calculating the context of subject " + subject);
AbstractContextManager.this.plugin.getLog().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating the context of subject " + subject);
e.printStackTrace();
}
}
@@ -209,7 +209,7 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
}
accumulator = ret;
} catch (Exception e) {
AbstractContextManager.this.plugin.getLog().warn("An exception was thrown whilst calculating static contexts");
AbstractContextManager.this.plugin.getLog().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating static contexts");
e.printStackTrace();
}
}
@@ -218,4 +218,14 @@ public abstract class AbstractContextManager<T> implements ContextManager<T> {
}
}
private static String getCalculatorClass(ContextCalculator<?> calculator) {
Class<?> calculatorClass;
if (calculator instanceof ProxiedContextCalculator) {
calculatorClass = ((ProxiedContextCalculator) calculator).getDelegate().getClass();
} else {
calculatorClass = calculator.getClass();
}
return calculatorClass.getName();
}
}
@@ -0,0 +1,37 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.contexts;
import me.lucko.luckperms.api.context.ContextCalculator;
/**
* Represents a {@link ContextCalculator} which delegates calls to another object.
*/
public interface ProxiedContextCalculator<T> extends ContextCalculator<T> {
Object getDelegate();
}