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,
38 'D_TRACE_ENTER' : false, 'D_TRACE_EXIT' : false, 'D_TIMEOUT' : false, 'D_FILTER' : false,
39 'D_CONSTRUCTOR' : false, 'D_FIREFOX' : false, 'D_LEGACY' : false, 'D_DATA' : false,
41 'D_CLAM' : false, 'D_PAGED_TREE' : false, 'D_GRID_LIST' : false, 'D_HTML_TABLE' : false,
42 'D_TAB' : false, 'D_LIST' : false,
44 'D_AUTH' : true, 'D_OPAC' : true, 'D_CAT' : true,
46 'D_PATRON_SEARCH' : false, 'D_PATRON_SEARCH_FORM' : false, 'D_PATRON_SEARCH_RESULTS' : false,
48 'D_PATRON_DISPLAY' : false, 'D_PATRON_DISPLAY_STATUS' : false, 'D_PATRON_DISPLAY_CONTACT' : false,
50 'D_PATRON_ITEMS' : false, 'D_PATRON_CHECKOUT_ITEMS' : false, 'D_PATRON_HOLDS' : false,
51 'D_PATRON_BILLS' : false, 'D_PATRON_EDIT' : false,
53 'D_CHECKIN' : false, 'D_CHECKIN_ITEMS' : false,
55 'D_HOLD_CAPTURE' : false, 'D_HOLD_CAPTURE_ITEMS' : false,
57 'D_PATRON_UTILS' : false, 'D_CIRC_UTILS' : false,
59 'D_FILE' : false, 'D_EXPLODE' : false, 'D_FM_UTILS' : false, 'D_PRINT' : false, 'D_SES' : true,
60 'D_SES_FUNC' : false, 'D_SES_RESULT' : true, 'D_SPAWN' : false, 'D_STRING' : false,
61 'D_UTIL' : false, 'D_WIN' : false, 'D_WIDGETS' : false
64 'filter_console_init' : function (p) {
65 this.sdump('D_FILTER',this.arg_dump(arguments,{0:true}));
67 var filterConsoleListener = {
68 observe: function( msg ) {
75 QueryInterface: function (iid) {
76 if (!iid.equals(Components.interfaces.nsIConsoleListener) &&
77 !iid.equals(Components.interfaces.nsISupports)) {
78 throw Components.results.NS_ERROR_NO_INTERFACE;
84 this.consoleService.registerListener(filterConsoleListener);
89 this.sdump('D_TRACE_EXIT',this.arg_dump(arguments));
92 'sdump' : function (level,msg) {
95 var message = now.valueOf() + '\tdelta = ' + (now.valueOf() - this.sdump_last_time.valueOf()) + '\t' + level + '\n' + msg;
96 if (this.sdump_levels['D_NONE']) return null;
97 if (this.sdump_levels[level]||this.sdump_levels['D_ALL']) {
98 this.sdump_last_time = now;
101 if (this.consoleDump) {
102 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
103 this.consoleService.logStringMessage(message);
107 dump('Calling sdump but ' + E + '\n');
111 'arg_dump' : function (args,dump_these) {
112 var s = '*>*>*> Called function ';
116 s += args.callee.toString().match(/\w+/g)[1] + ' : ';
117 for (var i = 0; i < args.length; i++)
118 s += typeof(args[i]) + ' ';
120 for (var i = 0; i < args.length; i++)
124 //dump('dump_these[i] = ' + dump_these[i] + ' arg = ' + arg + '\n');
126 if (typeof(dump_these[i])=='string') {
128 if (dump_these[i].slice(0,1) == '.') {
129 var cmd = 'arg' + dump_these[i];
132 result = eval( cmd );
134 result = cmd + ' ==> ' + E;
136 s += '\targ #' + i + ': ' + cmd + ' = ' + result;
140 result = eval( dump_these[i] );
142 result = dump_these[i] + ' ==> ' + E;
144 s += '\targ #' + i + ': ' + result;
148 s += '\targ #' + i + ' = ';
150 //s += js2JSON( arg );
158 if (this.arg_dump_full)
159 s += 'Definition: ' + args.callee.toString() + '\n';
164 return s + '\nDEBUG ME: ' + js2JSON(E) + '\n';
168 'handle_error' : function (E,annoy) {
170 if (instanceOf(E,ex)) {
172 //s += '\n\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n';
173 //s += 'This error was anticipated.\n\n';
174 //s += js2JSON(E).substr(0,200) + '...\n\n';
175 if (snd_bad) snd_bad();
177 s += '\n\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n';
178 s += 'This is a bug that we will fix later.\n\n';
180 s += js2JSON(E).substr(0,1024) + '\n\n';
183 s += E.substr(0,1024) + '\n\n';
188 if (snd_really_bad) snd_really_bad();
197 's_alert' : function (s) { alert(s); },
199 'get_ilsevent' : function(status) {
200 JSAN.use('OpenILS.data');
201 this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
202 return this.OpenILS.data.entities['ilsevent.'+status];
205 'yns_alert' : function (s,title,b1,b2,b3,c) {
208 s = Message to display
209 title = Text in Title Bar
210 b1 = Text for button 1
211 b2 = Text for button 2
212 b3 = Text for button 3
213 c = Text for confirmation checkbox. null for no confirm
216 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
218 // get a reference to the prompt service component.
219 var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
220 .getService(Components.interfaces.nsIPromptService);
222 // set the buttons that will appear on the dialog. It should be
223 // a set of constants multiplied by button position constants. In this case,
224 // three buttons appear, Save, Cancel and a custom button.
225 //var flags=promptService.BUTTON_TITLE_OK * promptService.BUTTON_POS_0 +
226 // promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1 +
227 // promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2;
228 var flags = promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
229 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 +
230 promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_2;
232 // display the dialog box. The flags set above are passed
233 // as the fourth argument. The next three arguments are custom labels used for
234 // the buttons, which are used if BUTTON_TITLE_IS_STRING is assigned to a
235 // particular button. The last two arguments are for an optional check box.
237 var rv = promptService.confirmEx(window,title, s, flags, b1, b2, b3, c, check);
238 if (c && !check.value) {
239 return this.yns_alert(s,title,b1,b2,b3,c);
245 dump('exiting util/error.js\n');