Skip to content

Commit

Permalink
Add new constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Soltis authored and Greg Soltis committed Mar 4, 2024
1 parent e0c927c commit 5df3759
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/telemetry.rs
Expand Up @@ -38,7 +38,7 @@ pub fn configure(
base: &mut CommandBase,
telemetry: CommandEventBuilder,
) {
let config = TelemetryConfig::new();
let config = TelemetryConfig::with_default_config_path();
let mut config = match config {
Ok(config) => config,
Err(e) => {
Expand Down
10 changes: 7 additions & 3 deletions crates/turborepo-telemetry/src/config.rs
Expand Up @@ -54,8 +54,12 @@ pub struct TelemetryConfig {
}

impl TelemetryConfig {
pub fn new() -> Result<TelemetryConfig, ConfigError> {
pub fn with_default_config_path() -> Result<TelemetryConfig, ConfigError> {
let config_path = get_config_path()?;
TelemetryConfig::new(config_path)
}

pub fn new(config_path: AbsoluteSystemPathBuf) -> Result<TelemetryConfig, ConfigError> {
debug!("Telemetry config path: {}", config_path);
if !config_path.exists() {
write_new_config(&config_path)?;
Expand Down Expand Up @@ -100,7 +104,7 @@ impl TelemetryConfig {
}

pub fn one_way_hash(input: &str) -> String {
match TelemetryConfig::new() {
match TelemetryConfig::with_default_config_path() {
Ok(config) => config.one_way_hash_with_config_salt(input),
Err(_) => TelemetryConfig::one_way_hash_with_tmp_salt(input),
}
Expand Down Expand Up @@ -252,7 +256,7 @@ fn write_new_config(file_path: &AbsoluteSystemPath) -> Result<(), ConfigError> {
// Create the directory if it doesn't exist
file_path
.ensure_dir()
.map_err(|_| ConfigError::Message("Failed to create director".to_string()))?;
.map_err(|_| ConfigError::Message("Failed to create directory".to_string()))?;

// Write the file
file_path
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-telemetry/src/lib.rs
Expand Up @@ -81,7 +81,7 @@ fn init(
) -> Result<(TelemetryHandle, TelemetrySender), Box<dyn std::error::Error>> {
let (tx, rx) = mpsc::unbounded_channel();
let (cancel_tx, cancel_rx) = oneshot::channel();
let mut config = TelemetryConfig::new()?;
let mut config = TelemetryConfig::with_default_config_path()?;
config.show_alert(ui);

let session_id = Uuid::new_v4();
Expand Down

0 comments on commit 5df3759

Please sign in to comment.