Answer the question
In order to leave comments, you need to log in
How to make NodeJS output file name and line number on error?
Here is a simple script. Which clearly demonstrates the problem with readFile. If we read a non-existent file, then an error will be generated. But in which file the error occurred and on which line - We will not know.
In such a simple script, it is not difficult to find an error. But if readFile is hidden it will be deep. In some third party module? Or even worse in several times nested module? Then the error will be harder to find.
How to make a node output file name and line number?
Answer the question
In order to leave comments, you need to log in
// Предварительная версия обработки ошибок функции Fs.readFile().
let configFileData;
try {
configFileData = await readFile(configFilePath, {encoding: 'utf8'});
} catch(e) {
Error.captureStackTrace(e);
throw e;
}
No way.
This information is simply not in the error returned by fs.readFile .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question