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

Removes the panic, throws a warning & returns an empty list, which should be expected behavior #73

Merged
merged 2 commits into from
Sep 29, 2023

Conversation

joao-vitor-sr
Copy link
Contributor

@joao-vitor-sr joao-vitor-sr commented Feb 20, 2023

fix: #55

Copy link

@Sntx626 Sntx626 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does improve the error message and provide a possible fix, however I think the panic should be avoided.

src/main.rs Outdated
@@ -178,7 +178,7 @@ fn main() -> crossterm::Result<()> {

if opt.list_languages {
opt.languages()
.expect("Couldn't get installed languages under config directory. Make sure the config directory exists.")
.expect("Couldn't get installed languages under the config directory. Make sure the config and language directory exist.")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This improves the error message.
However I agree with @omarkohl, the message should be printed as a warning and return an empty list with .or_else(vec![]).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there's no logging this could look like the following:

    if opt.list_languages {
        opt.languages()
            .or_else({
                println!("Warning: Couldn't get installed languages under config directory. Make sure the config directory exists.");
                vec![]
            })
            .iter()
            .for_each(|name| println!("{}", name.to_str().expect("Ill-formatted language name.")));
        return Ok(());
    }

@joao-vitor-sr joao-vitor-sr changed the title refactor(errors): better message when languaage directory doesn't exist refactor(errors): better handling of the languages directory Apr 8, 2023
@@ -177,8 +177,13 @@ fn main() -> crossterm::Result<()> {
}

if opt.list_languages {
opt.languages()
.expect("Couldn't get installed languages under config directory. Make sure the config directory exists.")
match opt.languages() {
Copy link
Contributor Author

@joao-vitor-sr joao-vitor-sr Apr 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since or_else methods on results don't return a default value, an if or a match is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(improving the explanation) the or_else will return another Result which has to be handled.

Copy link

@Sntx626 Sntx626 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good!
Removes the panic, throws a warning & returns an empty list, which should be expected behavior.
-> Approved

@joao-vitor-sr joao-vitor-sr changed the title refactor(errors): better handling of the languages directory Removes the panic, throws a warning & returns an empty list, which should be expected behavior Apr 12, 2023
Copy link
Owner

@max-niederman max-niederman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@max-niederman max-niederman merged commit 237223e into max-niederman:main Sep 29, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when .config/ttyper/language directory does not exist
3 participants