UNPKG

2.05 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright 2018 Palantir Technologies, Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19exports.showRuleCrashWarning = exports.showWarningOnce = exports.isError = exports.FatalError = void 0;
20var tslib_1 = require("tslib");
21var shownWarnings = new Set();
22/**
23 * Used to exit the program and display a friendly message without the callstack.
24 */
25var FatalError = /** @class */ (function (_super) {
26 tslib_1.__extends(FatalError, _super);
27 function FatalError(message, innerError) {
28 var _this = _super.call(this, message) || this;
29 _this.message = message;
30 _this.innerError = innerError;
31 _this.name = FatalError.NAME;
32 // Fix prototype chain for target ES5
33 Object.setPrototypeOf(_this, FatalError.prototype);
34 return _this;
35 }
36 FatalError.NAME = "FatalError";
37 return FatalError;
38}(Error));
39exports.FatalError = FatalError;
40function isError(possibleError) {
41 return possibleError != undefined && possibleError.message !== undefined;
42}
43exports.isError = isError;
44function showWarningOnce(message) {
45 if (!shownWarnings.has(message)) {
46 console.warn(message);
47 shownWarnings.add(message);
48 }
49}
50exports.showWarningOnce = showWarningOnce;
51function showRuleCrashWarning(message, ruleName, fileName) {
52 console.warn("The '" + ruleName + "' rule threw an error in '" + fileName + "':\n" + message);
53}
54exports.showRuleCrashWarning = showRuleCrashWarning;