-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Download logs * All tests * Fix typing check * Do not log * Align types * No ansi in my log files please * Unwanted space in env
- Loading branch information
1 parent
8e2cd6b
commit 3601ebc
Showing
7 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,55 @@ | ||
use crate::{ | ||
get_player_dir, player_config_exists, CONDUCTOR_STDERR_LOG_FILENAME, | ||
CONDUCTOR_STDOUT_LOG_FILENAME, LAIR_STDERR_LOG_FILENAME, | ||
}; | ||
use snafu::{ResultExt, Snafu}; | ||
use trycp_api::{DownloadLogsResponse, MessageResponse, TryCpServerResponse}; | ||
|
||
#[derive(Debug, Snafu)] | ||
pub(crate) enum DownloadLogsError { | ||
#[snafu(display("No player with this ID is configured {}", id))] | ||
PlayerNotConfigured { id: String }, | ||
#[snafu(display("Could not read lair stderr log for player with ID {}: {}", id, source))] | ||
LairStdErr { id: String, source: std::io::Error }, | ||
#[snafu(display( | ||
"Could not read holochain stdout log for player with ID {}: {}", | ||
id, | ||
source | ||
))] | ||
HolochainStdout { id: String, source: std::io::Error }, | ||
#[snafu(display( | ||
"Could not read holochain stderr log for player with ID {}: {}", | ||
id, | ||
source | ||
))] | ||
HolochainStderr { id: String, source: std::io::Error }, | ||
#[snafu(display("Could not serialize response: {}", source))] | ||
SerializeResponse { source: rmp_serde::encode::Error }, | ||
} | ||
|
||
pub(crate) fn download_logs(id: String) -> Result<MessageResponse, DownloadLogsError> { | ||
if !player_config_exists(&id) { | ||
return Err(DownloadLogsError::PlayerNotConfigured { id }); | ||
} | ||
|
||
let player_dir = get_player_dir(&id); | ||
|
||
let lair_stderr = player_dir.join(LAIR_STDERR_LOG_FILENAME); | ||
let lair_stderr = std::fs::read(&lair_stderr).context(LairStdErr { id: id.clone() })?; | ||
|
||
let conductor_stdout = player_dir.join(CONDUCTOR_STDOUT_LOG_FILENAME); | ||
let conductor_stdout = | ||
std::fs::read(&conductor_stdout).context(HolochainStdout { id: id.clone() })?; | ||
|
||
let conductor_stderr = player_dir.join(CONDUCTOR_STDERR_LOG_FILENAME); | ||
let conductor_stderr = std::fs::read(&conductor_stderr).context(HolochainStderr { id })?; | ||
|
||
Ok(MessageResponse::Bytes( | ||
rmp_serde::to_vec_named(&TryCpServerResponse::DownloadLogs(DownloadLogsResponse { | ||
lair_stderr, | ||
conductor_stdout, | ||
conductor_stderr, | ||
})) | ||
.context(SerializeResponse)?, | ||
)) | ||
} |
This file contains 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 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 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 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 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