Repository: microsoft/onefuzz
File: src/agent/onefuzz-task/src/tasks/coverage/generic.rs (Rust)

Code before:

        self.config.coverage.init_pull().await?;

        let coverage_file = self.config.coverage.local_path.join(COVERAGE_FILE);

        let coverage = {
            if let Ok(text) = fs::read_to_string(&coverage_file).await {
                let json = BinaryCoverageJson::deserialize(&text)?;
                BinaryCoverage::try_from(json)?
            } else {
                BinaryCoverage::default()
            }
        };

        let allowlist = self.load_target_allowlist().await?;

        let heartbeat = self.config.common.init_heartbeat(None).await?;

        let mut seen_inputs = false;

        let target_exe_path =
            try_resolve_setup_relative_path(&self.config.common.setup_dir, &self.config.target_exe)
                .await?;
        let target_exe = target_exe_path
            .to_str()
            .expect("Failed to resolve target_exe relative path");

        let mut context = TaskContext::new(
            &self.config,
            coverage,
            allowlist,
            heartbeat,
            target_exe.to_string(),
        )?;

        if !context.uses_input() {
            bail!("input is not specified on the command line or arguments for the target");
        }

        context.heartbeat.alive();

        for dir in &self.config.readonly_inputs {
            debug!("recording coverage for {}", dir.local_path.display());

            dir.init_pull().await?;
            let dir_count = context.record_corpus(&dir.local_path).await?;

            if dir_count > 0 {
                seen_inputs = true;
            }


Review comment (suggestion):
This should currently be unreachable, since we deserialized `target_exe` from a JSON file. However, in case things change, let's convert to a `Result` with an accurate error message:
```suggestion
            .ok_or_else(|| anyhow::format_err!("target exe path is not valid unicode"))?;
```

Code after:

        self.config.coverage.init_pull().await?;

        let coverage_file = self.config.coverage.local_path.join(COVERAGE_FILE);

        let coverage = {
            if let Ok(text) = fs::read_to_string(&coverage_file).await {
                let json = BinaryCoverageJson::deserialize(&text)?;
                BinaryCoverage::try_from(json)?
            } else {
                BinaryCoverage::default()
            }
        };

        let allowlist = self.load_target_allowlist().await?;

        let heartbeat = self.config.common.init_heartbeat(None).await?;

        let mut seen_inputs = false;

        let target_exe_path =
            try_resolve_setup_relative_path(&self.config.common.setup_dir, &self.config.target_exe)
                .await?;
        let target_exe = target_exe_path
            .to_str()
            .ok_or_else(|| anyhow::format_err!("target_exe path is not valid unicode"))?;

        let mut context = TaskContext::new(
            &self.config,
            coverage,
            allowlist,
            heartbeat,
            target_exe.to_string(),
        )?;

        if !context.uses_input() {
            bail!("input is not specified on the command line or arguments for the target");
        }

        context.heartbeat.alive();

        for dir in &self.config.readonly_inputs {
            debug!("recording coverage for {}", dir.local_path.display());

            dir.init_pull().await?;
            let dir_count = context.record_corpus(&dir.local_path).await?;

            if dir_count > 0 {
                seen_inputs = true;
            }