UNPKG

4.79 kBJavaScriptView Raw
1/*!
2 * Copyright (c) 2017-2018 by The Funfix Project Developers.
3 * Some rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * A composite error represents a list of errors that were caught
19 * while executing logic which delays re-throwing of errors.
20 */
21export class CompositeError extends Error {
22 constructor(errors) {
23 let reasons = "";
24 for (const e of errors.slice(0, 2)) {
25 let message = "";
26 if (e instanceof Error) {
27 message = `${e.name}(${e.message})`;
28 }
29 else {
30 message = `${e}`;
31 }
32 reasons += ", " + message;
33 }
34 reasons = reasons.slice(2);
35 if (errors.length > 2)
36 reasons = reasons + ", ...";
37 super(reasons);
38 this.name = "CompositeError";
39 this.errorsRef = errors;
40 // Workaround to make `instanceof` work in ES5
41 const self = this;
42 self.constructor = CompositeError;
43 self.__proto__ = CompositeError.prototype;
44 }
45 /**
46 * Returns the full list of caught errors.
47 */
48 errors() { return this.errorsRef.slice(); }
49}
50/**
51 * A dummy error that can be used for testing purposes.
52 */
53export class DummyError extends Error {
54 constructor(message) {
55 super(message);
56 this.name = "DummyError";
57 // Workaround to make `instanceof` work in ES5
58 const self = this;
59 self.constructor = DummyError;
60 self.__proto__ = DummyError.prototype;
61 }
62}
63/**
64 * Thrown by various accessor methods or partial functions to indicate
65 * that the element being requested does not exist.
66 */
67export class NoSuchElementError extends Error {
68 constructor(message) {
69 super(message);
70 this.name = "NoSuchElementError";
71 // Workaround to make `instanceof` work in ES5
72 const self = this;
73 self.constructor = NoSuchElementError;
74 self.__proto__ = NoSuchElementError.prototype;
75 }
76}
77/**
78 * Error throw in class constructors by implementations that
79 * are sealed or final.
80 */
81export class IllegalInheritanceError extends Error {
82 constructor(message) {
83 super(message);
84 this.name = "IllegalInheritanceError";
85 // Workaround to make `instanceof` work in ES5
86 const self = this;
87 self.constructor = IllegalInheritanceError;
88 self.__proto__ = IllegalInheritanceError.prototype;
89 }
90}
91/**
92 * Signals that a function has been invoked at an illegal
93 * or inappropriate time.
94 *
95 * In other words, environment or application is not in an
96 * appropriate state for the requested operation.
97 */
98export class IllegalStateError extends Error {
99 constructor(message) {
100 super(message);
101 this.name = "IllegalStateError";
102 // Workaround to make `instanceof` work in ES5
103 const self = this;
104 self.constructor = IllegalStateError;
105 self.__proto__ = IllegalStateError.prototype;
106 }
107}
108/**
109 * Signals that a function has been invoked with illegal
110 * arguments.
111 */
112export class IllegalArgumentError extends Error {
113 constructor(message) {
114 super(message);
115 this.name = "IllegalArgumentError";
116 // Workaround to make `instanceof` work in ES5
117 const self = this;
118 self.constructor = IllegalArgumentError;
119 self.__proto__ = IllegalArgumentError.prototype;
120 }
121}
122/**
123 * Signals that a function or a method is missing an implementation,
124 * which should be provided in the future.
125 */
126export class NotImplementedError extends Error {
127 constructor(message) {
128 super(message);
129 this.name = "NotImplementedError";
130 // Workaround to make `instanceof` work in ES5
131 const self = this;
132 self.constructor = NotImplementedError;
133 self.__proto__ = NotImplementedError.prototype;
134 }
135}
136/**
137 * Signals that completion of a procedure took longer than anticipated.
138 */
139export class TimeoutError extends Error {
140 constructor(message) {
141 super(message);
142 this.name = "TimeoutError";
143 // Workaround to make `instanceof` work in ES5
144 const self = this;
145 self.constructor = TimeoutError;
146 self.__proto__ = TimeoutError.prototype;
147 }
148}
149//# sourceMappingURL=errors.js.map
\No newline at end of file