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

Ignore inaccessible config file unless its path was specified as --config=... #312

Merged

Conversation

evan-goode
Copy link
Member

Ignore a missing or otherwise inaccessible /etc/dnf/dnf.conf instead of throwing an error.

If the user specifies the path to the config file on the command line, like dnf --config=/path/to/dnf.conf, then an error will still be thrown and displayed.

Similarly, if the config file is accessible but malformed/invalid, an error will still be thrown.

Resolves #305

@evan-goode evan-goode force-pushed the evan-goode/missing-conf branch from 3e53d24 to 637165d Compare February 22, 2023 21:48
@evan-goode
Copy link
Member Author

Moved the new error definitions to include/libdnf/common/exception.hpp; they wouldn't compile in base.hpp for some reason.

@evan-goode evan-goode marked this pull request as ready for review February 22, 2023 21:51
libdnf/repo/repo_sack.cpp Outdated Show resolved Hide resolved
@evan-goode evan-goode force-pushed the evan-goode/missing-conf branch from 637165d to b9f6efa Compare February 23, 2023 13:39
using Error::Error;
const char * get_domain_name() const noexcept override { return "libdnf::base"; }
const char * get_name() const noexcept override { return "InvalidConfigError"; }
};
Copy link
Member

@m-blaha m-blaha Feb 27, 2023

Choose a reason for hiding this comment

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

It seems to me that these specific errors do not fit in this header file where more general errors are defined.
include/libdnf/conf/config_parser.hpp might be a better fit for them, what do you think?
After all, config parser is the place where these exceptions have their roots. Maybe, they can be even handled / thrown directly in the ConfigParser::read()?

Copy link
Member

Choose a reason for hiding this comment

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

In case of adding the exceptions into some header which is already included in SWIG, like the include/libdnf/conf/config_parser.hpp, make sure to ignore these exceptions in related *.i file, otherwise it won't compile, e.g. in conf.i the following should do the trick:

%ignore libdnf::InaccessibleConfigError;
%ignore libdnf::InvalidConfigError;

@m-blaha m-blaha self-assigned this Feb 27, 2023
@evan-goode evan-goode force-pushed the evan-goode/missing-conf branch from b9f6efa to c1a531f Compare February 28, 2023 22:07
@evan-goode evan-goode force-pushed the evan-goode/missing-conf branch from c1a531f to 6ca197c Compare February 28, 2023 22:30
@evan-goode
Copy link
Member Author

I moved the error declarations to include/libdnf/conf/config_parser.hpp, and they are now thrown from ConfigParser::read, per @m-blaha's suggestion.

@m-blaha
Copy link
Member

m-blaha commented Mar 1, 2023

Thank you!

@m-blaha m-blaha merged commit 2dfcb47 into rpm-software-management:main Mar 1, 2023
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 thrown when loading a non-existent config file
3 participants