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

Improve rendering of error messages & fix record to map conversion #1842

Merged
merged 12 commits into from Aug 17, 2021

Conversation

tobim
Copy link
Member

@tobim tobim commented Aug 12, 2021

📔 Description

Best illustrated with a demo:
Old:

[22:45:53.372] failed to initialize plugins: !! unspecified: "failed to initialize plugin inventory: !! invalid_configuration: \"failed to apply config: !! convert_error: \\\"scope(\\\\\\\"[3](\\\\\\\\\\\\\\\"unable to parse \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"blahbal\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" into a vast.subnet\\\\\\\\\\\\\\\")\\\\\\\")\\\"\" "

New:

[23:01:15.022] failed to initialize plugins: !! unspecified: failed to initialize the inventory plugin: !! invalid_configuration: failed to apply config: !! convert_error: scope[3]: unable to parse "blahbal" into a vast.subnet

📝 Checklist

  • All user-facing changes have changelog entries.
  • The PR description contains instructions for the reviewer, if necessary.

🎯 Review Instructions

Commit-by-commit. Should be self-explanatory.

@tobim tobim requested a review from a team August 12, 2021 21:05
@@ -70,7 +70,7 @@ caf::error insert_to_map(To& dst, typename To::key_type&& key,
else
// TODO: Consider continuing if the old and new values are the same.
return caf::make_error(ec::convert_error,
fmt::format("{}: redefinition detected: \"{}\" "
fmt::format(": redefinition of {} detected: \"{}\" "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fmt::format(": redefinition of {} detected: \"{}\" "
fmt::format("redefinition of {} detected: {} "

Why not this?

Copy link
Member

Choose a reason for hiding this comment

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

I am not a fan of beginning the error context with a colon either. If you want to make this a thing @tobim then please make it consistently throughout the code base by adding the colon in the error rendering function.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is not even an option, because it destroys composition.

Copy link
Member Author

Choose a reason for hiding this comment

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

The data conversion overloads are a special case because the message will almost always get prepended with the path that leads to the location of the error. The desired output should be

convert_error: foo.bar[2].baz: redefinition of key detected: "A" vs "B"

I'm open to ideas for how to implement that without the need to add the colon to the inner message.

Copy link
Member

Choose a reason for hiding this comment

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

You can add the colon when rendering nested errors, just like you special-case std::string in error contexts now.

@@ -318,7 +327,7 @@ caf::error convert(const list& src, To& dst, const list_type& t) {
for (const auto& element : src) {
const auto* rec = caf::get_if<record>(&element);
if (!rec)
return caf::make_error(ec::convert_error, "no record in list");
return caf::make_error(ec::convert_error, ": no record in list");
Copy link
Member

Choose a reason for hiding this comment

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

This seems inside out: adding such context is the job of the calling context, no?

This change removes the insertion of backslashes from log messages
that print the content of a `caf::error`. Since errors can be
nested some log messages would contain 3 or even 7 consecutive
backslashes.
This turns the visitor in the conversion inspector into a double
dispatch. Doing so is necessary to catch convert overloads that
don't apply to matching data / type pairs. For example record fields
that contained another record weren't converted to maps with the
correct overload before.
@tobim tobim changed the title Improve rendering of error messages Improve rendering of error messages & fix record to map conversion Aug 16, 2021
@mavam
Copy link
Member

mavam commented Aug 16, 2021

@dominiklohmann can you take the review from here? Let's address the : issue in a separate PR.

@tobim tobim enabled auto-merge August 17, 2021 09:10
@tobim tobim merged commit 3fab8a2 into master Aug 17, 2021
@tobim tobim deleted the topic/nicer-errors branch August 17, 2021 09:10
dominiklohmann added a commit that referenced this pull request Aug 17, 2021
A recent oversight in #1842 broke the build (again). We must
use `VAST_FMT_RUNTIME` for format strings that cannot be verified at
compile time, e.g., because they are not constant.
@dominiklohmann dominiklohmann mentioned this pull request Aug 17, 2021
3 tasks
lava pushed a commit that referenced this pull request Aug 18, 2021
A recent oversight in #1842 broke the build (again). We must
use `VAST_FMT_RUNTIME` for format strings that cannot be verified at
compile time, e.g., because they are not constant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants