]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/evergreen/util/error.js
privileges
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / evergreen / util / error.js
1 dump('entering util/error.js\n');
2
3 if (typeof util == 'undefined') util = {};
4 util.error = function () {
5
6         try {
7                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
8                 this.consoleService = Components.classes['@mozilla.org/consoleservice;1']
9                         .getService(Components.interfaces.nsIConsoleService);
10         } catch(E) {
11                 this.consoleDump = false;
12                 dump('util.error constructor: ' + E + '\n');
13         }
14
15         this.sdump_last_time = new Date();
16
17         return this;
18 };
19
20 util.error.prototype = {
21
22         'printDebug' : true,
23         'consoleDump' : true,
24         'debugDump' : true,
25         'arg_dump_full' : false,
26
27         'debug' : function(e){
28                 dump('-----------------------------------------\n' 
29                         + e + '\n-----------------------------------------\n' );
30         },
31
32         'sdump_levels' : {
33
34                 'D_NONE' : false, 'D_ALL' : true, 'D_ERROR' : true, 'D_DEBUG' : true, 'D_TRACE' :  false,
35                 'D_TRACE_ENTER' :  false, 'D_TRACE_EXIT' :  false, 'D_TIMEOUT' :  false, 'D_FILTER' : false,
36                 'D_CONSTRUCTOR' : false, 'D_FIREFOX' : false, 'D_LEGACY' : false,
37
38                 'D_CLAM' : false, 'D_PAGED_TREE' : false, 'D_GRID_LIST' : false, 'D_HTML_TABLE' : false,
39                 'D_TAB' : false,
40
41                 'D_AUTH' : true, 'D_OPAC' : true, 'D_CAT' : false,
42
43                 'D_PATRON_SEARCH' : false, 'D_PATRON_SEARCH_FORM' : false, 'D_PATRON_SEARCH_RESULTS' : false,
44
45                 'D_PATRON_DISPLAY' : false, 'D_PATRON_DISPLAY_STATUS' : false, 'D_PATRON_DISPLAY_CONTACT' : false,
46
47                 'D_PATRON_ITEMS' : false, 'D_PATRON_CHECKOUT_ITEMS' : false, 'D_PATRON_HOLDS' : false,
48                 'D_PATRON_BILLS' : false, 'D_PATRON_EDIT' : false,
49
50                 'D_CHECKIN' : false, 'D_CHECKIN_ITEMS' : false,
51
52                 'D_HOLD_CAPTURE' : false, 'D_HOLD_CAPTURE_ITEMS' : false,
53
54                 'D_PATRON_UTILS' : false, 'D_CIRC_UTILS' : false,
55
56                 'D_FILE' : true, 'D_EXPLODE' : false, 'D_FM_UTILS' : false, 'D_PRINT' : false, 'D_SES' : true,
57                 'D_SES_FUNC' : false, 'D_SES_RESULT' : true, 'D_SPAWN' : false, 'D_STRING' : false,
58                 'D_UTIL' : false, 'D_WIN' : true, 'D_WIDGETS' : false
59         },
60
61         'filter_console_init' : function (p) {
62                 this.sdump('D_FILTER',this.arg_dump(arguments,{0:true}));
63
64                 var filterConsoleListener = {
65                         observe: function( msg ) {
66                                 try {
67                                         p.observe_msg( msg );
68                                 } catch(E) {
69                                         alert(E);
70                                 }
71                         },
72                         QueryInterface: function (iid) {
73                                 if (!iid.equals(Components.interfaces.nsIConsoleListener) &&
74                                         !iid.equals(Components.interfaces.nsISupports)) {
75                                                 throw Components.results.NS_ERROR_NO_INTERFACE;
76                                 }
77                                 return this;
78                         }
79                 };
80                 try {
81                         this.consoleService.registerListener(filterConsoleListener);    
82                 } catch(E) {
83                         alert(E);
84                 }
85
86                 this.sdump('D_TRACE_EXIT',this.arg_dump(arguments));
87         },
88
89         'sdump' : function (level,msg) {
90                 try {
91                         var now = new Date();
92                         var message = now.valueOf() + '\tdelta = ' + (now.valueOf() - this.sdump_last_time.valueOf()) + '\t' + level + '\n' + msg;
93                         if (this.sdump_levels['D_NONE']) return null;
94                         if (this.sdump_levels[level]||this.sdump_levels['D_ALL']) {
95                                 this.sdump_last_time = now;
96                                 if (this.debugDump)
97                                         this.debug(message);
98                                 if (this.consoleDump) {
99                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
100                                         this.consoleService.logStringMessage(message);
101                                 }
102                         }
103                 } catch(E) {
104                         dump('Calling sdump but ' + E + '\n');
105                 }
106         },
107
108         'arg_dump' : function (args,dump_these) {
109                 var s = '*>*>*> Called function ';
110                 try {
111                         if (!dump_these)
112                                 dump_these = {};
113                         s += args.callee.toString().match(/\w+/g)[1] + ' : ';
114                         for (var i = 0; i < args.length; i++)
115                                 s += typeof(args[i]) + ' ';
116                         s += '\n';
117                         for (var i = 0; i < args.length; i++)
118                                 if (dump_these[i]) {
119
120                                         var arg = args[i];
121                                         //dump('dump_these[i] = ' + dump_these[i] + '  arg = ' + arg + '\n');
122
123                                         if (typeof(dump_these[i])=='string') {
124
125                                                 if (dump_these[i].slice(0,1) == '.') {
126                                                         var cmd = 'arg' + dump_these[i];
127                                                         var result;
128                                                         try {
129                                                                 result = eval( cmd );
130                                                         } catch(E) {
131                                                                 result = cmd + ' ==> ' + E;
132                                                         }
133                                                         s += '\targ #' + i + ': ' + cmd + ' = ' + result;
134                                                 } else {
135                                                         var result;
136                                                         try {
137                                                                 result = eval( dump_these[i] );
138                                                         } catch(E) {
139                                                                 result = dump_these[i] + ' ==> ' + E;
140                                                         }
141                                                         s += '\targ #' + i + ': ' + result;
142                                                 }
143         
144                                         } else {
145                                                 s += '\targ #' + i + ' = ';
146                                                 try {
147                                                         //s += js2JSON( arg );
148                                                         s += arg;
149                                                 } catch(E) {
150                                                         s += arg;
151                                                 }
152                                         }
153         
154                                         s += '\n';
155                                         if (this.arg_dump_full)
156                                                 s += 'Definition: ' + args.callee.toString() + '\n';
157         
158                                 }
159                         return s;
160                 } catch(E) {
161                         return s + '\nDEBUG ME: ' + js2JSON(E) + '\n';
162                 }
163         },
164
165         'handle_error' : function (E,annoy) {
166                 var s = '';
167                 if (instanceOf(E,ex)) {
168                         s += E.err_msg();
169                         //s += '\n\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n';
170                         //s += 'This error was anticipated.\n\n';
171                         //s += js2JSON(E).substr(0,200) + '...\n\n';
172                         if (snd_bad) snd_bad();
173                 } else {
174                         s += '\n\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n';
175                         s += 'This is a bug that we will fix later.\n\n';
176                         try {
177                                 s += js2JSON(E).substr(0,1024) + '\n\n';
178                         } catch(E2) {
179                                 try {
180                                         s += E.substr(0,1024) + '\n\n';
181                                 } catch(E3) {
182                                         s += E + '\n\n';
183                                 }
184                         }
185                         if (snd_really_bad) snd_really_bad();
186                 }
187                 sdump('D_ERROR',s);
188                 if (annoy)
189                         this.s_alert(s);
190                 else
191                         alert(s);
192         },
193
194         's_alert' : function (s) { alert(s); }
195 }       
196
197 dump('exiting util/error.js\n');