Bug fixes round 3 (#298)

* fixed bugs

* title case

* bugs; ioerror

* reset breadcrumbs

* more fixes

* more fixes

* scrolling bug

* more fixes

* more fixes

* clippy

* canonicalize fix

* fixed requested changes

* removed debouncer update
This commit is contained in:
Wyatt Verchere
2023-07-19 14:13:25 -07:00
committed by GitHub
parent 6650cc9ce4
commit 1f478ec9fc
34 changed files with 932 additions and 602 deletions
+79 -14
View File
@@ -12,6 +12,7 @@ use tracing::error;
use crate::event::emit::emit_process;
use crate::event::ProcessPayloadType;
use crate::util::io::IOError;
use crate::EventState;
use tokio::task::JoinHandle;
use uuid::Uuid;
@@ -39,7 +40,15 @@ impl Children {
// The threads for stdout and stderr are spawned here
// Unlike a Hashmap's 'insert', this directly returns the reference to the MinecraftChild rather than any previously stored MinecraftChild that may exist
#[tracing::instrument(skip(self))]
#[tracing::instrument(skip(
self,
uuid,
log_path,
mc_command,
post_command,
censor_strings
))]
#[tracing::instrument(level = "trace", skip(self))]
#[theseus_macros::debug_pin]
pub async fn insert_process(
&mut self,
@@ -51,7 +60,7 @@ impl Children {
censor_strings: HashMap<String, String>,
) -> crate::Result<Arc<RwLock<MinecraftChild>>> {
// Takes the first element of the commands vector and spawns it
let mut child = mc_command.spawn()?;
let mut child = mc_command.spawn().map_err(IOError::from)?;
// Create std watcher threads for stdout and stderr
let shared_output =
@@ -125,7 +134,12 @@ impl Children {
// Wait on current Minecraft Child
let mut mc_exit_status;
loop {
if let Some(t) = current_child.write().await.try_wait()? {
if let Some(t) = current_child
.write()
.await
.try_wait()
.map_err(IOError::from)?
{
mc_exit_status = t;
break;
}
@@ -156,7 +170,7 @@ impl Children {
if let Some(mut m_command) = post_command {
{
let mut current_child = current_child.write().await;
let new_child = m_command.spawn()?;
let new_child = m_command.spawn().map_err(IOError::from)?;
current_pid = new_child.id().ok_or_else(|| {
crate::ErrorKind::LauncherError(
"Process immediately failed, could not get PID"
@@ -174,7 +188,12 @@ impl Children {
.await?;
loop {
if let Some(t) = current_child.write().await.try_wait()? {
if let Some(t) = current_child
.write()
.await
.try_wait()
.map_err(IOError::from)?
{
mc_exit_status = t;
break;
}
@@ -210,7 +229,12 @@ impl Children {
) -> crate::Result<Option<std::process::ExitStatus>> {
if let Some(child) = self.get(uuid) {
let child = child.write().await;
let status = child.current_child.write().await.try_wait()?;
let status = child
.current_child
.write()
.await
.try_wait()
.map_err(IOError::from)?;
Ok(status)
} else {
Ok(None)
@@ -224,7 +248,14 @@ impl Children {
if let Some(child) = self.get(&key) {
let child = child.clone();
let child = child.write().await;
if child.current_child.write().await.try_wait()?.is_none() {
if child
.current_child
.write()
.await
.try_wait()
.map_err(IOError::from)?
.is_none()
{
keys.push(key);
}
}
@@ -258,7 +289,14 @@ impl Children {
if let Some(child) = self.get(&key) {
let child = child.clone();
let child = child.write().await;
if child.current_child.write().await.try_wait()?.is_none() {
if child
.current_child
.write()
.await
.try_wait()
.map_err(IOError::from)?
.is_none()
{
profiles.push(child.profile_path.clone());
}
}
@@ -274,7 +312,14 @@ impl Children {
if let Some(child) = self.get(&key) {
let child = child.clone();
let child = child.write().await;
if child.current_child.write().await.try_wait()?.is_none() {
if child
.current_child
.write()
.await
.try_wait()
.map_err(IOError::from)?
.is_none()
{
if let Some(prof) = crate::api::profile::get(
&child.profile_path.clone(),
None,
@@ -312,7 +357,11 @@ impl SharedOutput {
) -> crate::Result<Self> {
Ok(SharedOutput {
output: Arc::new(RwLock::new(String::new())),
log_file: Arc::new(RwLock::new(File::create(log_file_path).await?)),
log_file: Arc::new(RwLock::new(
File::create(log_file_path)
.await
.map_err(|e| IOError::with_path(e, log_file_path))?,
)),
censor_strings,
})
}
@@ -330,7 +379,12 @@ impl SharedOutput {
let mut buf_reader = BufReader::new(child_stdout);
let mut line = String::new();
while buf_reader.read_line(&mut line).await? > 0 {
while buf_reader
.read_line(&mut line)
.await
.map_err(IOError::from)?
> 0
{
let val_line = self.censor_log(line.clone());
{
@@ -339,7 +393,10 @@ impl SharedOutput {
}
{
let mut log_file = self.log_file.write().await;
log_file.write_all(val_line.as_bytes()).await?;
log_file
.write_all(val_line.as_bytes())
.await
.map_err(IOError::from)?;
}
line.clear();
@@ -354,7 +411,12 @@ impl SharedOutput {
let mut buf_reader = BufReader::new(child_stderr);
let mut line = String::new();
while buf_reader.read_line(&mut line).await? > 0 {
while buf_reader
.read_line(&mut line)
.await
.map_err(IOError::from)?
> 0
{
let val_line = self.censor_log(line.clone());
{
@@ -363,7 +425,10 @@ impl SharedOutput {
}
{
let mut log_file = self.log_file.write().await;
log_file.write_all(val_line.as_bytes()).await?;
log_file
.write_all(val_line.as_bytes())
.await
.map_err(IOError::from)?;
}
line.clear();