-
-
Notifications
You must be signed in to change notification settings - Fork 45
Improve logging around resizing in QuestionsView #3370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve logging around resizing in QuestionsView #3370
Conversation
📝 WalkthroughWalkthroughThe Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Rationale: Single-file change affecting one method. The modification introduces straightforward error handling (try-catch) and logging instrumentation with localized scope, requiring minimal context to verify correctness and understand intent. Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
app/src/org/commcare/views/QuestionsView.java (2)
350-350: Consider using a class-level Handler instance.Creating a new
Handler()on every scroll operation is inefficient and creates unnecessary object allocations. Since handlers are thread-safe and reusable, declare a single instance at the class level.Apply this diff to optimize Handler usage:
public class QuestionsView extends ScrollView implements OnLongClickListener, WidgetChangedListener { // starter random number for view IDs private final static int VIEW_ID = 12345; + private final Handler handler = new Handler();Then update the method:
private void scrollToWidget(final QuestionWidget widget) { - new Handler().post(() -> { + handler.post(() -> { String widgetTextId = "None";
352-354: Consider more specific exception handling.While catching all exceptions prevents the logging from breaking the scroll operation, silently ignoring exceptions could hide real issues with widget state. Consider at least logging the exception type if one occurs, or catching only the specific exceptions expected (e.g.,
NullPointerException).-try { - widgetTextId = widget.getPrompt().getQuestion().getTextID(); -} catch (Exception ignore) {} +try { + widgetTextId = widget.getPrompt().getQuestion().getTextID(); +} catch (Exception e) { + Logger.log(LogTypes.TYPE_ERROR_DESIGN, "Failed to get widget text ID: " + e.getClass().getSimpleName()); +}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/src/org/commcare/views/QuestionsView.java(1 hunks)
🔇 Additional comments (1)
app/src/org/commcare/views/QuestionsView.java (1)
355-355: Verify that SOFT_ASSERT is the appropriate logging level.
SOFT_ASSERTtypically indicates unexpected conditions that should be investigated, whereas this logs every normal scroll operation. If the goal is diagnostic logging to help debug the Crashlytics issue, consider whetherTYPE_USER_ACTIONor a debug-level log would be more appropriate. However, if you intentionally want this to stand out in logs during investigation, SOFT_ASSERT may be acceptable temporarily.Can you confirm whether SOFT_ASSERT is intended here for prominent visibility during the Crashlytics investigation, or should this use a different log level?
|
@damagatchi retest this please |
| } catch (Exception ignore) {} | ||
| Logger.log(LogTypes.SOFT_ASSERT, "Attempting to scroll to widget: " + widgetTextId); | ||
|
|
||
| QuestionsView.this.scrollTo(0, widget.getTop()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avazirna you can instead catch the exception in this call and rethrow with the additional details, that way we will only log this in case of errrors, otherwise I am afraid this is a rather high frequency log that we will want to avoid logging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also think we should not crash on failure to scroll to a widget here but just log it as a non-fatal. Crashing a user out during form entry is the worst outcome as user loose all their filled data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, agree. The problem is that this is not when the issue occurs, but I'm suspecting that it's from the UI redrawn this causes. I can catch on onSizeChanged()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shubham1g5 I moved the log to onSizeChanged() 9aca919
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avazirna Makes sense, Assuming you are not able to repro this issue, curious how do you know if the exception is getting triggered after scrollToWidget ? Or you are just taking a guess here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shubham1g5 I haven't been able to reproduce, but one common factor between the forms where this issue is happening is the app callout question, so I'm trying to assess whether it's related. Within QuestionsView there is the restoreFocusToQuestionThatCalledOut() which triggers the logic to scrollToWidget(), so the previous log was to assess whether this is the cause and what's the widget causing the issue.
e86e98c to
9aca919
Compare
| super.onSizeChanged(w, h, oldw, oldh); | ||
| } catch (IllegalArgumentException e) { | ||
| Logger.log(LogTypes.SOFT_ASSERT, | ||
| "Resizing from "+oldw+"X"+oldh+" to "+w+"X"+h+" failed with focus on: " + findFocus()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what will findFocus equate to as String ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shubham1g5 I changed this to get the name of the view class and its parent, which is supposed to be a QuestionWidget - 7913cde
9aca919 to
7913cde
Compare
| Logger.log(LogTypes.SOFT_ASSERT, | ||
| "Resizing from " + oldw + "X" + oldh + " to " + w + "X" + h + " failed with focus on: " + getFocusedViewClassName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log exception as it will gives exception details also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We rethrow the exception, so the crashes will continue to happen and we will be able to get the details from the crash reports. But I'm happy to send add these to the log as well.
| String focusedViewClassName = "None"; | ||
| if (focusedView != null) { | ||
| focusedViewClassName = focusedView.getClass().toString(); | ||
| if (focusedView.getParent() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What can be parent of QuestionView ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parent here is of the view who has the focus which is likely to be a QuestionWidget, like a StringWidget for instance. A StringWidget is composed by an EditText which if it has the focus, I'm expecting this to return something like Resizing 1from 0X0 to 720X1600 failed with focus on: class androidx.widget.EditText/class org.commcare.views.widgets.StringWidget
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, in case I think you can use simple class name by getClass().getSimpleName() or if full path required by getClass().getName()
Product Description
This is to improve visibility around this issue. It seems that an issue occurs during layout updates when returning to CommCare after launching a third-party app.
Labels and Review