This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
fix: add more error info on missing functions folders #1134
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,34 +41,36 @@ export const safeUnlink = async (path: string) => { | |
// filenames within those directories, if at least one of the directories | ||
// exists. If not, an error is thrown. | ||
export const listFunctionsDirectories = async function (srcFolders: string[]) { | ||
const filenamesByDirectory = await Promise.all( | ||
srcFolders.map(async (srcFolder) => { | ||
try { | ||
const filenames = await listFunctionsDirectory(srcFolder) | ||
const filenamesByDirectory = await Promise.allSettled( | ||
srcFolders.map((srcFolder) => listFunctionsDirectory(srcFolder)), | ||
) | ||
const errorMessages: string[] = [] | ||
const validDirectories = filenamesByDirectory | ||
.map((result) => { | ||
if (result.status === 'rejected') { | ||
if (result.reason instanceof Error && (result.reason as NodeJS.ErrnoException).code !== 'ENOENT') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason Error does not contain
danez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw result.reason | ||
} | ||
|
||
return filenames | ||
} catch { | ||
return null | ||
} | ||
}), | ||
) | ||
const validDirectories = filenamesByDirectory.filter(nonNullable) | ||
|
||
return result.value | ||
}) | ||
.filter(nonNullable) | ||
|
||
if (validDirectories.length === 0) { | ||
throw new Error(`Functions folder does not exist: ${srcFolders.join(', ')}`) | ||
throw new Error(`Functions folders do not exist: ${srcFolders.join(', ')} | ||
${errorMessages.join('\n')}`) | ||
danez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return validDirectories.flat() | ||
} | ||
|
||
export const listFunctionsDirectory = async function (srcFolder: string) { | ||
try { | ||
const filenames = await fs.readdir(srcFolder) | ||
const listFunctionsDirectory = async function (srcFolder: string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the export as it is nowhere used outside this file, and also is not a Public API. |
||
const filenames = await fs.readdir(srcFolder) | ||
|
||
return filenames.map((name) => join(srcFolder, name)) | ||
} catch { | ||
throw new Error(`Functions folder does not exist: ${srcFolder}`) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we do not export it we do not need to catch anymore, because the error will be matched in the function above. |
||
return filenames.map((name) => join(srcFolder, name)) | ||
} | ||
|
||
export const resolveFunctionsDirectories = (input: string | string[]) => { | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allSettled
is available as of node 12.9.0