Skip to content

Provide clear error when directory does not exist #5216

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions src/Agent.Plugins/PipelineCache/TarUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public static async Task<string> ArchiveFilesToTarAsync(
throw new DirectoryNotFoundException($"Please specify path to a directory, File path is not allowed. {inputPath} is a file.");
}

if (!Directory.Exists(inputPath))
{
throw new DirectoryNotFoundException($"Please specify path to a directory, '{inputPath}' does not exist.");
}

var archiveFileName = CreateArchiveFileName();
var archiveFile = Path.Combine(Path.GetTempPath(), archiveFileName);

Expand Down
14 changes: 14 additions & 0 deletions src/Test/L0/Plugin/TarUtilsL0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Agent.Sdk;
using Agent.Plugins.PipelineCache;
using System.Diagnostics;
using System.IO;

namespace Microsoft.VisualStudio.Services.Agent.Tests.PipelineCaching
{
Expand All @@ -19,5 +20,18 @@ public async Task UnavailableProcessDependency_ThrowsNiceError()
startInfo.FileName = "ThisProcessObviouslyWillFail";
await Assert.ThrowsAsync<InvalidOperationException>(async () => await TarUtils.RunProcessAsync(new AgentTaskPluginExecutionContext(), startInfo, (p, ct) => null, () => { }, new CancellationToken()));
}

[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Plugin")]
public async Task Tar_ArchiveFilesToTarAsync_ThrowsDirectoryNotFoundException()
{
await Assert.ThrowsAsync<DirectoryNotFoundException>(async () =>
await TarUtils.ArchiveFilesToTarAsync(
new AgentTaskPluginExecutionContext(),
Path.Combine(Environment.CurrentDirectory, "nonexistentpath"),
CancellationToken.None)
);
}
}
}