Skip to content

Commit 38c3485

Browse files
committed
Handle file not found
1 parent 1569e6a commit 38c3485

File tree

1 file changed

+59
-45
lines changed

1 file changed

+59
-45
lines changed

generator/cmd/generateall.ts

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ executeSynchronous(async () => {
4545
if (!summaryPath) {
4646
// generate default full path
4747
summaryPath = path.join(constants.specsRepoPath, 'summary.log');
48+
console.log(`Summary path not passed, using default value: ${summaryPath}`);
4849
}
4950

5051
// resolve absolute path
@@ -60,54 +61,67 @@ executeSynchronous(async () => {
6061
const summaryLogger = await getLogger(summaryPath);
6162

6263
for (const basePath of basePaths) {
63-
const readme = await validateAndReturnReadmePath(localPath, basePath);
64-
const namespaces = keys(await getApiVersionsByNamespace(readme));
65-
let filteredAutoGenList = findOrGenerateAutogenEntries(basePath, namespaces)
66-
.filter(x => x.disabledForAutogen !== true);
67-
68-
if (args['readme-files']) {
69-
filteredAutoGenList = filteredAutoGenList.filter(c => {
70-
const readmeFiles = args['readme-files']?.map(x => x.toString());
71-
const r = readmeFiles?.find(f => f.startsWith('specification/' + c.basePath));
72-
if (r) {
73-
c.readmeFile = r;
74-
return true;
75-
}
76-
return false;
77-
});
78-
}
64+
try {
65+
const readme = await validateAndReturnReadmePath(localPath, basePath);
66+
const namespaces = keys(await getApiVersionsByNamespace(readme));
67+
let filteredAutoGenList = findOrGenerateAutogenEntries(basePath, namespaces)
68+
.filter(x => x.disabledForAutogen !== true);
69+
70+
if (args['readme-files']) {
71+
filteredAutoGenList = filteredAutoGenList.filter(c => {
72+
const readmeFiles = args['readme-files']?.map(x => x.toString());
73+
const r = readmeFiles?.find(f => f.startsWith('specification/' + c.basePath));
74+
if (r) {
75+
c.readmeFile = r;
76+
return true;
77+
}
78+
return false;
79+
});
80+
}
7981

80-
await clearAutoGeneratedSchemaRefs(filteredAutoGenList);
81-
82-
for (const autoGenConfig of filteredAutoGenList) {
83-
const pkg = {
84-
path: ['schemas']
85-
} as Package;
86-
try {
87-
const readme = await validateAndReturnReadmePath(localPath, autoGenConfig.readmeFile || autoGenConfig.basePath);
88-
pkg.packageName = getPackageString(readme);
89-
90-
const newConfigs = await generateSchemas(readme, autoGenConfig);
91-
schemaConfigs.push(...newConfigs);
92-
pkg.result = 'succeeded';
93-
} catch(error) {
94-
pkg.packageName = autoGenConfig.basePath;
95-
pkg.result = 'failed';
96-
console.log(chalk.red(`Caught exception processing autogenlist entry ${autoGenConfig.basePath}.`));
97-
console.log(chalk.red(error));
98-
99-
// Use markdown formatting as this summary will be included in the PR description
100-
logOut(summaryLogger,
101-
`<details>
102-
<summary>Failed to generate types for path '${basePath}'</summary>
103-
\`\`\`
104-
${error}
105-
\`\`\`
106-
</details>
107-
`);
82+
await clearAutoGeneratedSchemaRefs(filteredAutoGenList);
83+
84+
for (const autoGenConfig of filteredAutoGenList) {
85+
const pkg = {
86+
path: ['schemas']
87+
} as Package;
88+
try {
89+
const readme = await validateAndReturnReadmePath(localPath, autoGenConfig.readmeFile || autoGenConfig.basePath);
90+
pkg.packageName = getPackageString(readme);
91+
92+
const newConfigs = await generateSchemas(readme, autoGenConfig);
93+
schemaConfigs.push(...newConfigs);
94+
pkg.result = 'succeeded';
95+
} catch(error) {
96+
pkg.packageName = autoGenConfig.basePath;
97+
pkg.result = 'failed';
98+
console.log(chalk.red(`Caught exception processing autogenlist entry ${autoGenConfig.basePath}.`));
99+
console.log(chalk.red(error));
100+
101+
// Use markdown formatting as this summary will be included in the PR description
102+
logOut(summaryLogger,
103+
`<details>
104+
<summary>Failed to generate types for path '${basePath}'</summary>
105+
\`\`\`
106+
${error}
107+
\`\`\`
108+
</details>
109+
`);
110+
}
111+
packages.push(pkg);
108112
}
109-
packages.push(pkg);
113+
} catch (error) {
114+
// Use markdown formatting as this summary will be included in the PR description
115+
logOut(summaryLogger,
116+
`<details>
117+
<summary>Failed to generate types for path '${basePath}'</summary>
118+
\`\`\`
119+
${error}
120+
\`\`\`
121+
</details>
122+
`);
110123
}
124+
111125
}
112126

113127
await saveAutoGeneratedSchemaRefs(flatten(schemaConfigs));

0 commit comments

Comments
 (0)