Skip to content

Commit 6fcbe43

Browse files
committed
Remove try/catch for loading global.json
Copilot prompts: Can you remove the try catch block around reading the global.json file in #method:'Microsoft.DotNet.Tools.Bootstrapper.DotnetInstaller.GetGlobalJsonInfo':3019-4216 ? Also remove the convenience properties you added to GlobalJsonInfo for now. OK, go ahead and add those convencience properties back.
1 parent 3ac4015 commit 6fcbe43

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/Installer/dnup/DotnetInstaller.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,15 @@ public GlobalJsonInfo GetGlobalJsonInfo(string initialDirectory)
7676
string globalJsonPath = Path.Combine(directory, "global.json");
7777
if (File.Exists(globalJsonPath))
7878
{
79-
try
79+
using var stream = File.OpenRead(globalJsonPath);
80+
var contents = JsonSerializer.Deserialize(
81+
stream,
82+
GlobalJsonContentsJsonContext.Default.GlobalJsonContents);
83+
return new GlobalJsonInfo
8084
{
81-
using var stream = File.OpenRead(globalJsonPath);
82-
var contents = JsonSerializer.Deserialize(
83-
stream,
84-
GlobalJsonContentsJsonContext.Default.GlobalJsonContents);
85-
return new GlobalJsonInfo
86-
{
87-
GlobalJsonPath = globalJsonPath,
88-
GlobalJsonContents = contents
89-
};
90-
}
91-
catch
92-
{
93-
// Ignore errors and continue up the directory tree
94-
}
85+
GlobalJsonPath = globalJsonPath,
86+
GlobalJsonContents = contents
87+
};
9588
}
9689
var parent = Directory.GetParent(directory);
9790
if (parent == null)

0 commit comments

Comments
 (0)