Repository: microsoft/onefuzz
File: src/agent/onefuzz/src/monitor.rs (Rust)

Code before:

                    match create_kind {
                        CreateKind::File => {
                            return Ok(Some(path));
                        }
                        CreateKind::Folder => {
                            if self.report_directories {
                                return Ok(Some(path));
                            }
                        }
                        CreateKind::Any | CreateKind::Other => {
                            match fs::metadata(&path).await {
                                Ok(metadata) => {
                                    // check if it is a file or a folder
                                    if metadata.is_file() || self.report_directories {
                                        return Ok(Some(path));
                                    }
                                }
                                Err(e) => {
                                    warn!(
                                        "{:?}",
                                        Err(e).context(format!(
                                            "failed to get metadata for {}",
                                            path.display()
                                        ))
                                    );
                                }
                            }
                        }
                    }
                }
                EventKind::Modify(ModifyKind::Name(rename_mode)) => {
                    match rename_mode {
                        RenameMode::To => {
                            let path = paths.next().ok_or_else(|| {
                                format_err!("missing 'to' path for file rename-to event")
                            })?;

                            return Ok(Some(path));
                        }
                        RenameMode::Both => {
                            let _from = paths.next().ok_or_else(|| {
                                format_err!("missing 'from' path for file rename event")
                            })?;

                            let to = paths.next().ok_or_else(|| {
                                format_err!("missing 'to' path for file rename event")
                            })?;

                            return Ok(Some(to));
                        }

Review comment (bug):
```suggestion
warn!("failed to get metadata for {}:\n {}", path.display(), err);
```

Code after:

                    match create_kind {
                        CreateKind::File => {
                            return Ok(Some(path));
                        }
                        CreateKind::Folder => {
                            if self.report_directories {
                                return Ok(Some(path));
                            }
                        }
                        CreateKind::Any | CreateKind::Other => {
                            // Short-circuit and report this path if we're reporting everything.
                            if self.report_directories {
                                return Ok(Some(path));
                            }

                            match fs::metadata(&path).await {
                                Ok(metadata) => {
                                    // We're only reporting files, so make sure this is a file first.
                                    if metadata.is_file() {
                                        return Ok(Some(path));
                                    }
                                }
                                Err(e) => {
                                    warn!("failed to get metadata for {}: {:?}", path.display(), e);
                                }
                            }
                        }
                    }
                }
                EventKind::Modify(ModifyKind::Name(rename_mode)) => {
                    match rename_mode {
                        RenameMode::To => {
                            let path = paths.next().ok_or_else(|| {
                                format_err!("missing 'to' path for file rename-to event")
                            })?;

                            return Ok(Some(path));
                        }
                        RenameMode::Both => {
                            let _from = paths.next().ok_or_else(|| {
                                format_err!("missing 'from' path for file rename event")
                            })?;

                            let to = paths.next().ok_or_else(|| {
                                format_err!("missing 'to' path for file rename event")
                            })?;

                            return Ok(Some(to));
                        }
                        RenameMode::From => {