From 9f268a931694243a25489ef2f7efad71086c0cac Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Wed, 24 Jul 2024 07:41:51 -0700 Subject: [PATCH] Protoc stderr into error --- src-tauri/grpc/src/proto.rs | 50 +++++++++---------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/src-tauri/grpc/src/proto.rs b/src-tauri/grpc/src/proto.rs index 571c8489..a2fd5ab5 100644 --- a/src-tauri/grpc/src/proto.rs +++ b/src-tauri/grpc/src/proto.rs @@ -1,19 +1,18 @@ use std::env::temp_dir; use std::ops::Deref; use std::path::PathBuf; -use std::str::{from_utf8, FromStr}; +use std::str::FromStr; use anyhow::anyhow; use hyper::client::HttpConnector; use hyper::Client; use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder}; -use log::{debug, info, warn}; +use log::{debug, warn}; use prost::Message; use prost_reflect::{DescriptorPool, MethodDescriptor}; use prost_types::{FileDescriptorProto, FileDescriptorSet}; use tauri::path::BaseDirectory; use tauri::{AppHandle, Manager}; -use tauri_plugin_shell::process::CommandEvent; use tauri_plugin_shell::ShellExt; use tokio::fs; 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() .sidecar("yaakprotoc") .expect("yaakprotoc not found") .args(args) - .spawn() - .expect("yaakprotoc failed to start"); + .output() + .await + .expect("yaakprotoc failed to run"); - while let Some(event) = rx.recv().await { - match event { - CommandEvent::Stdout(line) => { - info!( - "protoc stdout: {}", - 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()); - } - } - } - _ => {} - }; + if !out.status.success() { + return Err(format!( + "protoc failed with status {}: {}", + out.status.code().unwrap(), + String::from_utf8_lossy(out.stderr.as_slice()) + )); } let bytes = fs::read(desc_path.as_path())