Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-5135

make a client error more helpful for debug

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Critical Critical
    • 10.0.0
    • 9.6.1
    • None
    • Security Level: Jimmy
    • None

      User Story

      1. As a support engineer, I want to see a javascript error stack trace so that I can start to debug more efficiently.
      2. As a web app developer, when I see a client error in a server log like Failed to mount: Unexpected token '.', it doesn't help a lot. Since I don't know the error happens on which browser and no error stack trace is not helpful for a support engineer to help him.
      3. As a web app developer, when a browser sends client errors to a server, it might be a way to allow a client to spam a server with lots of errors. This could be a kind of DOS attack. I need a way to disable this error-sending behavior.
      4. As a web app developer, I want to override the way to show an error popup, so that the error pop-up won't frighten end-users and think the system is broken.

      Acceptance Criteria

      1. print the javascript error stack trace in a browser console at which page URL:
      2. need to defend an attacker sending massive errors on purpose
      3. when sending the error to a server, need to include page URL info e.g. at http://mywebapp/mypage.zul
        Example:
        Client encountered an error at [MYPAGE.zul]. Error stack trace: 
        [ERROR STACKTRACE]
        
      4. make the js function to show error popup as a public and separate function, so that app devs can override it.

      Details

      Currently, zk shows an error when catching an error with zk.error():

      But it just shows the error dialog and sends it to the server with empty data like:

      > SEVERE: [Desktop z_6ry:/charts/14960.zul] client error: {}

      This doesn't help for debugging, especially when an error happens on the user side. Then it doesn't print any error stack trace at the console which takes more time to locate the root cause.

      There are several cases in ZK client that just call zk.error() for an error:

      • https://tracker.zkoss.org/browse/ZKCHARTS-130
      • SimpleConstraint.js
        try { this._regex = new RegExp(k >= 0 ? cst.substring(j, k) : cst.substring(j), regexFlags || 'g'); }

        catch (e)

        { zk.error(e.message || e); }

        <textbox constraint="//aab\o/"/><!-- cause js error: Invalid flags supplied to RegExp constructor-->

      • In js widget code in Pdfviewer, Barcode, Barcodescanner, Video they just show the error message like zk.error(err.message) and don't print the error stack trace.

      workaround

      	<device-config>
      		<device-type>ajax</device-type>
      		<embed><![CDATA[
              <script type="text/javascript">
              zk.afterLoad('zk', function() {
                  zk.error = function (msg) {
                      zAu.send(new zk.Event(null, 'error', {message: msg}, {ignorable: true}), 800);
                      zk._Erbx.push(msg);
                      if (msg.stack){
                          console.log(msg.stack);
                      }
                  };
              });
              </script>
           ]]></embed>
      	</device-config>
      

            rebeccalai rebeccalai
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: