Skip to content

Improve error messages expanding single-file #58557

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

Merged
merged 1 commit into from
Sep 13, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,58 @@ private void Bundle_extraction_can_recover_missing_files()
extractDir.Should().HaveFiles(extractedFiles);
}

[Fact]
private void Bundle_extraction_to_nonexisting_default()
{
string nonExistentPath = Path.Combine(
sharedTestState.DefaultBundledAppFixture.TestProject.OutputDirectory,
"nonexistent");

string defaultExpansionEnvVariable = OperatingSystem.IsWindows() ? "TMP" : "HOME";
string expectedErrorMessagePart = OperatingSystem.IsWindows() ?
$"Failed to determine default extraction location. Check if 'TMP'" :
$"Default extraction directory [{nonExistentPath}] either doesn't exist or is not accessible for read/write.";

Command.Create(sharedTestState.DefaultBundledAppExecutablePath)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable(defaultExpansionEnvVariable, nonExistentPath)
.Execute().Should().Fail()
.And.HaveStdErrContaining(expectedErrorMessagePart);
}

[Fact]
[SkipOnPlatform(TestPlatforms.Windows, "On Windows the default extraction path is determined by calling GetTempPath which looks at multiple places and can't really be undefined.")]
private void Bundle_extraction_default_undefined()
{
Command.Create(sharedTestState.DefaultBundledAppExecutablePath)
.CaptureStdErr()
.CaptureStdOut()
.EnvironmentVariable("HOME", null)
.Execute().Should().Fail()
.And.HaveStdErrContaining("Failed to determine default extraction location. Environment variable '$HOME' is not defined.");
}

public class SharedTestState : SharedTestStateBase, IDisposable
{
public TestProjectFixture TestFixture { get; set; }
public TestProjectFixture TestFixture { get; }

public TestProjectFixture DefaultBundledAppFixture { get; }
public string DefaultBundledAppExecutablePath { get; }
public Bundler DefaultBundledAppBundler { get; }

public SharedTestState()
{
TestFixture = PreparePublishedSelfContainedTestProject("StandaloneApp");

DefaultBundledAppFixture = TestFixture.Copy();
DefaultBundledAppBundler = BundleSelfContainedApp(DefaultBundledAppFixture, out var singleFile, BundleOptions.BundleNativeBinaries);
DefaultBundledAppExecutablePath = singleFile;
}

public void Dispose()
{
DefaultBundledAppFixture.Dispose();
TestFixture.Dispose();
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/native/corehost/hostmisc/pal.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,18 @@ bool get_extraction_base_parent_directory(pal::string_t& directory)
// check for the POSIX standard environment variable
if (pal::getenv(_X("HOME"), &directory))
{
return is_read_write_able_directory(directory);
if (is_read_write_able_directory(directory))
{
return true;
}
else
{
trace::error(_X("Default extraction directory [%s] either doesn't exist or is not accessible for read/write."), directory.c_str());
}
}
else
{
trace::error(_X("Failed to determine default extraction location. Environment variable '$HOME' is not defined."));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @am11. There's #58464 which is basically tracking potential improvements in where to put the files. I think using other means to obtain the default location falls into that category as well. I wanted to keep this one very simple, solely as a diagnostics improvement (not changing actual functional behavior).

Copy link
Member

@am11 am11 Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, makes sense. I made a small patch on top of your branch with this suggestion: am11@2ca8f26. Perhaps some variant of it could be considered. Will follow up once this PR is merged. :)

}

return false;
Expand All @@ -367,6 +378,7 @@ bool pal::get_default_bundle_extraction_base_dir(pal::string_t& extraction_dir)
}
else if (errno != EEXIST)
{
trace::error(_X("Failed to create default extraction directory [%s]. %s"), extraction_dir.c_str(), pal::strerror(errno));
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/native/corehost/hostmisc/pal.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ bool pal::get_default_bundle_extraction_base_dir(pal::string_t& extraction_dir)
{
if (!get_extraction_base_parent_directory(extraction_dir))
{
trace::error(_X("Failed to determine default extraction location. Check if 'TMP' or 'TEMP' points to existing path."));
return false;
}

Expand All @@ -588,6 +589,7 @@ bool pal::get_default_bundle_extraction_base_dir(pal::string_t& extraction_dir)
if (CreateDirectoryW(extraction_dir.c_str(), NULL) == 0 &&
GetLastError() != ERROR_ALREADY_EXISTS)
{
trace::error(_X("Failed to create default extraction directory [%s]. %s, error code: %d"), extraction_dir.c_str(), pal::strerror(errno), GetLastError());
return false;
}

Expand Down