Support readiness before putting the winjs app out for trial

Published April 15, 2014 1:08 pm

Before deploying the current app under development for trial, I was thinking about app support. We needed:

  1. ability to quickly get the error information from the user.
  2. ability to get unhandled exception detail in case App crashes.

Let’s talk about first. Across the app codebase, Util method handleError is used to display error to the user. This method used the standard Windows.UI.Popups.MessageDialog. The solution was to add a ‘copy’ command to the dialog – to enable user to copy error to clipboard. The code for this is quite straight forward by going through some pages in msdn.

function handleError(error)
{
    assert.instanceOf(error, Error);
    var message = getDisplayErrorMessage(error);
    var popups = Windows.UI.Popups;
    var dialog = new popups.MessageDialog(message);
    dialog.commands.append(new popups.UICommand('Copy', copyCommand));
    dialog.commands.append(new popups.UICommand('Close'));
    dialog.defaultCommandIndex = 1;
    return dialog.showAsync();

    function copyCommand(event)
    {
        copyToClipboard({ message: message, stack: error.stack });
    }

    function copyToClipboard(data)    
    {
        assert.isObject(data);
        var dt = Windows.ApplicationModel.DataTransfer;
        var dp = new dt.DataPackage();
        dp.requestedOperation = dt.DataPackageOperation.copy;
        dp.setText(JSON.stringify(data));
        dt.Clipboard.setContent(dp);
    }
}

getErrorDisplayMessage is implementation specific. In our case, it goes through all innerError and error contextual detail – to form a display message. For example: every error related to a backend service call includes requestId guid. This enables support to trace down the faulting service request.

Regards second thing: WinJS.Application.onerror or Windows.onerror provides the hook to get to the unhandled exception. First tried solution was to copy the unhandled exception to clipboard through this hook. What I found – the error is copied to the clipboard but clipboard is cleared after the app exits. Hence, this solution does not work.

After little bit of bing, I found a post – which mentioned that the apphost source logs an administrative event in windows event log when the app crashes. Quickest way to get exception details to clipboard is –

  1. win+x key,
  2. selection event viewer,
  3. go to custom views->administrative events,
  4. right click the event with source ‘apphost’,
  5. copy->copy details as text.

Steps are long but for the time being – they looked good enough. event has all the details including exception fields and stack. Other solution is to log details to disk and add feature in app to share/copy to clipboard the data about last app crash. This solution looked costly for now.

With this, the app is support ready. How do you handle errors in your app and ask user to share the error info with you?