diff --git a/eng/tools/spec-gen-sdk-runner/src/index.ts b/eng/tools/spec-gen-sdk-runner/src/index.ts index f770708804b0..183f8e4c1b60 100644 --- a/eng/tools/spec-gen-sdk-runner/src/index.ts +++ b/eng/tools/spec-gen-sdk-runner/src/index.ts @@ -22,12 +22,18 @@ export async function main() { mkdirSync(logFolder, { recursive: true }); } let statusCode: number; - if (batchType) { - statusCode = await generateSdkForBatchSpecs(batchType); - } else if (pullRequestNumber) { - statusCode = await generateSdkForSpecPr(); - } else { - statusCode = await generateSdkForSingleSpec(); + try { + if (batchType) { + statusCode = await generateSdkForBatchSpecs(batchType); + } else if (pullRequestNumber) { + statusCode = await generateSdkForSpecPr(); + } else { + statusCode = await generateSdkForSingleSpec(); + } + } catch (error) { + console.error("Unhandled exception in spec-gen-sdk-runner:", error); + console.log("##vso[task.complete result=Failed;]"); + exit(1); } if (statusCode !== 0) { console.log("##vso[task.complete result=Failed;]"); diff --git a/eng/tools/spec-gen-sdk-runner/src/utils.ts b/eng/tools/spec-gen-sdk-runner/src/utils.ts index 1a8705926156..d32b77036846 100644 --- a/eng/tools/spec-gen-sdk-runner/src/utils.ts +++ b/eng/tools/spec-gen-sdk-runner/src/utils.ts @@ -249,13 +249,8 @@ export function findAllParentsWithFile( results.push(currentPath); } } catch (error) { - logMessage( - `Error reading directory: ${currentPath}. ` + - `If this is a transient IO error, please re-run the pipeline. ` + - `Error details: ${inspect(error)}`, - LogLevel.Error, - ); - throw error; + logMessage(`Error reading directory: ${currentPath} with ${inspect(error)}`, LogLevel.Warn); + return results; } currentPath = path.dirname(currentPath); // Check if we've reached the root of the path (stopAtFolder) or diff --git a/eng/tools/spec-gen-sdk-runner/test/utils/findAllParentsWithFile.test.ts b/eng/tools/spec-gen-sdk-runner/test/utils/findAllParentsWithFile.test.ts index 08cce1341382..3af123b3d251 100644 --- a/eng/tools/spec-gen-sdk-runner/test/utils/findAllParentsWithFile.test.ts +++ b/eng/tools/spec-gen-sdk-runner/test/utils/findAllParentsWithFile.test.ts @@ -66,10 +66,13 @@ describe("findAllParentsWithFile", () => { ); }); - test("throws error when directory does not exist", () => { - expect(() => - findAllParentsWithFile("specification/nonexistent/path", typespecProjectRegex, repoRoot), - ).toThrow(/ENOENT/); + test("returns empty array when directory does not exist", () => { + const result = findAllParentsWithFile( + "specification/nonexistent/path", + typespecProjectRegex, + repoRoot, + ); + expect(result).toHaveLength(0); }); test("stops at specified boundary and finds files before it", () => {