Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

report nice error message when dotnet is not installed or not valid #5477

Merged
merged 34 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
81589b3
report nice error message when dotnet is not installed
chunyu3 Jan 3, 2025
57ca9c0
change the diagonosic code
chunyu3 Jan 3, 2025
e68c4d9
Merge branch 'main' of https://github.com/microsoft/typespec into Fix…
chunyu3 Jan 3, 2025
176c45f
Merge branch 'main' into Fix5364
chunyu3 Jan 6, 2025
3adef56
Merge branch 'main' of https://github.com/microsoft/typespec into Fix…
chunyu3 Jan 8, 2025
a6d54ca
check dotnet runtime when generate fail
chunyu3 Jan 12, 2025
4dee9a5
use semver to parse and compare version
chunyu3 Jan 12, 2025
80bc6c7
Merge branch 'main' into Fix5364
chunyu3 Jan 13, 2025
1a3e0a2
Update packages/http-client-csharp/emitter/src/lib/lib.ts
chunyu3 Jan 15, 2025
35adcaa
Update packages/http-client-csharp/emitter/src/constants.ts
chunyu3 Jan 15, 2025
e9c0ed2
Update packages/http-client-csharp/emitter/src/emitter.ts
chunyu3 Jan 15, 2025
a477162
Update packages/http-client-csharp/emitter/src/lib/lib.ts
chunyu3 Jan 15, 2025
10cd636
Update packages/http-client-csharp/emitter/src/emitter.ts
chunyu3 Jan 15, 2025
6127a1b
change text
chunyu3 Jan 15, 2025
caedb3f
Update packages/http-client-csharp/emitter/src/emitter.ts
chunyu3 Jan 15, 2025
0942fdb
Merge branch 'main' into Fix5364
chunyu3 Jan 15, 2025
e34ce6f
update comment
chunyu3 Jan 15, 2025
e5c7d12
Merge branch 'Fix5364' of https://github.com/chunyu3/typespec into Fi…
chunyu3 Jan 15, 2025
75ef4ef
update the dotnet download url
chunyu3 Jan 16, 2025
8934ce3
use dotnet --version to check dotnet sdk
chunyu3 Jan 17, 2025
eee758f
Merge branch 'main' into Fix5364
chunyu3 Jan 17, 2025
f45887f
compare as number
chunyu3 Jan 17, 2025
f6b3410
remove extra quote in error message
chunyu3 Jan 17, 2025
8b0bb82
add Unit test for validateDotNetSDK
chunyu3 Jan 17, 2025
0fff783
Merge branch 'main' into Fix5364
chunyu3 Jan 17, 2025
81a4380
Update packages/http-client-csharp/emitter/src/lib/lib.ts
chunyu3 Jan 18, 2025
3694213
typo
chunyu3 Jan 20, 2025
e87f80f
mock dotnet not installed scenario
chunyu3 Jan 20, 2025
bca3546
Update packages/http-client-csharp/emitter/src/emitter.ts
chunyu3 Jan 20, 2025
057cece
format
chunyu3 Jan 20, 2025
4650160
add UT for different dotnet sdk installation scenarios with mock
chunyu3 Jan 20, 2025
b4eb6df
simple mock
chunyu3 Jan 20, 2025
2c9ab1f
Merge branch 'main' into Fix5364
chunyu3 Jan 20, 2025
1729cfa
Merge branch 'main' into Fix5364
chunyu3 Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 36 additions & 19 deletions packages/http-client-csharp/emitter/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getDirectoryPath,
joinPaths,
logDiagnostics,
NoTarget,
chunyu3 marked this conversation as resolved.
Show resolved Hide resolved
Program,
resolvePath,
} from "@typespec/compiler";
Expand All @@ -18,6 +19,7 @@ import { dirname } from "path";
import { fileURLToPath } from "url";
import { configurationFileName, tspOutputFileName } from "./constants.js";
import { createModel } from "./lib/client-model-builder.js";
import { reportDiagnostic } from "./lib/lib.js";
import { LoggerLevel } from "./lib/log-level.js";
import { Logger } from "./lib/logger.js";
import { NetEmitterOptions, resolveOptions, resolveOutputFolder } from "./options.js";
Expand Down Expand Up @@ -150,25 +152,40 @@ export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
const command = `dotnet --roll-forward Major ${generatorPath} ${outputFolder} -p ${options["plugin-name"]}${constructCommandArg(newProjectOption)}${constructCommandArg(existingProjectOption)}${constructCommandArg(debugFlag)}`;
Logger.getInstance().info(command);

const result = await execAsync(
"dotnet",
[
"--roll-forward",
"Major",
generatorPath,
outputFolder,
"-p",
options["plugin-name"],
newProjectOption,
existingProjectOption,
debugFlag,
],
{ stdio: "inherit" },
);
if (result.exitCode !== 0) {
if (result.stderr) Logger.getInstance().error(result.stderr);
if (result.stdout) Logger.getInstance().verbose(result.stdout);
throw new Error(`Failed to generate SDK. Exit code: ${result.exitCode}`);
try {
const result = await execAsync(
"dotnet",
[
"--roll-forward",
"Major",
generatorPath,
outputFolder,
"-p",
options["plugin-name"],
newProjectOption,
existingProjectOption,
debugFlag,
],
{ stdio: "inherit" },
);
if (result.exitCode !== 0) {
if (result.stderr) Logger.getInstance().error(result.stderr);
if (result.stdout) Logger.getInstance().verbose(result.stdout);
throw new Error(`Failed to generate SDK. Exit code: ${result.exitCode}`);
}
} catch (error: any) {
if (error && "code" in (error as {}) && error["code"] === "ENOENT") {
chunyu3 marked this conversation as resolved.
Show resolved Hide resolved
reportDiagnostic(sdkContext.program, {
code: "dependency-runtime-missing",
chunyu3 marked this conversation as resolved.
Show resolved Hide resolved
format: {
dotnetMajorVersion: "8",
downloadUrl: "https://dotnet.microsoft.com/en-us/download",
chunyu3 marked this conversation as resolved.
Show resolved Hide resolved
},
target: NoTarget,
});
} else {
throw new Error(error);
}
}
if (!options["save-inputs"]) {
// delete
Expand Down
6 changes: 6 additions & 0 deletions packages/http-client-csharp/emitter/src/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ const $lib = createTypeSpecLibrary({
default: paramMessage`${"message"}`,
},
},
"dependency-runtime-missing": {
severity: "error",
messages: {
default: paramMessage`Dotnet is not found in PATH. Please install DotNet ${"dotnetMajorVersion"} or above. Dotnet can be downloaded from ${"downloadUrl"}"`,
},
},
},
emitter: {
options: NetEmitterOptionsSchema,
Expand Down
Loading