Skip to content
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

feat: Log GutenbergKit errors #21621

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.viewpager.widget.ViewPager.SimpleOnPageChangeListener
import com.automattic.android.tracks.crashlogging.CrashLogging
import com.automattic.android.tracks.crashlogging.JsException
import com.automattic.android.tracks.crashlogging.JsExceptionCallback
import com.automattic.android.tracks.crashlogging.JsExceptionStackTraceElement
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
Expand Down Expand Up @@ -251,6 +252,7 @@ import org.wordpress.gutenberg.GutenbergWebViewPool
import org.wordpress.aztec.AztecExceptionHandler
import org.wordpress.aztec.exceptions.DynamicLayoutGetBlockIndexOutOfBoundsException
import org.wordpress.aztec.util.AztecLog
import org.wordpress.gutenberg.GutenbergJsException
import org.wordpress.gutenberg.GutenbergView
import org.wordpress.gutenberg.MediaType
import java.io.File
Expand Down Expand Up @@ -2540,6 +2542,36 @@ class EditPostActivity : BaseAppCompatActivity(), EditorFragmentActivity, Editor
openMediaLibrary(mediaType, initialSelection)
}
})
editorFragment?.onLogJsException(object : GutenbergView.LogJsExceptionListener {
override fun onLogJsException(exception: GutenbergJsException) {
val stackTraceElements = exception.stackTrace.map { stackTrace ->
JsExceptionStackTraceElement(
stackTrace.fileName,
stackTrace.lineNumber,
stackTrace.colNumber,
stackTrace.function
)
}

val jsException = JsException(
exception.type,
exception.message,
stackTraceElements,
exception.context,
exception.tags,
exception.isHandled,
exception.handledBy
)

val callback = object : JsExceptionCallback {
override fun onReportSent(success: Boolean) {
// Do nothing
}
}
Comment on lines +2547 to +2570
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike placing all of this GBK-specific logic in this file. I imagine it would require a larger refactor to avoid this, and I feel less confident envisioning what that might resemble. As one may notice, this addition mimics similar logic around it.

I welcome any thoughts of simple improvements, as well as long-term refactor ideas for decoupling the various editors. Transparently, the current Android editor logic is very confusing to me.


onLogJsException(jsException, callback)
}
})
} else {
editorFragment?.titleOrContentChanged?.observe(this@EditPostActivity) { _: Editable? ->
storePostViewModel.savePostWithDelay()
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ google-play-services-auth = '20.4.1'
google-services = '4.4.2'
gravatar = '2.2.0'
greenrobot-eventbus = '3.3.1'
gutenberg-kit = 'trunk-cc52214a50893b41898607ac0bff7f2787b085bb'
gutenberg-kit = '64-7c72b11fd9c4dba754706b4e79325f59b37ea3b6'
gutenberg-mobile = 'v1.121.0'
indexos-media-for-mobile = '43a9026f0973a2f0a74fa813132f6a16f7499c3a'
jackson-databind = '2.12.7.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
import org.wordpress.aztec.watchers.EndOfBufferMarkerAdder;
import org.wordpress.gutenberg.GutenbergView.ContentChangeListener;
import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener;
import org.wordpress.gutenberg.GutenbergView.LogJsExceptionListener;
import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener;
import org.xml.sax.Attributes;

Expand Down Expand Up @@ -718,6 +719,9 @@ public Pair<CharSequence, CharSequence> getTitleAndContent(CharSequence original
@Override public void onOpenMediaLibrary(@Nullable OpenMediaLibraryListener listener) {
}

@Override public void onLogJsException(@NonNull LogJsExceptionListener listener) {
}

@Override
public void onToolbarCollapseButtonClicked() {
mEditorFragmentListener.onTrackableEvent(TrackableEvent.ELLIPSIS_COLLAPSE_BUTTON_TAPPED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.wordpress.android.util.helpers.MediaGallery;
import org.wordpress.gutenberg.GutenbergView.ContentChangeListener;
import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener;
import org.wordpress.gutenberg.GutenbergView.LogJsExceptionListener;
import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener;

import java.util.ArrayList;
Expand All @@ -44,6 +45,7 @@ public abstract Pair<CharSequence, CharSequence> getTitleAndContent(CharSequence
public abstract void onEditorContentChanged(ContentChangeListener listener);
public abstract void onEditorHistoryChanged(HistoryChangeListener listener);
public abstract void onOpenMediaLibrary(OpenMediaLibraryListener listener);
public abstract void onLogJsException(LogJsExceptionListener listener);
public abstract LiveData<Editable> getTitleOrContentChanged();
public abstract void appendMediaFile(MediaFile mediaFile, String imageUrl, ImageLoader imageLoader);
public abstract void appendMediaFiles(Map<String, MediaFile> mediaList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.wordpress.aztec.IHistoryListener;
import org.wordpress.gutenberg.GutenbergView.ContentChangeListener;
import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener;
import org.wordpress.gutenberg.GutenbergView.LogJsExceptionListener;
import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener;
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergBridgeJS2Parent.LogExceptionCallback;
import org.wordpress.mobile.ReactNativeGutenbergBridge.GutenbergEmbedWebViewActivity;
Expand Down Expand Up @@ -1266,6 +1267,9 @@ public void onEditorHistoryChanged(@NonNull HistoryChangeListener listener) {
public void onOpenMediaLibrary(@NonNull OpenMediaLibraryListener listener) {
}

public void onLogJsException(@NonNull LogJsExceptionListener listener) {
}

@Override
public LiveData<Editable> getTitleOrContentChanged() {
return mTextWatcher.getAfterTextChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.wordpress.gutenberg.GutenbergView;
import org.wordpress.gutenberg.GutenbergView.ContentChangeListener;
import org.wordpress.gutenberg.GutenbergView.HistoryChangeListener;
import org.wordpress.gutenberg.GutenbergView.LogJsExceptionListener;
import org.wordpress.gutenberg.GutenbergView.OpenMediaLibraryListener;
import org.wordpress.gutenberg.GutenbergView.TitleAndContentCallback;
import org.wordpress.gutenberg.GutenbergWebViewPool;
Expand Down Expand Up @@ -82,6 +83,7 @@ public class GutenbergKitEditorFragment extends EditorFragmentAbstract implement
@Nullable private ContentChangeListener mContentChangeListener = null;
@Nullable private HistoryChangeListener mHistoryChangeListener = null;
@Nullable private OpenMediaLibraryListener mOpenMediaLibraryListener = null;
@Nullable private LogJsExceptionListener mOnLogJsExceptionListener = null;

private boolean mEditorDidMount;

Expand Down Expand Up @@ -139,6 +141,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mGutenbergView.setContentChangeListener(mContentChangeListener);
mGutenbergView.setHistoryChangeListener(mHistoryChangeListener);
mGutenbergView.setOpenMediaLibraryListener(mOpenMediaLibraryListener);
mGutenbergView.setLogJsExceptionListener(mOnLogJsExceptionListener);
mGutenbergView.setEditorDidBecomeAvailable(view -> {
mEditorFragmentListener.onEditorFragmentContentReady(new ArrayList<>(), false);
});
Expand Down Expand Up @@ -376,6 +379,10 @@ public void onOpenMediaLibrary(@NonNull OpenMediaLibraryListener listener) {
mOpenMediaLibraryListener = listener;
}

public void onLogJsException(@NonNull LogJsExceptionListener listener) {
mOnLogJsExceptionListener = listener;
}

@Override
public LiveData<Editable> getTitleOrContentChanged() {
return mTextWatcher.getAfterTextChanged();
Expand Down
Loading