improve error message for unresolved tools
This commit is contained in:
parent
aed81d43db
commit
0b746ee559
4 changed files with 47 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using NuGet.Frameworks;
|
||||
|
@ -19,15 +20,39 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
|
||||
public string GetBestLockFilePath(string packageId, VersionRange versionRange, NuGetFramework framework)
|
||||
{
|
||||
if (versionRange == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(versionRange));
|
||||
}
|
||||
|
||||
if (framework == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(framework));
|
||||
}
|
||||
|
||||
var availableToolVersions = GetAvailableToolVersions(packageId);
|
||||
|
||||
var bestVersion = versionRange.FindBestMatch(availableToolVersions);
|
||||
if (bestVersion == null)
|
||||
{
|
||||
throw new GracefulException($"Version for package `{packageId}` could not be resolved.");
|
||||
}
|
||||
|
||||
return GetLockFilePath(packageId, bestVersion, framework);
|
||||
}
|
||||
|
||||
public string GetLockFilePath(string packageId, NuGetVersion version, NuGetFramework framework)
|
||||
{
|
||||
if (version == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(version));
|
||||
}
|
||||
|
||||
if (framework == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(framework));
|
||||
}
|
||||
|
||||
return Path.Combine(
|
||||
GetBaseToolPath(packageId),
|
||||
version.ToNormalizedString(),
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
public class CommandUnknownException : Exception
|
||||
public class CommandUnknownException : GracefulException
|
||||
{
|
||||
public CommandUnknownException()
|
||||
{
|
||||
|
|
19
src/Microsoft.DotNet.Cli.Utils/GracefulEceptionException.cs
Normal file
19
src/Microsoft.DotNet.Cli.Utils/GracefulEceptionException.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
public class GracefulException : Exception
|
||||
{
|
||||
public GracefulException()
|
||||
{
|
||||
}
|
||||
|
||||
public GracefulException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public GracefulException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,13 +34,11 @@ namespace Microsoft.DotNet.Cli
|
|||
{
|
||||
return Program.ProcessArgs(args, new Telemetry());
|
||||
}
|
||||
catch (CommandUnknownException e)
|
||||
catch (GracefulException e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
|
||||
Console.WriteLine(e.Message.Red().Bold());
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static int ProcessArgs(string[] args, ITelemetry telemetryClient)
|
||||
|
|
Loading…
Reference in a new issue