Skip to content

Commit

Permalink
Merge pull request #2086 from Azure/jcotillo/handle_file_not_found
Browse files Browse the repository at this point in the history
Handle file not found failure, added log to show default summary log path
  • Loading branch information
jorgecotillo authored Dec 8, 2021
2 parents 4673365 + 48061bb commit bf9feb8
Showing 1 changed file with 60 additions and 45 deletions.
105 changes: 60 additions & 45 deletions generator/cmd/generateall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ executeSynchronous(async () => {
// using 'localPath' here because at this point it is guaranteed that the folder got created (when cloneAndGenerateBasePaths function is invoked)
// or is an existing path
summaryPath = path.join(localPath, 'summary.log');
console.log(`Summary path not passed, using default value: ${summaryPath}`);
}

// resolve absolute path
Expand All @@ -62,54 +63,68 @@ executeSynchronous(async () => {
const summaryLogger = await getLogger(summaryPath);

for (const basePath of basePaths) {
const readme = await validateAndReturnReadmePath(localPath, basePath);
const namespaces = keys(await getApiVersionsByNamespace(readme));
let filteredAutoGenList = findOrGenerateAutogenEntries(basePath, namespaces)
.filter(x => x.disabledForAutogen !== true);

if (args['readme-files']) {
filteredAutoGenList = filteredAutoGenList.filter(c => {
const readmeFiles = args['readme-files']?.map(x => x.toString());
const r = readmeFiles?.find(f => f.startsWith('specification/' + c.basePath));
if (r) {
c.readmeFile = r;
return true;
}
return false;
});
}
try {
const readme = await validateAndReturnReadmePath(localPath, basePath);
const namespaces = keys(await getApiVersionsByNamespace(readme));
let filteredAutoGenList = findOrGenerateAutogenEntries(basePath, namespaces)
.filter(x => x.disabledForAutogen !== true);

if (args['readme-files']) {
filteredAutoGenList = filteredAutoGenList.filter(c => {
const readmeFiles = args['readme-files']?.map(x => x.toString());
const r = readmeFiles?.find(f => f.startsWith('specification/' + c.basePath));
if (r) {
c.readmeFile = r;
return true;
}
return false;
});
}

await clearAutoGeneratedSchemaRefs(filteredAutoGenList);

for (const autoGenConfig of filteredAutoGenList) {
const pkg = {
path: ['schemas']
} as Package;
try {
const readme = await validateAndReturnReadmePath(localPath, autoGenConfig.readmeFile || autoGenConfig.basePath);
pkg.packageName = getPackageString(readme);

const newConfigs = await generateSchemas(readme, autoGenConfig);
schemaConfigs.push(...newConfigs);
pkg.result = 'succeeded';
} catch(error) {
pkg.packageName = autoGenConfig.basePath;
pkg.result = 'failed';
console.log(chalk.red(`Caught exception processing autogenlist entry ${autoGenConfig.basePath}.`));
console.log(chalk.red(error));

// Use markdown formatting as this summary will be included in the PR description
logOut(summaryLogger,
`<details>
<summary>Failed to generate types for path '${basePath}'</summary>
\`\`\`
${error}
\`\`\`
</details>
`);
await clearAutoGeneratedSchemaRefs(filteredAutoGenList);

for (const autoGenConfig of filteredAutoGenList) {
const pkg = {
path: ['schemas']
} as Package;
try {
const readme = await validateAndReturnReadmePath(localPath, autoGenConfig.readmeFile || autoGenConfig.basePath);
pkg.packageName = getPackageString(readme);

const newConfigs = await generateSchemas(readme, autoGenConfig);
schemaConfigs.push(...newConfigs);
pkg.result = 'succeeded';
} catch(error) {
pkg.packageName = autoGenConfig.basePath;
pkg.result = 'failed';
console.log(chalk.red(`Caught exception processing autogenlist entry ${autoGenConfig.basePath}.`));
console.log(chalk.red(error));

// Use markdown formatting as this summary will be included in the PR description
logOut(summaryLogger,
`<details>
<summary>Failed to generate types for path '${autoGenConfig.basePath}' and namespace '${autoGenConfig.namespace}'</summary>
\`\`\`
${error}
\`\`\`
</details>
`);
}
packages.push(pkg);
}
packages.push(pkg);
} catch (error) {
// Use markdown formatting as this summary will be included in the PR description
// This error usually indicates that a file has not been found (readme)
logOut(summaryLogger,
`<details>
<summary>Failed to generate types for path '${basePath}' probably due to readme not found or due to any other file not found exception.</summary>
\`\`\`
${error}
\`\`\`
</details>
`);
}

}

await saveAutoGeneratedSchemaRefs(flatten(schemaConfigs));
Expand Down

0 comments on commit bf9feb8

Please sign in to comment.