Skip to content

Commit

Permalink
track a telemetry event when package discovery yields an invalid package
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Lyon authored and Alexander Lyon committed Feb 16, 2024
1 parent 1575d41 commit d8285e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
26 changes: 21 additions & 5 deletions crates/turborepo-lib/src/run/mod.rs
Expand Up @@ -12,7 +12,7 @@ pub mod task_id;

use std::{
collections::HashSet,
io::{IsTerminal, Write},
io::{ErrorKind, IsTerminal, Write},
sync::Arc,
time::SystemTime,
};
Expand All @@ -29,15 +29,15 @@ use turborepo_cache::{AsyncCache, RemoteCacheOpts};
use turborepo_ci::Vendor;
use turborepo_env::EnvironmentVariableMap;
use turborepo_repository::{
package_graph::{PackageGraph, PackageName},
package_json::PackageJson,
package_graph::{self, PackageGraph, PackageName},
package_json::{self, PackageJson},
};
use turborepo_scm::SCM;
use turborepo_telemetry::events::{
command::CommandEventBuilder,
generic::{DaemonInitStatus, GenericEventBuilder},
repo::{RepoEventBuilder, RepoType},
EventBuilder,
EventBuilder, TrackedErrors,
};
use turborepo_ui::{cprint, cprintln, ColorSelector, BOLD_GREY, GREY, UI};
#[cfg(feature = "daemon-package-discovery")]
Expand Down Expand Up @@ -311,7 +311,23 @@ impl Run {
builder.with_package_discovery(fallback_discovery)
};

builder.build().await?
match builder.build().await {
Ok(graph) => graph,
// if we can't find the package.json, it is a bug, and we should report it.
// likely cause is that package discovery watching is not up to date.
// note: there _is_ a false positive from a race condition that can occur
// from toctou if the package.json is deleted, but we'd like to know
Err(package_graph::builder::Error::PackageJson(package_json::Error::Io(io)))
if io.kind() == ErrorKind::NotFound =>
{
run_telemetry.track_error(TrackedErrors::InvalidPackageDiscovery);
return Err(package_graph::builder::Error::PackageJson(
package_json::Error::Io(io),
)
.into());
}
Err(e) => return Err(e.into()),
}
};

repo_telemetry.track_package_manager(pkg_dep_graph.package_manager().to_string());
Expand Down
6 changes: 6 additions & 0 deletions crates/turborepo-telemetry/src/events/mod.rs
Expand Up @@ -55,6 +55,11 @@ pub enum TrackedErrors {
ErrorFetchingFromCache,
FailedToPipeOutputs,
UnknownChildExit,
/// Yielded when package discovery yields a
/// list of packages that fails downstream.
/// Currently only indicates a package being
/// reported when it does not exist.
InvalidPackageDiscovery,
}

impl Display for TrackedErrors {
Expand All @@ -72,6 +77,7 @@ impl Display for TrackedErrors {
TrackedErrors::ErrorFetchingFromCache => write!(f, "error_fetching_from_cache"),
TrackedErrors::FailedToPipeOutputs => write!(f, "failed_to_pipe_outputs"),
TrackedErrors::UnknownChildExit => write!(f, "unknown_child_exit"),
TrackedErrors::InvalidPackageDiscovery => write!(f, "invalid_package_discovery"),
}
}
}
Expand Down

0 comments on commit d8285e6

Please sign in to comment.