[snapshot] descriptive error on snapshot deletion of running vm#4981
Open
noor-malaika wants to merge 1 commit into
Open
[snapshot] descriptive error on snapshot deletion of running vm#4981noor-malaika wants to merge 1 commit into
noor-malaika wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the UX around deleting snapshots by returning a clearer, precondition-style error when a user attempts to delete a snapshot from a running instance, avoiding the current low-level backend failure output.
Changes:
- Add a daemon-side precondition check to block snapshot deletion when the instance is running.
- Adjust the
deleteCLI failure handling to avoid printing the “Use --purge…” hint for snapshot-related precondition failures.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/daemon/daemon.cpp |
Adds an early FAILED_PRECONDITION error when deleting snapshots on a running instance. |
src/client/cli/cmd/delete.cpp |
Updates FAILED_PRECONDITION handling to conditionally suppress the “Use --purge…” hint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
2428
to
+2440
| if (!all || !purge) // if we're not purging the instance, we need to delete | ||
| // specified snapshots | ||
| for (const auto& snapshot_name : pick) | ||
| { | ||
| if (vm_it->second->current_state() == mp::VirtualMachine::State::running) | ||
| { | ||
| status_promise->set_value(grpc::Status{ | ||
| grpc::StatusCode::FAILED_PRECONDITION, | ||
| fmt::format("Instance '{}' must be stopped before deleting a snapshot.", instance_name)}); | ||
| return; | ||
| } | ||
| vm_it->second->delete_snapshot(snapshot_name); | ||
| } |
Comment on lines
+75
to
+82
| if (status.error_code() == grpc::StatusCode::FAILED_PRECONDITION) | ||
| { | ||
| const auto& msg = status.error_message(); | ||
| if (msg.find("snapshot") != std::string::npos) | ||
| return standard_failure_handler_for(name(), cerr, status); | ||
| return standard_failure_handler_for(name(), cerr, status, "Use --purge to forcefully delete it."); | ||
| } | ||
| return standard_failure_handler_for(name(), cerr, status); |
Comment on lines
74
to
+82
| auto on_failure = [this](grpc::Status& status) -> ReturnCodeVariant { | ||
| // grpc::StatusCode::FAILED_PRECONDITION matches mp::VMStateInvalidException | ||
| return status.error_code() == grpc::StatusCode::FAILED_PRECONDITION | ||
| ? standard_failure_handler_for(name(), | ||
| cerr, | ||
| status, | ||
| "Use --purge to forcefully delete it.") | ||
| : standard_failure_handler_for(name(), cerr, status); | ||
| if (status.error_code() == grpc::StatusCode::FAILED_PRECONDITION) | ||
| { | ||
| const auto& msg = status.error_message(); | ||
| if (msg.find("snapshot") != std::string::npos) | ||
| return standard_failure_handler_for(name(), cerr, status); | ||
| return standard_failure_handler_for(name(), cerr, status, "Use --purge to forcefully delete it."); | ||
| } | ||
| return standard_failure_handler_for(name(), cerr, status); |
Collaborator
|
Hi @noor-malaika, thank you for your interest in Multipass and your effort to contribute. I had a brief look at the PR and I think copilot's comments make sense. Before I assign someone to review your PR, could you please sort it out with Copilot's reviews? Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pr adds a descriptive error msg on trying snapshot deletion of a running vm.
Related Issue(s)
Closes #4824
Testing
Manual testing steps:
Screenshots (if applicable)
Checklist