in src/startApp.ts [61:128]
async function loadEntryPointFile(functionAppDirectory: string): Promise<void> {
const entryPointPattern = worker.app.packageJson.main;
if (entryPointPattern) {
let currentFile: string | undefined = undefined;
try {
const files = await globby(entryPointPattern, { cwd: functionAppDirectory });
if (files.length === 0) {
let message: string = globby.hasMagic(entryPointPattern, { cwd: functionAppDirectory })
? 'Found zero files matching the supplied pattern'
: 'File does not exist';
if (entryPointPattern === 'index.js') {
// This is by far the most common error and typically happens by accident, so we'll give these folks a little more help
message += '. Learn more here: https://aka.ms/AAla7et';
}
throw new AzFuncSystemError(message);
}
for (const file of files) {
currentFile = file;
worker.log({
message: `Loading entry point file "${file}"`,
level: LogLevel.Debug,
logCategory: LogCategory.System,
});
try {
const entryPointFilePath = path.join(functionAppDirectory, file);
worker.app.currentEntryPoint = entryPointFilePath;
await loadScriptFile(entryPointFilePath, worker.app.packageJson);
} finally {
worker.app.currentEntryPoint = undefined;
}
worker.log({
message: `Loaded entry point file "${file}"`,
level: LogLevel.Debug,
logCategory: LogCategory.System,
});
}
} catch (err) {
const error = ensureErrorType(err);
const newMessage = `Worker was unable to load entry point "${currentFile || entryPointPattern}": ${
error.message
}`;
if (shouldBlockOnEntryPointError()) {
trySetErrorMessage(error, newMessage);
error.isAzureFunctionsSystemError = true;
// We don't want to throw this error now (during workerInit or funcEnvReload) because technically the worker is fine
// Instead, it will be thrown during functionMetadata or functionLoad response which better indicates that the user's app is the problem
worker.app.blockingAppStartError = error;
// This will ensure the error makes it to the user's app insights
console.error(error.stack);
} else {
// In this case, the error will never block the app
// The most we can do without breaking backwards compatibility is log it as an rpc system log below
}
// Always log as rpc system log, which goes to our internal telemetry
worker.log({
message: newMessage,
level: LogLevel.Error,
logCategory: LogCategory.System,
});
error.loggedOverRpc = true;
}
}
}