Skip to content

Commit

Permalink
Python config error handling (#1768)
Browse files Browse the repository at this point in the history
  • Loading branch information
phiSgr authored Sep 23, 2024
1 parent d76cb50 commit 083bc80
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions apps/framework-cli/src/framework/data_model/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::collections::{HashMap, HashSet};
use std::path::{absolute, Path};

use tokio::io::AsyncReadExt;

use crate::framework::typescript::export_collectors::get_data_model_configs;
use log::{info, warn};
use log::info;
use serde::Deserialize;
use serde::Serialize;
use std::ffi::OsStr;
Expand Down Expand Up @@ -67,6 +65,7 @@ pub struct DataModelConfig {
#[non_exhaustive]
pub enum ModelConfigurationError {
TypescriptRunner(#[from] crate::framework::typescript::export_collectors::ExportCollectorError),
#[error("Failed to get the Data Model configuration with Python\n{0}")]
PythonRunner(String),
}

Expand All @@ -87,18 +86,19 @@ async fn execute_python_model_file_for_config(
.await
.map_err(|e| ModelConfigurationError::PythonRunner(e.to_string()))?;

let mut stdout = match process.stdout {
Some(handle) => handle,
None => return Ok(HashMap::new()),
};

let mut raw_string_stdout: String = String::new();
let output = process
.wait_with_output()
.await
.map_err(|e| ModelConfigurationError::PythonRunner(e.to_string()))?;

if stdout.read_to_string(&mut raw_string_stdout).await.is_err() {
warn!("Unable to read stdout for python config dump");
return Ok(HashMap::new());
if !output.status.success() {
return Err(ModelConfigurationError::PythonRunner(
String::from_utf8_lossy(&output.stderr).to_string(),
));
}

let raw_string_stdout = String::from_utf8_lossy(&output.stdout);

let configs: HashMap<ConfigIdentifier, DataModelConfig> = raw_string_stdout
.split("___DATAMODELCONFIG___")
.filter_map(|entry| {
Expand Down

0 comments on commit 083bc80

Please sign in to comment.