Skip to content

Commit 0762541

Browse files
committed
Include file paths in warnings as well
Log warnings together with errors
1 parent eaebafb commit 0762541

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

test-app/build-tools/jsparser/helpers/logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function (setting) {
2424

2525
if (setting.disable) {
2626
for (var prop in appLog) {
27-
if(prop != 'error' || !setting.showErrorLogs) {
27+
if((prop != 'error' && prop != 'warn') || !setting.showErrorsAndWarnings) {
2828
appLog[prop] = function () { };
2929
}
3030
}

test-app/build-tools/jsparser/js_parser.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
const enableLogger = (process.env.AST_PARSER_ENABLE_LOGGING && process.env.AST_PARSER_ENABLE_LOGGING.trim() === "true")
99
|| (process.argv && process.argv.includes("enableVerboseLogging"));
1010

11-
var showErrorLogs = !enableLogger && (process.argv && process.argv.includes("enableErrorLogging"))
11+
const showErrorsAndWarnings = !enableLogger && (process.argv && process.argv.includes("enableErrorLogging"));
1212

1313
loggingSettings = {
1414
"logPath": require("path").join(__dirname, "logs", "i.txt"),
1515
"strategy": "console",
1616
"APP_NAME": "ast_parser",
17-
"showErrorLogs": showErrorLogs,
17+
"showErrorsAndWarnings": showErrorsAndWarnings,
1818
"disable": !enableLogger
1919
};
2020

@@ -70,6 +70,22 @@ function getRelativeToBuildTools(relativePath) {
7070
/////////////// EXECUTE ////////////////
7171
var tsHelpersFilePath = path.join(inputDir, "..", "internal", "ts_helpers.js");
7272

73+
/*
74+
* If there is an exception anywhere down the line it's caught here
75+
* If the error is criticalthe process is exited.
76+
*/
77+
var exceptionHandler = function (path, reason) {
78+
if (reason.errCode && reason.errCode === 1) {
79+
logger.error(`Error processing '${path}': ${reason.message}`);
80+
logger.error("PROCESS EXITING...");
81+
process.stderr.write(reason.message);
82+
process.exit(4);
83+
}
84+
else {
85+
logger.error(`Error processing '${path}:' ` + reason);
86+
}
87+
}
88+
7389
// ENTRY POINT!
7490
readLinesFromFile(inputFilesPath, inputFiles, tsHelpersFilePath)
7591
.then(getFileAst)
@@ -162,8 +178,8 @@ function traverseFiles(filesToTraverse) {
162178
logger.info("Visiting JavaScript file: " + fp);
163179

164180
readFile(fp)
165-
.then(astFromFileContent)
166-
.then(visitAst)
181+
.then(astFromFileContent.bind(null, fp))
182+
.then(visitAst.bind(null, fp))
167183
.then(writeToFile)
168184
.catch(exceptionHandler.bind(null, fp));
169185
}
@@ -177,7 +193,7 @@ var readFile = function (filePath, err) {
177193
return new Promise(function (resolve, reject) {
178194
fs.readFile(filePath, function (err, data) {
179195
if (err) {
180-
logger.warn("+DIDN'T get content of file: " + filePath);
196+
logger.warn(`+DIDN'T get content of file: ${filePath}!`);
181197
return reject(err);
182198
}
183199

@@ -193,10 +209,10 @@ var readFile = function (filePath, err) {
193209
/*
194210
* Get's the AST (https://en.wikipedia.org/wiki/Abstract_syntax_tree) from the file content and passes it down the line.
195211
*/
196-
var astFromFileContent = function (data, err) {
212+
var astFromFileContent = function (path, data, err) {
197213
return new Promise(function (resolve, reject) {
198214
if (err) {
199-
logger.warn("+DIDN'T parse ast from file!");
215+
logger.warn(`+DIDN'T parse ast from file: ${path}!`);
200216
return reject(err);
201217
}
202218

@@ -218,10 +234,10 @@ function onlyUnique(value, index, self) {
218234
* Visist's the passed AST with a given visitor and extracts nativescript speciffic data.
219235
* Passes the extracted bindings data down the line.
220236
*/
221-
var visitAst = function (data, err) {
237+
var visitAst = function (path, data, err) {
222238
return new Promise(function (resolve, reject) {
223239
if (err) {
224-
logger.warn("+DIDN'T visit ast!");
240+
logger.warn(`+DIDN'T visit ast for file: ${path}!`);
225241
return reject(err);
226242
}
227243

@@ -271,20 +287,4 @@ var writeToFile = function (data, err) {
271287
logger.info("No need to generate anything. (UP-TO-DATE)");
272288
}
273289
});
274-
}
275-
276-
/*
277-
* If there is an exception anywhere down the line it's caught here
278-
* If the error is criticalthe process is exited.
279-
*/
280-
var exceptionHandler = function (path, reason) {
281-
if (reason.errCode && reason.errCode === 1) {
282-
logger.error(`Error processing '${path}': ${reason.message}`);
283-
logger.error("PROCESS EXITING...");
284-
process.stderr.write(reason.message);
285-
process.exit(4);
286-
}
287-
else {
288-
logger.error(`Error processing '${path}:' ` + reason);
289-
}
290290
}

0 commit comments

Comments
 (0)