From db1ab602737f8456c725c1d298a30a0ca1ac0829 Mon Sep 17 00:00:00 2001
From: Damyon Wiese <damyon@moodle.com>
Date: Tue, 22 Nov 2016 21:54:03 +0800
Subject: [PATCH] MDL-57103 JS: Exceptions give exceptions

Exceptions returned from ajax are not in the format expected by the JS, so
an error occurs and the exception popups are not appearing.

Conflicts:
	lib/amd/build/notification.min.js
	lib/amd/src/notification.js
---
 lib/amd/build/notification.min.js | Bin 671 -> 895 bytes
 lib/amd/src/notification.js       |  27 ++++++++++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/lib/amd/build/notification.min.js b/lib/amd/build/notification.min.js
index 37952ecce657876371431e889b0b613295202bfb..2da3ec7a91ba40d986cdb1a7dfe1fc50d15448e3 100644
GIT binary patch
delta 344
zcmZvYT}lHn6h^6_Yw$7TAtbhB6rn;(TtYWcE9B><9XgXp%qSw#75LNzxCQs)V)UkT
z+CKP}obS7bn|z)BUVMKJHnr!p3l4l8z)_|0+Y>}jjC{`8t{LO|lcH3NjC5eSWgUDx
zCPQ_Chx8%riUy~1(iX(~-cWi6I(^ZJSY<XxBwL;BidPM8LiqfVEUpBJz7ivMI@#AS
zDy<2&CZrNm%b1<tEOvVp#jI-$Bvlw17;}B->jq}J1y#r;zNrVYfw0W0``c@jY<~vh
b>P`sp@&ES(G%#i)q!g2l4ljJm&tCrkKDuyX

delta 118
zcmey*HlKAvFQZ?QUQ%Lmc1clUa;ln|Mv`7mW?rgaX>L+#ku8!`v_ULbMkh%xEi)(8
qFEKY2T^b~=GkGzSnYe)_P+4&a&{&|Fl+>is^vt}pe4WW0%;f;lxG6&b

diff --git a/lib/amd/src/notification.js b/lib/amd/src/notification.js
index 1880b80..d574cdc 100644
--- a/lib/amd/src/notification.js
+++ b/lib/amd/src/notification.js
@@ -88,14 +88,31 @@ define(['core/yui'], function(Y) {
          */
         exception: function(ex) {
             // Fudge some parameters.
+            if (typeof ex.stack == 'undefined') {
+                ex.stack = '';
+            }
+            if (ex.debuginfo) {
+                ex.stack += ex.debuginfo + '\n';
+            }
             if (ex.backtrace) {
-                ex.lineNumber = ex.backtrace[0].line;
-                ex.fileName = ex.backtrace[0].file;
-                ex.fileName = '...' + ex.fileName.substr(ex.fileName.length - 20);
-                ex.stack = ex.debuginfo;
+                ex.stack += ex.backtrace;
+                var ln = ex.backtrace.match(/line ([^ ]*) of/);
+                var fn = ex.backtrace.match(/ of ([^:]*): /);
+                if (ln && ln[1]) {
+                    ex.lineNumber = ln[1];
+                }
+                if (fn && fn[1]) {
+                    ex.fileName = fn[1];
+                    if (ex.fileName.length > 30) {
+                        ex.fileName = '...' + ex.fileName.substr(ex.fileName.length - 27);
+                    }
+                }
+            }
+            if (typeof ex.name == 'undefined' && ex.errorcode) {
                 ex.name = ex.errorcode;
             }
-            Y.use('moodle-core-notification-exception', function () {
+
+            Y.use('moodle-core-notification-exception', function() {
                 var modal = new M.core.exception(ex);
 
                 modal.show();
-- 
1.9.1

