Improve exception handling and reporting

#KT-59445
This commit is contained in:
Vladimir Dolzhenko
2023-06-20 13:27:17 +02:00
committed by Space Team
parent d865202bd5
commit 05652e7d8d
@@ -591,11 +591,24 @@ public class LockBasedStorageManager implements StorageManager {
} }
catch (Throwable throwable) { catch (Throwable throwable) {
if (ExceptionUtilsKt.isProcessCanceledException(throwable)) { if (ExceptionUtilsKt.isProcessCanceledException(throwable)) {
cache.remove(input); Object remove;
try {
remove = cache.remove(input);
} catch (Throwable e) {
throw unableToRemoveKey(input, e);
}
if (remove != NotValue.COMPUTING) {
throw inconsistentComputingKey(input, remove);
}
//noinspection ConstantConditions //noinspection ConstantConditions
throw (RuntimeException)throwable; throw (RuntimeException)throwable;
} }
if (throwable == error) { if (throwable == error) {
try {
cache.remove(input);
} catch (Throwable e) {
throw unableToRemoveKey(input, e);
}
throw storageManager.exceptionHandlingStrategy.handleException(throwable); throw storageManager.exceptionHandlingStrategy.handleException(throwable);
} }
@@ -625,6 +638,22 @@ public class LockBasedStorageManager implements StorageManager {
); );
} }
private AssertionError inconsistentComputingKey(K input, Object oldValue) {
return sanitizeStackTrace(
new AssertionError("Inconsistent key detected. "
+ NotValue.COMPUTING + " is expected, was: " + oldValue
+ ", most probably race condition detected on input " + input
+ " under " + storageManager)
);
}
private AssertionError unableToRemoveKey(K input, Throwable throwable) {
return sanitizeStackTrace(
new AssertionError("Unable to remove "
+ input + " under " + storageManager, throwable)
);
}
@Override @Override
public boolean isComputed(K key) { public boolean isComputed(K key) {
Object value = cache.get(key); Object value = cache.get(key);