Skip to content

Commit

Permalink
Improvements around forc plugins command (FuelLabs#1969)
Browse files Browse the repository at this point in the history
Use the full path of the plugin when parsing it for a description.

This avoids the following panic caused by trying to exec an executable
in a sub-folder with a partial path:

```
~/dev/sway/target/debug$ forc plugins
Installed Plugins:
thread 'main' panicked at 'Could not get plugin description.: Os { code:
2, kind: NotFound, message: "No such file or directory" }',
forc/src/cli/commands/plugins.rs:43:10
stack backtrace:
   0: rust_begin_unwind
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
   2: core::result::unwrap_failed
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5
   3: core::result::Result<T,E>::expect
at
/rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1035:23
   4: forc::cli::commands::plugins::parse_description_for_plugin
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:40:16
   5: forc::cli::commands::plugins::format_print_description
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:81:23
   6: forc::cli::commands::plugins::print_plugin
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:97:5
   7: forc::cli::commands::plugins::exec
at
/home/joao/dev/sway/forc/src/cli/commands/plugins.rs:28:21
```
  • Loading branch information
tritao authored Jun 29, 2022
1 parent 753639c commit 92ec0a6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions forc/src/cli/commands/plugins.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cli::PluginsCommand;
use anyhow::{anyhow, Result};
use clap::Parser;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use tracing::info;

/// Find all forc plugins available via `PATH`.
Expand Down Expand Up @@ -32,9 +32,9 @@ pub(crate) fn exec(command: PluginsCommand) -> Result<()> {

/// Find a plugin's description
///
/// Given a plugin name, returns the description included in the `-h` opt. Returns
/// a generic description if a description cannot be found
fn parse_description_for_plugin(plugin: &str) -> String {
/// Given a cannonical plugin path, returns the description included in the `-h` opt.
/// Returns a generic description if a description cannot be found
fn parse_description_for_plugin(plugin: &Path) -> String {
use std::process::Command;
let default_description = "No description found for this plugin.";
let proc = Command::new(plugin)
Expand Down Expand Up @@ -78,7 +78,7 @@ fn format_print_description(
.to_string()
};

let description = parse_description_for_plugin(&display);
let description = parse_description_for_plugin(&path);

if describe {
Ok(format!(" {} \t\t{}", display, description))
Expand Down

0 comments on commit 92ec0a6

Please sign in to comment.