-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: report a clear cli error when no herdr server is running #1963
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
ogulcancelik
merged 3 commits into
herdrdev:master
from
season179:issue/1941-cli-server-not-running
Aug 1, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| use std::fmt; | ||
| use std::path::Path; | ||
|
|
||
| use crate::api::schema::{ErrorBody, ErrorResponse}; | ||
|
|
||
| /// Marker error signalling a dead API socket. Carries the `ErrorResponse` that | ||
| /// should be printed at the edge that finally surfaces the error, so callers | ||
| /// that recover (e.g. plugin offline fallback) print nothing. Mirrors | ||
| /// `ProtocolMismatchReported`, except printing is deferred because several CLI | ||
| /// commands recover from a dead server instead of reporting it. | ||
| #[derive(Debug)] | ||
| pub(super) struct ServerNotRunningReported { | ||
| pub(super) response: ErrorResponse, | ||
| } | ||
|
|
||
| impl fmt::Display for ServerNotRunningReported { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| // Delegate to the carried message so pre-existing paths that | ||
| // stringify transport errors still show the actionable text. | ||
| f.write_str(&self.response.error.message) | ||
| } | ||
| } | ||
|
|
||
| impl std::error::Error for ServerNotRunningReported {} | ||
|
|
||
| /// Builds the friendly `server_not_running` ErrorResponse shown when no | ||
| /// server is listening on the resolved API socket. | ||
| pub(super) fn response(request_id: &str, socket_path: &Path) -> ErrorResponse { | ||
| let attach_command = startup_command(socket_path); | ||
| ErrorResponse { | ||
| id: request_id.to_string(), | ||
| error: ErrorBody { | ||
| code: "server_not_running".into(), | ||
| message: format!( | ||
| "no herdr server is running at {}; run `{attach_command}` to start or attach it", | ||
| socket_path.display() | ||
| ), | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| fn startup_command(socket_path: &Path) -> String { | ||
| let session_socket = | ||
| crate::session::api_socket_path_for(crate::session::active_name().as_deref()); | ||
| if socket_path == session_socket { | ||
| crate::session::local_attach_command() | ||
| } else { | ||
| // A socket override wins over an inherited HERDR_SESSION. Keep the | ||
| // command in the current environment so it starts the overridden | ||
| // target instead of directing the user to an unrelated session. | ||
| "herdr".to_string() | ||
| } | ||
| } | ||
|
|
||
| /// Wraps the response in the recognizable marker WITHOUT printing. The caller | ||
| /// that ultimately surfaces the error prints the carried response (see | ||
| /// `reported_response`); recovering callers simply drop it. | ||
| pub(super) fn reported_error(response: ErrorResponse) -> std::io::Error { | ||
| std::io::Error::other(ServerNotRunningReported { response }) | ||
| } | ||
|
|
||
| pub(super) fn was_reported(err: &std::io::Error) -> bool { | ||
| err.get_ref() | ||
| .and_then(|source| source.downcast_ref::<ServerNotRunningReported>()) | ||
| .is_some() | ||
| } | ||
|
|
||
| /// Returns the `ErrorResponse` carried by a `server_not_running` marker, if any, | ||
| /// so the surfacing edge can print it exactly once. | ||
| pub(super) fn reported_response(err: &std::io::Error) -> Option<&ErrorResponse> { | ||
| err.get_ref() | ||
| .and_then(|source| source.downcast_ref::<ServerNotRunningReported>()) | ||
| .map(|reported| &reported.response) | ||
| } |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.