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

Fixes an outrageous number of bugs and warnings #90

Merged
merged 23 commits into from
Jan 13, 2025
Merged

Conversation

viniciusferrao
Copy link
Owner

No description provided.

@viniciusferrao viniciusferrao self-assigned this Jan 8, 2025
@viniciusferrao viniciusferrao marked this pull request as draft January 8, 2025 21:52
Copy link
Owner Author

@viniciusferrao viniciusferrao left a comment

Choose a reason for hiding this comment

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

@dhilst can you check?

@@ -45,7 +40,12 @@
if (spdlog::get(productName) != nullptr) { \
spdlog::get(productName)->info(__VA_ARGS__); \
}

#define LOG_ABORT_IF(cnd, msg) \
Copy link
Owner Author

@viniciusferrao viniciusferrao Jan 10, 2025

Choose a reason for hiding this comment

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

I don't like the idea of adding logic to a macro.

The idea here is to just print the logs. That's the single responsibility. If you need to do a check, do it on code, print a log an then exits.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-macros2

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay I'll remove the macro.

src/os.cpp Outdated
if (version.find('.') != std::string::npos) {
LOG_ABORT("system version (in the answerfile.yml) must follow the format M.N, where M is the major version number and N is the minor version number.");
}
LOG_ABORT_IF(version.find('.') == std::string::npos,
Copy link
Owner Author

Choose a reason for hiding this comment

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

That's what I'm talking about. Use a if statement and does not hide it behind a macro.

src/repos.cpp Outdated
try {
std::filesystem::copy(dir_entry, "/etc/yum.repos.d");
} catch (std::filesystem::filesystem_error const& ex) {
if (ex.code().message().starts_with("File exists")) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

We must not compare string to handle errors. That's very bad design. Text can change, and the language of the glibc may also changes this. We need to aim for portability so a better implementation is to compare the error return code, like this:

if (ex.code().default_error_condition() == std::errc::file_exists) {
	continue;
}

// If it's not "file exists", maybe rethrow or handle differently
std::cerr << "Copy failed: " << ex.what() << '\n';
// handle or rethrow

Comment on lines 27 to 31
#define LOG_ABORT(...) \
if (spdlog::get(productName) != nullptr) { \
spdlog::get(productName)->critical(__VA_ARGS__); \
std::exit(-1); \
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

The macro must not exit. That's not the responsibility of this macro.

@dhilst dhilst self-assigned this Jan 10, 2025
* Fix typos in the documentation.
* Fix typos on LOG messages.
* Change variable names to be more accurate with the context.
* Rethrow should also follow the golden rule of: throw by value and catch by reference.

Signed-off-by: Vinícius Ferrão <[email protected]>
@viniciusferrao viniciusferrao changed the title Fixes an outragous number of bugs and warnings Fixes an outrageous number of bugs and warnings Jan 10, 2025
src/os.cpp Outdated
LOG_CRITICAL("Unexpected value for system.version (in answerfile.ini). "
"Expected M.N format, e.g., 9.5. Value found instead: {}",
version);
std::exit(-1);
Copy link
Owner Author

Choose a reason for hiding this comment

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

I don't like this explicit std::exit here. I think this should be an exception and let the exception handler unroll the stack and call std::terminate if it does not find any point of recovery.

It's not the responsibility of this class to call std::exit.

However I didn't changed that myself because I would like to discuss it first.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, should we have our exception for this or reuse some of the stl?

@dhilst
Copy link
Collaborator

dhilst commented Jan 11, 2025

I fixed all the warnings, the tool is running to the end and the node is booting
image

Now we can focus on the code quality issues

@dhilst dhilst marked this pull request as ready for review January 13, 2025 14:34
This change will keep the project more reliable while
still getting updates from upstream on minor versions.

Signed-off-by: Vinícius Ferrão <[email protected]>
This workflow is broken, let's see if an update will fix it.

Signed-off-by: Vinícius Ferrão <[email protected]>
Signed-off-by: Vinícius Ferrão <[email protected]>
Signed-off-by: Vinícius Ferrão <[email protected]>
@@ -45,7 +40,12 @@
if (spdlog::get(productName) != nullptr) { \
spdlog::get(productName)->info(__VA_ARGS__); \
}

#define LOG_ABORT_IF(cnd, msg) \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay I'll remove the macro.

src/os.cpp Outdated
LOG_CRITICAL("Unexpected value for system.version (in answerfile.ini). "
"Expected M.N format, e.g., 9.5. Value found instead: {}",
version);
std::exit(-1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, should we have our exception for this or reuse some of the stl?

@viniciusferrao viniciusferrao merged commit 168e99d into master Jan 13, 2025
4 checks passed
@viniciusferrao viniciusferrao deleted the fix-bugs branch January 13, 2025 21:04
@dhilst
Copy link
Collaborator

dhilst commented Jan 13, 2025

🚀

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