summaryrefslogtreecommitdiffstats
path: root/services/sync/tps/extensions/mozmill/resource/modules/errors.js
blob: 58d1a918a2da8b72da99fc7afdd59de7305aaa4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, you can obtain one at http://mozilla.org/MPL/2.0/. */

var EXPORTED_SYMBOLS = ['BaseError',
                        'ApplicationQuitError',
                        'AssertionError',
                        'TimeoutError'];


/**
 * Creates a new instance of a base error
 *
 * @class Represents the base for custom errors
 * @param {string} [aMessage=Error().message]
 *        The error message to show
 * @param {string} [aFileName=Error().fileName]
 *        The file name where the error has been raised
 * @param {string} [aLineNumber=Error().lineNumber]
 *        The line number of the file where the error has been raised
 * @param {string} [aFunctionName=undefined]
 *        The function name in which the error has been raised
 */
function BaseError(aMessage, aFileName, aLineNumber, aFunctionName) {
  this.name = this.constructor.name;

  var err = new Error();
  if (err.stack) {
    this.stack = err.stack;
  }

  this.message = aMessage || err.message;
  this.fileName = aFileName || err.fileName;
  this.lineNumber = aLineNumber || err.lineNumber;
  this.functionName = aFunctionName;
}


/**
 * Creates a new instance of an application quit error used by Mozmill to
 * indicate that the application is going to shutdown
 *
 * @class Represents an error object thrown when the application is going to shutdown
 * @param {string} [aMessage=Error().message]
 *        The error message to show
 * @param {string} [aFileName=Error().fileName]
 *        The file name where the error has been raised
 * @param {string} [aLineNumber=Error().lineNumber]
 *        The line number of the file where the error has been raised
 * @param {string} [aFunctionName=undefined]
 *        The function name in which the error has been raised
 */
function ApplicationQuitError(aMessage, aFileName, aLineNumber, aFunctionName) {
  BaseError.apply(this, arguments);
}

ApplicationQuitError.prototype = Object.create(BaseError.prototype, {
  constructor : { value : ApplicationQuitError }
});


/**
 * Creates a new instance of an assertion error
 *
 * @class Represents an error object thrown by failing assertions
 * @param {string} [aMessage=Error().message]
 *        The error message to show
 * @param {string} [aFileName=Error().fileName]
 *        The file name where the error has been raised
 * @param {string} [aLineNumber=Error().lineNumber]
 *        The line number of the file where the error has been raised
 * @param {string} [aFunctionName=undefined]
 *        The function name in which the error has been raised
 */
function AssertionError(aMessage, aFileName, aLineNumber, aFunctionName) {
  BaseError.apply(this, arguments);
}

AssertionError.prototype = Object.create(BaseError.prototype, {
  constructor : { value : AssertionError }
});

/**
 * Creates a new instance of a timeout error
 *
 * @class Represents an error object thrown by failing assertions
 * @param {string} [aMessage=Error().message]
 *        The error message to show
 * @param {string} [aFileName=Error().fileName]
 *        The file name where the error has been raised
 * @param {string} [aLineNumber=Error().lineNumber]
 *        The line number of the file where the error has been raised
 * @param {string} [aFunctionName=undefined]
 *        The function name in which the error has been raised
 */
function TimeoutError(aMessage, aFileName, aLineNumber, aFunctionName) {
  AssertionError.apply(this, arguments);
}

TimeoutError.prototype = Object.create(AssertionError.prototype, {
  constructor : { value : TimeoutError }
});