Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 854feef

Browse files
author
William Li
authored
Give a different error to guide use to install via global tools (#9070)
Give a different error to guide use to install via global tools so, if several bundled DotnetTools cannot finish source build on time. The user can use global tools to get it. The original plan that adding a different resolver is hard due to resolver can only find dll that will be used to spawn a process. However, the command constructor will give an error message when resolver find null. By adding a different error when the command name is part of the list, it can achieve the same goal.
1 parent bc83d98 commit 854feef

17 files changed

+238
-1
lines changed

src/Microsoft.DotNet.Cli.Utils/Command.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public class Command : ICommand
2121

2222
private bool _running = false;
2323

24+
private static string[] _knownCommandsAvailableAsDotNetTool = new[] { "dotnet-dev-certs", "dotnet-ef", "dotnet-sql-cache", "dotnet-user-secrets", "dotnet-watch" };
25+
2426
private Command(CommandSpec commandSpec)
2527
{
2628
var psi = new ProcessStartInfo
@@ -102,7 +104,14 @@ public static Command Create(
102104

103105
if (commandSpec == null)
104106
{
105-
throw new CommandUnknownException(commandName);
107+
if (_knownCommandsAvailableAsDotNetTool.Contains(commandName, StringComparer.OrdinalIgnoreCase))
108+
{
109+
throw new CommandAvailableAsDotNetToolException(commandName);
110+
}
111+
else
112+
{
113+
throw new CommandUnknownException(commandName);
114+
}
106115
}
107116

108117
var command = new Command(commandSpec);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
6+
namespace Microsoft.DotNet.Cli.Utils
7+
{
8+
public class CommandAvailableAsDotNetToolException : GracefulException
9+
{
10+
public CommandAvailableAsDotNetToolException(string commandName) : base(GetMessage(commandName))
11+
{
12+
}
13+
14+
public CommandAvailableAsDotNetToolException(string commandName, Exception innerException) : base(
15+
GetMessage(commandName), innerException)
16+
{
17+
}
18+
19+
private static string GetMessage(string commandName)
20+
{
21+
var commandRemoveLeadningDotnet = commandName.Replace("dotnet-", string.Empty);
22+
var packageName = "dotnet-" + commandRemoveLeadningDotnet.ToLower();
23+
24+
return string.Format(LocalizableStrings.CannotFindCommandAvailableAsTool,
25+
commandRemoveLeadningDotnet,
26+
packageName);
27+
}
28+
}
29+
}

src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.resx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,9 @@
271271
<data name="EmbedAppNameInHostFileNameIsTooLong" xml:space="preserve">
272272
<value>Given file name '{0}' is longer than 1024 bytes</value>
273273
</data>
274+
<data name="CannotFindCommandAvailableAsTool" xml:space="preserve">
275+
<value>Cannot find command 'dotnet {0}', please run the following command to install
276+
277+
dotnet tool install --global {1}</value>
278+
</data>
274279
</root>

src/Microsoft.DotNet.Cli.Utils/xlf/LocalizableStrings.cs.xlf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@
259259
<target state="new">Given file name '{0}' is longer than 1024 bytes</target>
260260
<note />
261261
</trans-unit>
262+
<trans-unit id="CannotFindCommandAvailableAsTool">
263+
<source>Cannot find command 'dotnet {0}', please run the following command to install
264+
265+
dotnet tool install --global {1}</source>
266+
<target state="new">Cannot find command 'dotnet {0}', please run the following command to install
267+
268+
dotnet tool install --global {1}</target>
269+
<note />
270+
</trans-unit>
262271
</body>
263272
</file>
264273
</xliff>

src/Microsoft.DotNet.Cli.Utils/xlf/LocalizableStrings.de.xlf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@
259259
<target state="new">Given file name '{0}' is longer than 1024 bytes</target>
260260
<note />
261261
</trans-unit>
262+
<trans-unit id="CannotFindCommandAvailableAsTool">
263+
<source>Cannot find command 'dotnet {0}', please run the following command to install
264+
265+
dotnet tool install --global {1}</source>
266+
<target state="new">Cannot find command 'dotnet {0}', please run the following command to install
267+
268+
dotnet tool install --global {1}</target>
269+
<note />
270+
</trans-unit>
262271
</body>
263272
</file>
264273
</xliff>

src/Microsoft.DotNet.Cli.Utils/xlf/LocalizableStrings.es.xlf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@
259259
<target state="new">Given file name '{0}' is longer than 1024 bytes</target>
260260
<note />
261261
</trans-unit>
262+
<trans-unit id="CannotFindCommandAvailableAsTool">
263+
<source>Cannot find command 'dotnet {0}', please run the following command to install
264+
265+
dotnet tool install --global {1}</source>
266+
<target state="new">Cannot find command 'dotnet {0}', please run the following command to install
267+
268+
dotnet tool install --global {1}</target>
269+
<note />
270+
</trans-unit>
262271
</body>
263272
</file>
264273
</xliff>

src/Microsoft.DotNet.Cli.Utils/xlf/LocalizableStrings.fr.xlf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@
259259
<target state="new">Given file name '{0}' is longer than 1024 bytes</target>
260260
<note />
261261
</trans-unit>
262+
<trans-unit id="CannotFindCommandAvailableAsTool">
263+
<source>Cannot find command 'dotnet {0}', please run the following command to install
264+
265+
dotnet tool install --global {1}</source>
266+
<target state="new">Cannot find command 'dotnet {0}', please run the following command to install
267+
268+
dotnet tool install --global {1}</target>
269+
<note />
270+
</trans-unit>
262271
</body>
263272
</file>
264273
</xliff>

src/Microsoft.DotNet.Cli.Utils/xlf/LocalizableStrings.it.xlf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@
259259
<target state="new">Given file name '{0}' is longer than 1024 bytes</target>
260260
<note />
261261
</trans-unit>
262+
<trans-unit id="CannotFindCommandAvailableAsTool">
263+
<source>Cannot find command 'dotnet {0}', please run the following command to install
264+
265+
dotnet tool install --global {1}</source>
266+
<target state="new">Cannot find command 'dotnet {0}', please run the following command to install
267+
268+
dotnet tool install --global {1}</target>
269+
<note />
270+
</trans-unit>
262271
</body>
263272
</file>
264273
</xliff>

src/Microsoft.DotNet.Cli.Utils/xlf/LocalizableStrings.ja.xlf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@
259259
<target state="new">Given file name '{0}' is longer than 1024 bytes</target>
260260
<note />
261261
</trans-unit>
262+
<trans-unit id="CannotFindCommandAvailableAsTool">
263+
<source>Cannot find command 'dotnet {0}', please run the following command to install
264+
265+
dotnet tool install --global {1}</source>
266+
<target state="new">Cannot find command 'dotnet {0}', please run the following command to install
267+
268+
dotnet tool install --global {1}</target>
269+
<note />
270+
</trans-unit>
262271
</body>
263272
</file>
264273
</xliff>

src/Microsoft.DotNet.Cli.Utils/xlf/LocalizableStrings.ko.xlf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@
259259
<target state="new">Given file name '{0}' is longer than 1024 bytes</target>
260260
<note />
261261
</trans-unit>
262+
<trans-unit id="CannotFindCommandAvailableAsTool">
263+
<source>Cannot find command 'dotnet {0}', please run the following command to install
264+
265+
dotnet tool install --global {1}</source>
266+
<target state="new">Cannot find command 'dotnet {0}', please run the following command to install
267+
268+
dotnet tool install --global {1}</target>
269+
<note />
270+
</trans-unit>
262271
</body>
263272
</file>
264273
</xliff>

0 commit comments

Comments
 (0)