Skip to content

Commit

Permalink
fix(core): handle events that do not have paths (nrwl#22947)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli authored Apr 23, 2024
1 parent b37bfdb commit 3d9bd16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
27 changes: 19 additions & 8 deletions packages/nx/src/native/watch/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,32 @@ pub(super) struct WatchEventInternal {
pub origin: Option<String>,
}

impl From<&Event> for WatchEventInternal {
fn from(value: &Event) -> Self {


impl TryFrom<&Event> for WatchEventInternal {
type Error = anyhow::Error;

fn try_from(value: &Event) -> std::result::Result<Self, Self::Error> {
let transformed = transform_event(value);
let value = transformed.as_ref().unwrap_or(value);

let path = value.paths().next().expect("there should always be a path");
let Some(path) = value.paths().next() else {
let error_msg = "unable to get path from the event";
trace!(?value, error_msg);
anyhow::bail!(error_msg)
};

let event_kind = value
let Some( event_kind ) = value
.tags
.iter()
.find_map(|t| match t {
Tag::FileEventKind(event_kind) => Some(event_kind),
_ => None,
})
.expect("there should always be a file event kind");
}) else {
let error_msg = "unable to get the file event kind";
trace!(?value, error_msg);
anyhow::bail!(error_msg)
};

let path_ref = path.0;
let event_type = if path.1.is_none() && !path_ref.exists() {
Expand Down Expand Up @@ -112,10 +123,10 @@ impl From<&Event> for WatchEventInternal {

trace!(?path, ?event_kind, ?event_type, "event kind -> event type");

WatchEventInternal {
Ok(WatchEventInternal {
path: path.0.into(),
r#type: event_type,
origin: None,
}
})
}
}
11 changes: 7 additions & 4 deletions packages/nx/src/native/watch/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@ impl Watcher {
let events = action
.events
.par_iter()
.map(|ev| {
let mut watch_event: WatchEventInternal = ev.into();
watch_event.origin = Some(origin_path.clone());
watch_event
.filter_map(|ev| {
ev.try_into()
.map(|mut watch_event: WatchEventInternal| {
watch_event.origin = Some(origin_path.clone());
watch_event
})
.ok()
})
.collect::<Vec<WatchEventInternal>>();

Expand Down

0 comments on commit 3d9bd16

Please sign in to comment.