1 dump('entering util/error.js\n');
3 if (typeof util == 'undefined') util = {};
4 util.error = function () {
7 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
8 this.consoleService = Components.classes['@mozilla.org/consoleservice;1']
9 .getService(Components.interfaces.nsIConsoleService);
11 this.consoleDump = false;
12 dump('util.error constructor: ' + E + '\n');
15 this.sdump_last_time = new Date();
22 util.error.prototype = {
27 'arg_dump_full' : false,
29 'debug' : function(e){
30 dump('-----------------------------------------\n'
31 + e + '\n-----------------------------------------\n' );
36 'D_NONE' : false, 'D_ALL' : false, 'D_ERROR' : true, 'D_DEBUG' : true, 'D_TRACE' : true,
37 'D_TRACE_ENTER' : false, 'D_TRACE_EXIT' : false, 'D_TIMEOUT' : false, 'D_FILTER' : false,
38 'D_CONSTRUCTOR' : false, 'D_FIREFOX' : false, 'D_LEGACY' : false,
40 'D_CLAM' : false, 'D_PAGED_TREE' : false, 'D_GRID_LIST' : false, 'D_HTML_TABLE' : false,
43 'D_AUTH' : true, 'D_OPAC' : true, 'D_CAT' : false,
45 'D_PATRON_SEARCH' : false, 'D_PATRON_SEARCH_FORM' : false, 'D_PATRON_SEARCH_RESULTS' : false,
47 'D_PATRON_DISPLAY' : false, 'D_PATRON_DISPLAY_STATUS' : false, 'D_PATRON_DISPLAY_CONTACT' : false,
49 'D_PATRON_ITEMS' : false, 'D_PATRON_CHECKOUT_ITEMS' : false, 'D_PATRON_HOLDS' : false,
50 'D_PATRON_BILLS' : false, 'D_PATRON_EDIT' : false,
52 'D_CHECKIN' : false, 'D_CHECKIN_ITEMS' : false,
54 'D_HOLD_CAPTURE' : false, 'D_HOLD_CAPTURE_ITEMS' : false,
56 'D_PATRON_UTILS' : false, 'D_CIRC_UTILS' : false,
58 'D_FILE' : true, 'D_EXPLODE' : false, 'D_FM_UTILS' : false, 'D_PRINT' : false, 'D_SES' : true,
59 'D_SES_FUNC' : false, 'D_SES_RESULT' : true, 'D_SPAWN' : false, 'D_STRING' : false,
60 'D_UTIL' : false, 'D_WIN' : true, 'D_WIDGETS' : false
63 'filter_console_init' : function (p) {
64 this.sdump('D_FILTER',this.arg_dump(arguments,{0:true}));
66 var filterConsoleListener = {
67 observe: function( msg ) {
74 QueryInterface: function (iid) {
75 if (!iid.equals(Components.interfaces.nsIConsoleListener) &&
76 !iid.equals(Components.interfaces.nsISupports)) {
77 throw Components.results.NS_ERROR_NO_INTERFACE;
83 this.consoleService.registerListener(filterConsoleListener);
88 this.sdump('D_TRACE_EXIT',this.arg_dump(arguments));
91 'sdump' : function (level,msg) {
94 var message = now.valueOf() + '\tdelta = ' + (now.valueOf() - this.sdump_last_time.valueOf()) + '\t' + level + '\n' + msg;
95 if (this.sdump_levels['D_NONE']) return null;
96 if (this.sdump_levels[level]||this.sdump_levels['D_ALL']) {
97 this.sdump_last_time = now;
100 if (this.consoleDump) {
101 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
102 this.consoleService.logStringMessage(message);
106 dump('Calling sdump but ' + E + '\n');
110 'arg_dump' : function (args,dump_these) {
111 var s = '*>*>*> Called function ';
115 s += args.callee.toString().match(/\w+/g)[1] + ' : ';
116 for (var i = 0; i < args.length; i++)
117 s += typeof(args[i]) + ' ';
119 for (var i = 0; i < args.length; i++)
123 //dump('dump_these[i] = ' + dump_these[i] + ' arg = ' + arg + '\n');
125 if (typeof(dump_these[i])=='string') {
127 if (dump_these[i].slice(0,1) == '.') {
128 var cmd = 'arg' + dump_these[i];
131 result = eval( cmd );
133 result = cmd + ' ==> ' + E;
135 s += '\targ #' + i + ': ' + cmd + ' = ' + result;
139 result = eval( dump_these[i] );
141 result = dump_these[i] + ' ==> ' + E;
143 s += '\targ #' + i + ': ' + result;
147 s += '\targ #' + i + ' = ';
149 //s += js2JSON( arg );
157 if (this.arg_dump_full)
158 s += 'Definition: ' + args.callee.toString() + '\n';
163 return s + '\nDEBUG ME: ' + js2JSON(E) + '\n';
167 'handle_error' : function (E,annoy) {
169 if (instanceOf(E,ex)) {
171 //s += '\n\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n';
172 //s += 'This error was anticipated.\n\n';
173 //s += js2JSON(E).substr(0,200) + '...\n\n';
174 if (snd_bad) snd_bad();
176 s += '\n\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n';
177 s += 'This is a bug that we will fix later.\n\n';
179 s += js2JSON(E).substr(0,1024) + '\n\n';
182 s += E.substr(0,1024) + '\n\n';
187 if (snd_really_bad) snd_really_bad();
196 's_alert' : function (s) { alert(s); },
198 'get_ilsevent' : function(status) {
199 JSAN.use('OpenILS.data');
200 this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
201 return this.OpenILS.data.entities['ilsevent.'+status];
204 'yns_alert' : function (s,title,b1,b2,b3,c) {
207 s = Message to display
208 title = Text in Title Bar
209 b1 = Text for button 1
210 b2 = Text for button 2
211 b3 = Text for button 3
212 c = Text for confirmation checkbox. null for no confirm
215 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
217 // get a reference to the prompt service component.
218 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
219 .getService(Components.interfaces.nsIPromptService);
221 // set the buttons that will appear on the dialog. It should be
222 // a set of constants multiplied by button position constants. In this case,
223 // three buttons appear, Save, Cancel and a custom button.
224 //var flags=promptService.BUTTON_TITLE_OK * promptService.BUTTON_POS_0 +
225 // promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1 +
226 // promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2;
227 var flags = promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
228 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 +
229 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2;
231 // display the dialog box. The flags set above are passed
232 // as the fourth argument. The next three arguments are custom labels used for
233 // the buttons, which are used if BUTTON_TITLE_IS_STRING is assigned to a
234 // particular button. The last two arguments are for an optional check box.
236 var rv = promptService.confirmEx(window,title, s, flags, b1, b2, b3, c, check);
237 if (c && !check.value) {
238 return this.yns_alert(s,title,b1,b2,b3,c);
244 dump('exiting util/error.js\n');