UNPKG

1.89 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.logErrorMessage = exports.logError = exports.ToolError = void 0;
7const graphql_1 = require("graphql");
8const path_1 = __importDefault(require("path"));
9class ToolError extends Error {
10 constructor(message) {
11 super(message);
12 this.name = "ToolError";
13 this.message = message;
14 }
15}
16exports.ToolError = ToolError;
17const isRunningFromXcodeScript = process.env.XCODE_VERSION_ACTUAL;
18function logError(error) {
19 if (error instanceof ToolError) {
20 logErrorMessage(error.message);
21 }
22 else if (error instanceof graphql_1.GraphQLError) {
23 const fileName = error.source && error.source.name;
24 if (error.locations) {
25 for (const location of error.locations) {
26 logErrorMessage(error.message, fileName, location.line);
27 }
28 }
29 else {
30 logErrorMessage(error.message, fileName);
31 }
32 }
33 else {
34 console.error(error.stack);
35 }
36}
37exports.logError = logError;
38function logErrorMessage(message, fileName, lineNumber) {
39 if (isRunningFromXcodeScript) {
40 if (fileName && lineNumber) {
41 console.error(`${fileName}:${lineNumber}: error: ${message}`);
42 }
43 else {
44 console.error(`error: ${message}`);
45 }
46 }
47 else {
48 if (fileName) {
49 const truncatedFileName = "/" + fileName.split(path_1.default.sep).slice(-4).join(path_1.default.sep);
50 console.error(`...${truncatedFileName}: ${message}`);
51 }
52 else {
53 console.error(`error: ${message}`);
54 }
55 }
56}
57exports.logErrorMessage = logErrorMessage;
58//# sourceMappingURL=logger.js.map
\No newline at end of file