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

Zonemaster::CLI: don’t lose early log messages #416

Open
wants to merge 1 commit into
base: release-v2024.2.1
Choose a base branch
from

Conversation

marc-vanderwal
Copy link
Contributor

@marc-vanderwal marc-vanderwal commented Dec 19, 2024

Purpose

This PR fixes a problem where, in one particular set of circumstances (caused by user error), zonemaster-cli fails to display messages on the terminal.

Adding fake delegation by means of the --ns command-line option can sometimes elicit early Zonemaster::Engine log messages that are lost because the translator isn’t properly initialized at this stage. For reasons that I do not understand fully yet, this situation causes a condition where the zonemaster-cli script displays no message at all, even though it should.

As a workaround for this problem, we set the callback to Zonemaster::Engine::Logger twice. First, we set it to a closure that simply appends them to a queue of yet-to-be-printed messages. Right after the translator is initialized, we print the header and messages stored by the first callback before switching the callback to the function we actually wanted to use, which prints the messages on the terminal.

A brief test shows no unintended side-effects with other output formats such as JSON. But the run() method in Zonemaster::CLI is long and has a high cyclomatic complexity, which doesn’t really help with testing!

Context

Fixes #402.

Changes

  • Buffer messages generated by Zonemaster-Engine before Zonemaster-CLI is fully initialized.

How to test this PR

Run the following command:

zonemaster-cli --level INFO --test basic --ns ns1.zonemaster.net zonemaster.net

zonemaster-cli should display at least one log message complaining about the fake delegation missing required glue. Previously, it would only display the table header and no message at all.

Adding fake delegation by means of the --ns command-line option can
sometimes elicit early Zonemaster::Engine log messages that are lost
because the translator isn’t properly initialized at this stage. For
reasons that I do not understand fully yet, this situation causes a
condition where the zonemaster-cli script displays no message at all,
even though it should.

As a workaround for this problem, we set the callback to
Zonemaster::Engine::Logger twice. First, we set it to a closure that
simply appends them to a queue of yet-to-be-printed messages. Right
after the translator is initialized, we print the header and messages
stored by the first callback before switching the callback to the
function we actually wanted to use, which prints the messages on the
terminal.

A brief test shows no unintended side-effects with other output formats
such as JSON. But the run() method in Zonemaster::CLI is long and has a
high cyclomatic complexity, which doesn’t really help with testing!
@marc-vanderwal marc-vanderwal added T-Bug Type: Bug in software or error in test case description V-Patch Versioning: The change gives an update of patch in version. labels Dec 19, 2024
@marc-vanderwal marc-vanderwal added this to the v2024.2.1 milestone Dec 19, 2024
@matsduf matsduf changed the base branch from develop to release-v2024.2.1 December 19, 2024 10:28
@matsduf
Copy link
Contributor

matsduf commented Dec 19, 2024

Run the following command:

zonemaster-cli --level INFO --test basic01 --ns ns1.zonemaster.net zonemaster.net

zonemaster-cli should display at least one log message complaining about the fake delegation missing required glue. Previously, it would only display the table header and no message at all.

It should display messages from Basic01 too. I think it is better to run "--test Basic" to show that it shows messages from both Basic01 and Basic02.

@marc-vanderwal
Copy link
Contributor Author

It should display messages from Basic01 too. I think it is better to run "--test Basic" to show that it shows messages from both Basic01 and Basic02.

Good idea; I’ve updated the testing procedure in the PR text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Bug Type: Bug in software or error in test case description V-Patch Versioning: The change gives an update of patch in version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zonemaster-cli outputs no message at all if name server given by --ns lacks required glue
2 participants