Skip to content

Commit

Permalink
Throw custom exception to understand better context of crash
Browse files Browse the repository at this point in the history
Summary:
We are having this [MID](https://www.internalfb.com/logview/instagram_android_crashes/f37030d0e3709c2366462f94c66663b1?trace_tab=0&ds=%7B%22start%22%3A%22-2%20weeks%22%2C%22end%22%3A%22now%22%7D) , where it seems there is an inconsistency between `initialStatesToRestore` and `animationStates`.

I'm trying to add more information on the context to see if I can understand a bit better what is happening. (I might have to add more info later on, but let's start somewhere).

Reviewed By: apowolny

Differential Revision: D67024338

fbshipit-source-id: f6b2df54f0d7054d00a97eaf0baf02257b4d49a0
  • Loading branch information
Fabio Carballo authored and facebook-github-bot committed Dec 10, 2024
1 parent 04a99a1 commit 3145757
Showing 1 changed file with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -725,18 +725,71 @@ private void createAnimationsForTransitionUnit(
}

private void restoreInitialStates() {
for (PropertyHandle propertyHandle : mInitialStatesToRestore.keySet()) {
final float value = mInitialStatesToRestore.get(propertyHandle);
final TransitionId transitionId = propertyHandle.getTransitionId();
final AnimationState animationState = mAnimationStates.get(transitionId);
if (animationState.mountContentGroup != null) {
setPropertyValue(propertyHandle.getProperty(), value, animationState.mountContentGroup);
PropertyHandle lastPropertyHandle = null;
try {
for (PropertyHandle propertyHandle : mInitialStatesToRestore.keySet()) {
lastPropertyHandle = propertyHandle;
final float value = mInitialStatesToRestore.get(propertyHandle);
final TransitionId transitionId = propertyHandle.getTransitionId();
final AnimationState animationState = mAnimationStates.get(transitionId);

if (animationState.mountContentGroup != null) {
setPropertyValue(propertyHandle.getProperty(), value, animationState.mountContentGroup);
}
}
} catch (Exception e) {
throw new InconsistentInitialStateRestorationException(lastPropertyHandle, e);
}

mInitialStatesToRestore.clear();
}

private class InconsistentInitialStateRestorationException extends RuntimeException {

@Nullable private PropertyHandle lastPropHandle;

public InconsistentInitialStateRestorationException(
@Nullable PropertyHandle lastPropHandle, Exception cause) {
super(cause);
this.lastPropHandle = lastPropHandle;
}

@Override
public String getMessage() {
StringBuilder message = new StringBuilder();
message
.append("Inconsistent initial state restoration:\n")
.append("- mAnimationStates (")
.append(mAnimationStates.ids().size())
.append("):\n")
.append(" - ids: ")
.append(mAnimationStates.ids())
.append("\n- mInitialStatesToRestore (")
.append(mInitialStatesToRestore.size())
.append("):\n");

for (PropertyHandle propertyHandle : mInitialStatesToRestore.keySet()) {
Float value = mInitialStatesToRestore.get(propertyHandle);
final TransitionId transitionid = propertyHandle.getTransitionId();
boolean isCrashingOne =
lastPropHandle != null && lastPropHandle.getTransitionId().equals(transitionid);
final String propertyName = propertyHandle.getProperty().getName();

message
.append(" - propertyHandle[transitionId=")
.append(transitionid)
.append(", property=")
.append(propertyName)
.append("]")
.append(isCrashingOne ? "[crashing] " : " ")
.append(value)
.append("\n");
}

return message.toString();
}
}

private void setMountContentInner(
TransitionId transitionId,
AnimationState animationState,
Expand Down

0 comments on commit 3145757

Please sign in to comment.