Skip to content

Commit 8181261

Browse files
authored
[TypeSpec Validation] Ensure "compile" and "format" rules fail if process returns error (#25458)
- Fixes #25453
1 parent 36cf4f3 commit 8181261

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

eng/tools/TypeSpecValidation/src/rules/compile.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,25 @@ export class CompileRule implements Rule {
1313
let errorOutput: string | undefined;
1414

1515
if (await checkFileExists(path.join(folder, "main.tsp"))) {
16-
let [std, err] = await runCmd(`npx --no tsp compile . --warn-as-error`, folder);
17-
stdOutput += std;
18-
if (err == null) {
16+
let [err, stdout, stderr] = await runCmd(`npx --no tsp compile . --warn-as-error`, folder);
17+
if (err) {
1918
success = false;
20-
errorOutput += err;
19+
errorOutput += err.message;
2120
}
21+
stdOutput += stdout;
22+
errorOutput += stderr;
2223
}
2324
if (await checkFileExists(path.join(folder, "client.tsp"))) {
24-
let [std, err] = await runCmd(
25+
let [err, stdout, stderr] = await runCmd(
2526
`npx --no tsp compile client.tsp --no-emit --warn-as-error`,
2627
folder
2728
);
28-
stdOutput += std;
29-
if (err == null) {
29+
if (err) {
3030
success = false;
31-
errorOutput += err;
31+
errorOutput += err.message;
3232
}
33+
stdOutput += stdout;
34+
errorOutput += stderr;
3335
}
3436

3537
return {

eng/tools/TypeSpecValidation/src/rules/format.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ export class FormatRule implements Rule {
88

99
async execute(folder: string): Promise<RuleResult> {
1010
// Format parent folder to include shared files
11-
let [stdOutput, errorOutput] = await runCmd(`npx tsp format ../**/*.tsp`, folder);
1211

13-
let success = errorOutput == null ? false : true;
12+
let [err, stdOutput, errorOutput] = await runCmd(`npx tsp format ../**/*.tsp`, folder);
13+
// Failing on both err and errorOutput because of known bug in tsp format where it returns 0 on failed formatting
14+
// https://github.com/microsoft/typespec/issues/2323
15+
let success = !err && !errorOutput;
1416
return {
1517
success: success,
1618
stdOutput: stdOutput,

eng/tools/TypeSpecValidation/src/rules/npm-prefix.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class NpmPrefixRule implements Rule {
88

99
async execute(folder: string): Promise<RuleResult> {
1010
let expected_npm_prefix = process.cwd();
11-
const actual_npm_prefix = (await runCmd(`npm prefix`, folder))[0].trim();
11+
const actual_npm_prefix = (await runCmd(`npm prefix`, folder))[1].trim();
1212

1313
let success = true;
1414
let stdOutput =

eng/tools/TypeSpecValidation/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export async function runCmd(cmd: string, cwd: string) {
1212
)
1313
)) as any;
1414

15-
return [stdout, stderr + err?.message] as string[];
15+
return [err, stdout, stderr];
1616
}
1717

1818
export async function checkFileExists(file: string) {

0 commit comments

Comments
 (0)