Skip to content

Message Handling "cleanup" #561

Closed
Closed
@balthisar

Description

@balthisar

I started to write this in response to #412, but it's actually a broader issue, and I'd like to spur some discussion on a bit of refactoring to simplify Tidy, as well as address #412.

In #412, we're looking for a way to allow Tidy to show additional information whenever it performs any type of fix, including the fixes that are currently "quiet" fixes. The original proposal was to add another new configuration option to the mix. Instead, I'd like to step back and see if we can simplify this completely.

Currently we have messages categorized per this enum:

typedef enum
{
    TidyInfo = 350,       /**< Report: Information about markup usage */
    TidyWarning,          /**< Report: Warning message */
    TidyConfig,           /**< Report: Configuration error */
    TidyAccess,           /**< Report: Accessibility message */
    TidyError,            /**< Report: Error message - output suppressed */
    TidyBadDocument,      /**< Report: I/O or file system error */
    TidyFatal,            /**< Report: Crash! */
    TidyDialogueInfo,     /**< Dialogue: Non-document related information */
    TidyDialogueSummary,  /**< Dialogue: Summary-related information */
    TidyDialogueDoc,      /**< Dialogue: Document-related information */
} TidyReportLevel;

Nominally only TidyWarning and TidyError result in a non-zero exit code from the CLI, although file errors and the like can change the exit code, too.

The TidyInfo isn't used very much; perhaps it should be used a little bit more for cases like this, i.e., "silent changes" become TidyInfo messages that we can handle appropriately. Or maybe we insert a new category between TidyInfo and TidyWarning, e.g., `TidyTouchup" or something.

Before considering yet another new option, though, what do we already have?

  • show-info will squelch any TidyInfo messages, but it also squelches some of the "dialogue-like" output that Tidy delivers (the new TidyDialogueInfo) category.
  • show-warnings can be used to hide the warnings
  • show-errors isn't a boolean, but places a limit to the amount of errors that will be output, and setting this to zero does squelch all errors. Now the thing about show-errors is that it only limits errors, not warnings or info. So if you set show-errors to, say, 10, but have 100 warnings, you'll still see all of them.

If you're using a callback filter, none of these options have any effect, as it becomes the responsibility of the host program to implement all of this functionality.

All of the document-related messages are generated and output in the order they are detected during Tidying, so the message-table output is a mix of warnings and errors, and not necessarily in document line number order (e.g., from the lexer, from the parser, from the post-processing that Accessibility produces).

Tidy's output is also mixed in that document-related messages can be interspersed with operational messages. For example, missing config file isn't related to a document issue but precedes the document information table. The Accessibility message interrupts the document message table for no good reason, and finally summary information and other dialogue-type information is added at the end.

So, what would we do if we were starting from scratch?

What I would do is eliminate all of these filtering and limited functions from LibTidy completely, and move them to the CLI, and let the CLI handle this stuff just like any other LibTidy user is expected to do. I tend to think that this would be an unpopular move, though, and it would complicate configuration files, and we have a rich history of allowing these options in the config file. So, I won't go there.

I think we need to carefully define the granularity that is expected from document messages versus dialogue messages, and attack them separately.

To handle the document messages, I suggest that we eliminate show-warnings and show-info entirely, and replace show-errors with something else. Instead, we have a new show-document-messages option with the values possible values of "None" or "Quiet", "Errors", "Warnings", and "Info", each of which show progressively more information.

  • "None" or "Quiet" shows no document messages at all.
  • "Errors" shows only errors.
  • "Warnings" shows errors and warnings. This would be default.
  • "Info" shows everything.

I would also buffer all of the document message output, and emit it in line and column number order instead of the current order, which is line and column order for each piece of Tidy handling the code. I don't think we support any embedded systems with such little memory that we can't spare a few K to hold document messages in memory until we're done Tidying, so that we can sort them. However, is a bit tricky because tidyParseFile() (or stdin), tidyCleanAndRepair(), and tidyRunDiagnostics() each produce their own messages. Maybe for a "phase 2" down the line...

show-errors would also be replaced with limit-document-messages which limits the number of messages, not just the number of errors.

Moving on, there are also several other types of non-document messages that are one of the "dialogue" message types. Things such as reporting missing config files, giving helpful information, giving the error count summary, showing information about Tidy, are all "dialogue" type messages. Right now both show-info and quiet affect these, but it's not currently clearly, logically defined what and why certain pieces of this information is hidden.

Maybe we replace quiet and show-info with another enum type option, e.g., "show-other-messages" with values that bring some sanity to this.

  • "None" or "Quiet" shows nothing, except for errors (such as missing config files) that we must report.
  • "Summary" shows only the summary.
  • "Messages" shows the summary and other helpful messages.
  • "All" shows the summary, helpful messages, and the Tidy information. This would be default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions