Skip to content

Commit c778157

Browse files
committed
feat: add propre handling of the extensions install process
1 parent 3151344 commit c778157

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

apps/sandbox/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async fn main() {
1010
init_tracing(
1111
vec![Tracing {
1212
kind: TracingKind::Console,
13-
level: VerboseLevel::DEBUG,
13+
level: VerboseLevel::TRACE,
1414
additional: Default::default(),
1515
name: "test2".to_string(),
1616
}],

libs/vscode/src/error.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@ pub enum GetInstalledExtensionsError {
44
StdoutAttachError,
55
IoError(std::io::Error),
66
}
7+
8+
#[derive(Debug)]
9+
pub enum InstallExtensionError {
10+
EmptyReturn,
11+
StdoutAttachError,
12+
FailedToInstallExtension(String),
13+
GetInstalledExtensionsError(GetInstalledExtensionsError),
14+
IoError(std::io::Error),
15+
}

libs/vscode/src/extensions.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashMap;
22

33
use serde::{Deserialize, Serialize};
44

5-
use crate::error::GetInstalledExtensionsError;
5+
use crate::error::{GetInstalledExtensionsError, InstallExtensionError};
66

77
#[derive(Debug, Clone, Serialize, Deserialize)]
88
pub struct Extensions {}
@@ -23,6 +23,7 @@ impl Extensions {
2323
"ms-kubernetes-tools.vscode-kubernetes-tools".to_string(),
2424
"ms-vscode-remote.remote-ssh".to_string(),
2525
"ms-vscode.remote-server".to_string(),
26+
"test.test".to_string(),
2627
"bierner.emojisense".to_string(),
2728
]
2829
}
@@ -70,7 +71,7 @@ impl Extensions {
7071
}
7172

7273
#[tracing::instrument(level = "trace")]
73-
pub fn install_extension(&self, extension: &str) -> Result<(), GetInstalledExtensionsError> {
74+
pub fn install_extension(&self, extension: &str) -> Result<(), InstallExtensionError> {
7475
let command = format!("code --install-extension {}", extension);
7576
tracing::trace!("Installing extension: {}", extension);
7677
let output = if cfg!(target_os = "windows") {
@@ -85,8 +86,14 @@ impl Extensions {
8586
.output()
8687
.expect("failed to execute process")
8788
};
88-
let output = String::from_utf8_lossy(&output.stdout);
89-
tracing::trace!("output: {:?}", output);
89+
let out = String::from_utf8_lossy(&output.stdout);
90+
let err = String::from_utf8_lossy(&output.stderr);
91+
tracing::trace!("output: {:?} : {:?}", out, err);
92+
if err != "" {
93+
return Err(InstallExtensionError::FailedToInstallExtension(
94+
err.to_string(),
95+
));
96+
}
9097
Ok(())
9198
}
9299
}

0 commit comments

Comments
 (0)