improve error message for unresolved tools

This commit is contained in:
Krzysztof Wicher 2016-04-12 16:44:34 -07:00
parent aed81d43db
commit 0b746ee559
4 changed files with 47 additions and 5 deletions

View file

@ -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(),

View file

@ -2,7 +2,7 @@
namespace Microsoft.DotNet.Cli.Utils
{
public class CommandUnknownException : Exception
public class CommandUnknownException : GracefulException
{
public CommandUnknownException()
{

View 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)
{
}
}
}

View file

@ -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)