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

Raising error on missing configuration file inclusion #3498

Merged
merged 7 commits into from
Feb 25, 2020

Conversation

adamjakab
Copy link
Contributor

I think it is better to know than ignoring it silently. I don't know how you feel about this but I am requesting this PR because I lost a good deal of time convinced that my configuration was read only to discover that I mistyped the path. We could also opt for a 'softer' warning...

@sampsyo
Copy link
Member

sampsyo commented Feb 23, 2020

It seems fine to add a warning along these lines! I think I'd lean toward just a warning, however, rather than exiting with a traceback. Also, note that we already handle NotFoundError—maybe we should just print the message there instead of adding a new handler?

@adamjakab
Copy link
Contributor Author

Ok for the warning (no traceback) part. However, I think the decision to make here is if a missing configuration file constitutes to a bad-enough situation for which we want to interrupt the execution or not. In my opinion it does because the application would behave differently from how I would expect it to do with all the configuration files loaded.

@sampsyo
Copy link
Member

sampsyo commented Feb 23, 2020

I guess I feel pretty agnostic about that precise distinction? But one argument for leaving it as a warning is to be less disruptive to people who were relying on the old behavior, who will now just get a warning when they run beets instead of being prevented from running it altogether… you could have an import in there that just points to a placeholder location that is only sometimes filled with an actual config file, for example.

@adamjakab
Copy link
Contributor Author

Ok. I see your point. Let's go with a simple warning then.

@adamjakab
Copy link
Contributor Author

adamjakab commented Feb 24, 2020

This, with the following configuration:

include: 
    - inexistent.yml

produces:

$ ./beet
Warning! Missing configuration file! [Errno 2] No such file or directory: '/Users/jackisback/.config/beets/DEVEL/inexistent.yml'
Usage: 
  beet COMMAND [ARGS...]
  beet help COMMAND
...

and beets keeps running happily ;)

However, it does not catch badly formatted configuration files. With:

include: 
    - badformat.yml

and with the 'badformat.yml' file:

this
    will
        not
            pass
        as
    ok
yml

I expected the same warning to show because the confuse.load_yaml() function throws a ConfigReadError. It does not. This is what I get:

$ ./beet
configuration error: musicbrainz.host not found

and beets exits. But maybe this needs a separate PR.

@sampsyo
Copy link
Member

sampsyo commented Feb 24, 2020

Great; thanks for continuing to sort this out!

A few random things:

  • I wish we could use logging instead of print, but I think that would necessitate an impossible circular import. 😢
  • Barring that, let's at least print to stderr instead of stdout.
  • I recommend this somewhat terser error message: "configuration `import` failed: "

I am also a tad confused by the issue with the malformed YAML… I would have expected that to throw an error too. Maybe we should dig into why that's not happening!

@adamjakab
Copy link
Contributor Author

Sure, no worries.

As for the malformed yaml issue I will open a separate issue (also referencing this PR) and we can dig into it. It seems odd.

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Looking good! Could you please add a quick changelog entry?

@adamjakab
Copy link
Contributor Author

Could you please add a quick changelog entry?

Hi @sampsyo. This one: docs/changelog.rst? Can you please give me an advice on what editor to use to edit rst files? I have not used this format before and I don't want to mess it up. tnx

@sampsyo
Copy link
Member

sampsyo commented Feb 25, 2020

Looks like you got it; thanks!!

I don't have specific text editor recommendations for editing ReST files (I just use vim 😃), but you might consider previewing changes to the docs. You can generate the HTML files by typing make html in the docs directory, which likely will require you to install Sphinx.

@sampsyo sampsyo merged commit 69c3ba4 into beetbox:master Feb 25, 2020
sampsyo added a commit that referenced this pull request Feb 25, 2020
@adamjakab adamjakab deleted the dev-cfg-inc branch March 1, 2020 22:40
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.

2 participants