Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Findex panics when ApplicationCommand::Command variants RString is empty #46

Closed
Longestboi opened this issue Nov 6, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Longestboi
Copy link
Contributor

Description

When passing an empty Rstring to ApplicationCommand::Command in the return RVec<FResult> of a plugins handle_query function, Findex panics at crates/findex/src/gui/result_list_row.rs:136:42.

Do you already have Findex Installed? (If yes, how did you install?)

I have installed Findex with the automated method detailed in INSTALLATION.md.
Also, to test and attempt to fix the issue, I cloned the repo and ran Findex in release mode.

To Reproduce

Return this from a plugins handle_query function:

RVec::from(vec![FResult {
    cmd: ApplicationCommand::Command(RString::new()),
    name: "No Command",
    desc: RNone,
    score: size::MAX,
    icon: RString::new()
}])

Expected behavior

For the program to execute no command

System information

  • Distro: Ubuntu 22.04.2
  • Findex Version: development

Output of rustc --version --verbose (if you compiled findex on your machine):

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

Additional context

To fix this issue, I added the below code above result_list_row.rs:132:

if cmd.is_empty() {
    return;
}

I'm not sure if returning when the cmd RString is empty would be the most optimal solution. Adding a None variant to the ApplicationCommand enum or wrapping cmd in an ROption could be better options. Both would break plugins, either requiring recompilation or rewriting and recompilation, though.

@Longestboi Longestboi added the bug Something isn't working label Nov 6, 2023
@mdgaziur
Copy link
Owner

mdgaziur commented Nov 8, 2023

Hi, thanks for reporting this issue! I think, it'd be better to add a None variant to ApplicationCommand. That'll require minimal amount of changes in the codebase.

@mdgaziur
Copy link
Owner

mdgaziur commented Nov 8, 2023

I think this fix will open the door to making plugins like calculator, currency converter etc without Findex crashing every time the user presses enter.

mdgaziur added a commit that referenced this issue Nov 9, 2023
Added a None variant to let plugins explicity give no-op results and a
check to ensure that Findex doesn't crash empty command.
@mdgaziur
Copy link
Owner

mdgaziur commented Nov 9, 2023

Should be fixed now in 46e977f

@mdgaziur mdgaziur closed this as completed Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants