Protoc stderr into error

This commit is contained in:
Gregory Schier
2024-07-24 07:41:51 -07:00
parent f51575508e
commit 9f268a9316

View File

@@ -1,19 +1,18 @@
use std::env::temp_dir; use std::env::temp_dir;
use std::ops::Deref; use std::ops::Deref;
use std::path::PathBuf; use std::path::PathBuf;
use std::str::{from_utf8, FromStr}; use std::str::FromStr;
use anyhow::anyhow; use anyhow::anyhow;
use hyper::client::HttpConnector; use hyper::client::HttpConnector;
use hyper::Client; use hyper::Client;
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder}; use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
use log::{debug, info, warn}; use log::{debug, warn};
use prost::Message; use prost::Message;
use prost_reflect::{DescriptorPool, MethodDescriptor}; use prost_reflect::{DescriptorPool, MethodDescriptor};
use prost_types::{FileDescriptorProto, FileDescriptorSet}; use prost_types::{FileDescriptorProto, FileDescriptorSet};
use tauri::path::BaseDirectory; use tauri::path::BaseDirectory;
use tauri::{AppHandle, Manager}; use tauri::{AppHandle, Manager};
use tauri_plugin_shell::process::CommandEvent;
use tauri_plugin_shell::ShellExt; use tauri_plugin_shell::ShellExt;
use tokio::fs; use tokio::fs;
use tokio_stream::StreamExt; use tokio_stream::StreamExt;
@@ -65,46 +64,21 @@ pub async fn fill_pool_from_files(
} }
} }
let (mut rx, _child) = app_handle let out = app_handle
.shell() .shell()
.sidecar("yaakprotoc") .sidecar("yaakprotoc")
.expect("yaakprotoc not found") .expect("yaakprotoc not found")
.args(args) .args(args)
.spawn() .output()
.expect("yaakprotoc failed to start"); .await
.expect("yaakprotoc failed to run");
while let Some(event) = rx.recv().await { if !out.status.success() {
match event { return Err(format!(
CommandEvent::Stdout(line) => { "protoc failed with status {}: {}",
info!( out.status.code().unwrap(),
"protoc stdout: {}", String::from_utf8_lossy(out.stderr.as_slice())
from_utf8(line.as_slice()).unwrap_or_default().to_string() ));
);
}
CommandEvent::Stderr(line) => {
info!(
"protoc stderr: {}",
from_utf8(line.as_slice()).unwrap_or_default().to_string()
);
}
CommandEvent::Error(e) => {
return Err(e.to_string());
}
CommandEvent::Terminated(c) => {
match c.code {
Some(0) => {
// success
}
Some(code) => {
return Err(format!("protoc failed with exit code: {}", code,));
}
None => {
return Err("protoc failed with no exit code".to_string());
}
}
}
_ => {}
};
} }
let bytes = fs::read(desc_path.as_path()) let bytes = fs::read(desc_path.as_path())