1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.logErrorMessage = exports.logError = exports.ToolError = void 0;
|
7 | const graphql_1 = require("graphql");
|
8 | const path_1 = __importDefault(require("path"));
|
9 | class ToolError extends Error {
|
10 | constructor(message) {
|
11 | super(message);
|
12 | this.name = "ToolError";
|
13 | this.message = message;
|
14 | }
|
15 | }
|
16 | exports.ToolError = ToolError;
|
17 | const isRunningFromXcodeScript = process.env.XCODE_VERSION_ACTUAL;
|
18 | function 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 | }
|
37 | exports.logError = logError;
|
38 | function 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 | }
|
57 | exports.logErrorMessage = logErrorMessage;
|
58 |
|
\ | No newline at end of file |