Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
19 changes: 19 additions & 0 deletions libmamba/include/mamba/core/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,25 @@ namespace mamba
Console(const Context& context);
~Console();

/** Utility to set `"success": false` on destruction of this object
when it's destructor is invoked while an exception is in flight.

This helps avoiding situations where an exception that should be
considered a failure of the overall operation is thrown but
the json is still set with `"success": true`, while it should be `false`,
misleading the testing outputs.
*/
struct JSonFailureOnException
{
~JSonFailureOnException()
{
if (std::uncaught_exceptions() > 0)
{
Console::instance().json_write({ { "success", false } });
}
}
};

private:

void json_print();
Expand Down
3 changes: 3 additions & 0 deletions libmamba/src/core/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ namespace mamba
bool
MTransaction::execute(const Context& ctx, ChannelContext& channel_context, PrefixData& prefix)
{
// If an exception exists this function, we must consider the whole operation a failure.
Console::JSonFailureOnException fail_json_on_exception;
Comment thread
Klaim marked this conversation as resolved.
Outdated

// JSON output
// back to the top level if any action was required
if (!empty())
Expand Down
11 changes: 5 additions & 6 deletions micromamba/tests/test_pkg_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,16 +393,15 @@ def test_no_writable_extracted_dir_corrupted(self, tmp_home, tmp_root_prefix, tm
f"**{file_to_find_in_package}", recursive=True, root_dir=old_cache_dir
)
for file in files:
(old_cache_dir / file).unlink()
file.unlink()
helpers.recursive_chmod(tmp_cache, 0o500)

os.environ["CONDA_PKGS_DIRS"] = f"{tmp_cache}"

# Mamba now handles corrupted extracted directories in read-only caches gracefully
# by extracting to a temporary location, so the operation should succeed
helpers.create(
"-n", "myenv", package_to_check_requirements(), "-vv", "--json", no_dry_run=True
)
with pytest.raises(subprocess.CalledProcessError):
helpers.create(
"-n", "myenv", package_to_check_requirements(), "-vv", "--json", no_dry_run=True
)

def test_first_writable_extracted_dir_corrupted(
self, tmp_home, tmp_root_prefix, tmp_cache, tmp_cache_alt
Expand Down
Loading