Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
give more context information when logging gwt error on server
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Nov 9, 2012
1 parent 784a793 commit f5b5121
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 13 deletions.
Expand Up @@ -57,10 +57,12 @@ public class Application implements EntryPoint
private static Identity identity;

private final static WebTransGinjector injector = GWT.create(WebTransGinjector.class);
private UncaughtExceptionHandlerImpl exceptionHandler;

public void onModuleLoad()
{
GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandlerImpl(injector.getDispatcher(), injector.getUserConfig()));
exceptionHandler = new UncaughtExceptionHandlerImpl(injector.getDispatcher(), injector.getUserConfig());
GWT.setUncaughtExceptionHandler(exceptionHandler);

injector.getDispatcher().execute(new ActivateWorkspaceAction(getWorkspaceId()), new AsyncCallback<ActivateWorkspaceResult>()
{
Expand Down Expand Up @@ -192,6 +194,9 @@ public void onSuccess(GetDocumentListResult result)
// re-use these stats for the project stats
Log.info("Time to calculate project stats: " + String.valueOf(System.currentTimeMillis() - start) + "ms");
eventBus.fireEvent(new ProjectStatsUpdatedEvent(projectStats));

exceptionHandler.setAppPresenter(appPresenter);
exceptionHandler.setTargetContentsPresenter(injector.getTargetContentsPresenter());
}
});
}
Expand Down Expand Up @@ -280,8 +285,6 @@ public static String getModuleParentBaseUrl()
*
* @param message to display
* @param e non-null to provide a stack trace in an expandable view.
* @param linkText text to display for link
* @param linkUrl href for link
*/
private static void showErrorWithLink(String message, Throwable e)
{
Expand Down
@@ -1,5 +1,7 @@
package org.zanata.webtrans.client;

import org.zanata.webtrans.client.presenter.AppPresenter;
import org.zanata.webtrans.client.presenter.TargetContentsPresenter;
import org.zanata.webtrans.client.presenter.UserConfigHolder;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.rpc.NoOpAsyncCallback;
Expand All @@ -8,11 +10,8 @@
import org.zanata.webtrans.shared.rpc.RemoteLoggingAction;
import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.UmbrellaException;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.HTMLPanel;
Expand All @@ -29,6 +28,8 @@ class UncaughtExceptionHandlerImpl implements GWT.UncaughtExceptionHandler

private final CachingDispatchAsync dispatcher;
private final UserConfigHolder configHolder;
private AppPresenter appPresenter;
private TargetContentsPresenter targetContentsPresenter;

protected UncaughtExceptionHandlerImpl(CachingDispatchAsync dispatcher, UserConfigHolder configHolder)
{
Expand All @@ -44,7 +45,12 @@ public void onUncaughtException(Throwable exception)
Log.fatal("uncaught exception", e);

String stackTrace = buildStackTraceMessages(e);
dispatcher.execute(new RemoteLoggingAction(stackTrace), new NoOpAsyncCallback<NoOpResult>());

RemoteLoggingAction action = new RemoteLoggingAction(stackTrace);
action.addContextInfo("selected Doc", appPresenter.getSelectedDocumentInfoOrNull());
action.addContextInfo("selected TransUnitId", targetContentsPresenter.getCurrentTransUnitIdOrNull());
action.addContextInfo("editor contents", targetContentsPresenter.getNewTargets());
dispatcher.execute(action, new NoOpAsyncCallback<NoOpResult>());

if (!configHolder.isShowError())
{
Expand Down Expand Up @@ -117,4 +123,14 @@ private static DisclosurePanel buildStackTraceDisclosurePanel(String stackTrace)
disclosurePanel.setOpen(false);
return disclosurePanel;
}

public void setAppPresenter(AppPresenter appPresenter)
{
this.appPresenter = appPresenter;
}

public void setTargetContentsPresenter(TargetContentsPresenter targetContentsPresenter)
{
this.targetContentsPresenter = targetContentsPresenter;
}
}
Expand Up @@ -6,6 +6,7 @@
import org.zanata.webtrans.client.history.History;
import org.zanata.webtrans.client.history.Window;
import org.zanata.webtrans.client.presenter.AppPresenter;
import org.zanata.webtrans.client.presenter.TargetContentsPresenter;
import org.zanata.webtrans.client.presenter.UserConfigHolder;
import org.zanata.webtrans.client.presenter.DocumentListPresenter;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
Expand Down Expand Up @@ -38,4 +39,6 @@ public interface WebTransGinjector extends Ginjector
History getHistory();

HistoryEventHandlerService getHistoryEventHandlerService();

TargetContentsPresenter getTargetContentsPresenter();
}
Expand Up @@ -293,6 +293,11 @@ public DocumentId getSelectedDocIdOrNull()
return selectedDocument == null ? null : selectedDocument.getId();
}

public DocumentInfo getSelectedDocumentInfoOrNull()
{
return selectedDocument == null ? null : selectedDocument;
}

@Override
public void onShowSideMenu(ShowSideMenuEvent event)
{
Expand Down
Expand Up @@ -32,7 +32,7 @@ public NoOpResult execute(RemoteLoggingAction action, ExecutionContext context)
{
identity.checkLoggedIn();
log.error("[gwt-log] from user: {} on workspace: {}", identity.getCredentials().getUsername(), action.getWorkspaceId());
log.error("[gwt-log] {}", action.getMessage());
log.error("[gwt-log] context: {} \n{}", action.getContextInfo(), action.getMessage());
}
catch (Exception e)
{
Expand Down
Expand Up @@ -62,10 +62,10 @@ public String toString()
@Override
public boolean equals(Object obj)
{
if (obj == null)
return false;
if (!(obj instanceof DocumentInfo))
if (obj == null || !(obj instanceof DocumentInfo))
{
return false;
}
DocumentInfo other = (DocumentInfo) obj;
return (id.equals(other.getId()));
}
Expand Down
@@ -1,13 +1,17 @@
package org.zanata.webtrans.shared.rpc;

import java.util.logging.Level;
import java.util.List;

import com.google.common.base.Objects;
import com.google.common.collect.Lists;

/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
public class RemoteLoggingAction extends AbstractWorkspaceAction<NoOpResult>
{
private String message;
private List<String> contextInfo = Lists.newArrayList();

@SuppressWarnings("unused")
public RemoteLoggingAction()
Expand All @@ -29,4 +33,15 @@ public String getMessage()
{
return message;
}

public List<String> getContextInfo()
{
return contextInfo;
}

public RemoteLoggingAction addContextInfo(String contextName, Object contextValue)
{
contextInfo.add(Objects.toStringHelper("").add(contextName, contextValue).toString());
return this;
}
}
Expand Up @@ -284,6 +284,7 @@ public void canSwitchToDocumentView()
{
// Given: current selected document is null
assertThat(presenter.getSelectedDocIdOrNull(), Matchers.is(Matchers.nullValue()));
assertThat(presenter.getSelectedDocumentInfoOrNull(), Matchers.is(Matchers.nullValue()));
when(messages.documentListTitle()).thenReturn("Documents");
presenter.setStatesForTest(projectStats, selectedDocumentStats, null, null);

Expand Down Expand Up @@ -344,12 +345,13 @@ public void canSelectDocumentNotInEditorView()

verifyNoMoreInteractions(display);
assertThat(presenter.getSelectedDocIdOrNull(), Matchers.is(docId));
assertThat(presenter.getSelectedDocumentInfoOrNull(), Matchers.is(documentInfo));
}

@Test
public void onDocumentStatsUpdateWillDoNothingIfNoSelectedDocument()
{
assertThat(presenter.getSelectedDocIdOrNull(), Matchers.is(Matchers.nullValue()));
assertThat(presenter.getSelectedDocumentInfoOrNull(), Matchers.is(Matchers.nullValue()));

presenter.onDocumentStatsUpdated(new DocumentStatsUpdatedEvent(new DocumentId(1L), new TranslationStats()));

Expand Down

0 comments on commit f5b5121

Please sign in to comment.