-
Notifications
You must be signed in to change notification settings - Fork 418
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
tidy -utf interpreted as tidy -u -t -f instead of as -utf8, without error #921
Comments
@bryceharrington, yes, I too would prefer that But historically, the founders of But if someone were to present a patch or a PR, AND after further |
@bryceharrington, seems I may have been far too hasty in my reply... sorry... As I started to look at the issue more closely, I was immediately reminded of the current, perhaps quite unique, style of
So an exit(?) on an error in Such a big change may, or may not be acceptable... And on another point you made, it is quite common to allow command line options to override anything given in a For the power user, that builds And some time ago we rejected a new option, like So, while I look forward to further feedback, comments, in general it seems nothing can be done, at this time, about either issue... sorry... |
@bryceharrington, as mentioned in #681, am quite disturbed about the situation presented there... While I still can not see drastically, dramatically, changing Even with no option errors, or file failures, Parts of the current console /* Read command line */
while ( argc > 0 )
{
if (argc > 1 && argv[1][0] == '-') /* or "--" */
{
/* *** DEAL WITH OPTIONS - '-' or '--' */
--argc;
++argv;
continue;
}
if ( argc > 1 )
htmlfil = argv[1];
/* *** DEAL WITH A FILE */
}
contentErrors += tidyErrorCount( tdoc );
contentWarnings += tidyWarningCount( tdoc );
accessWarnings += tidyAccessWarningCount( tdoc ); /* note: not used! */
--argc;
++argv;
if ( argc <= 1 )
break;
} /* read command line loop */
And then, **after** the complete command line, and all file(s), processed -
/* footnote printing only if errors or warnings */
if ( contentErrors + contentWarnings > 0 )
tidyErrorSummary(tdoc);
/* prints the general info, if applicable */
tidyGeneralInfo(tdoc);
/* called to free hash tables etc. */
tidyRelease( tdoc );
/* return status can be used by scripts */
if ( contentErrors > 0 )
return 2;
if ( contentWarnings > 0 )
return 1;
/* 0 signifies all is ok */
return 0;
} I am now thinking that /* return status can be used by scripts */
if ( fatalErrors > 0 )
return -1
if ( contentErrors > 0 )
return 2;
if ( contentWarnings > 0 )
return 1;
/* 0 signifies all is ok */
return 0;
} And for sure, an This would perpetuate the problem that, in the case of multiple files, you do not know which file caused the problem... but keep the full command line processing, before the exit... But would really assist users who process the files one-by-one, say through a script... hopefully the majority... I will try to find the time to code something along these lines, and present it in a Meantime, look forward to further comments, patches, ideas, ... related to this... especially those strongly for or against ... thanks... |
Hi geoffmcl, thanks for continuing to mull over the issue. I sympathize with the need to balance historical compatibility when considering fixes.
Yes, this seems like it would be a sensible improvement to tidy. The section of code where it prints the "HTML Tidy: unknown option: ..." could increment an unknownOption counter, which could be checked with the others to generate a non-zero exit code like -1. |
20210226: Start @bryceharrington, as you suggest it is related to the code that prints This, in general, is the process I followed - Documentation: See htidy-org \documentation_posts\2000-03-01-part_running.md... There may be several other portions of the Consider an option like -exit-on-error, but prob. with order of command line - rejected for now... and an option to revert this exit change, but again rejected it, for now... Implementation notes:
diff --git a/src/message.c b/src/message.c
index ee2e6c6..aa7f3e8 100644
--- a/src/message.c
+++ b/src/message.c
@@ -169,7 +169,7 @@ static void messageOut( TidyMessageImpl *message )
go = go && message->code != STRING_CONTENT_LOOKS;
go = go && message->code != STRING_NO_SYSID;
go = go && message->level != TidyDialogueInfo;
- go = go && message->level != TidyConfig;
+ /* go = go && message->level != TidyConfig; Is. #921 - these are errors, not informational! */
go = go && message->level != TidyInfo;
go = go && !(message->level >= TidyDialogueSummary &&
message->code != STRING_NEEDS_INTERVENTION);
diff --git a/src/config.c b/src/config.c
index bae56b8..3dd22a0 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1581,7 +1581,10 @@ Bool ParsePickList( TidyDocImpl* doc, const TidyOptionImpl* entry )
return yes;
}
- TY_(ReportBadArgument)( doc, entry->name );
+ /* Is. #921 - this service calls 'GetParsePickListValue', which already emits
+ * 'ReportBadArgument' if it fails, so eliminate this duplicate call
+ * TY_(ReportBadArgument)( doc, entry->name );
+ */
return no;
}
Finally, maybe some error case has been missed, BUT it seems all the major bases covered! In addition to the above 2 patches, console tidy.c patch, so far... diff --git a/console/tidy.c b/console/tidy.c
index 3a3d9ad..f5eb22a 100644
--- a/console/tidy.c
+++ b/console/tidy.c
@@ -49,6 +49,8 @@ static FILE* errout = NULL;
** @{
*/
+/** Fatal error count - like bad option, no files, etc - Exit -1 */
+static uint errorCount = 0; /* Is. #921 */
/* MARK: - Miscellaneous Utilities */
/***************************************************************************//**
@@ -2123,6 +2125,7 @@ int main( int argc, char** argv )
if ( status != 0 ) {
fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_CONFIG_FILE, status);
fprintf(errout, "\n");
+ errorCount++; /* Is. #921 - config file failed */
}
}
#endif /* TIDY_CONFIG_FILE */
@@ -2133,6 +2136,7 @@ int main( int argc, char** argv )
if ( status != 0 ) {
fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), cfgfil, status);
fprintf(errout, "\n");
+ errorCount++; /* Is. #921 - config file failed */
}
}
#ifdef TIDY_USER_CONFIG_FILE
@@ -2142,6 +2146,7 @@ int main( int argc, char** argv )
if ( status != 0 ) {
fprintf(errout, tidyLocalizedString( TC_MAIN_ERROR_LOAD_CONFIG ), TIDY_USER_CONFIG_FILE, status);
fprintf(errout, "\n");
+ errorCount++; /* Is. #921 - config file failed */
}
}
#endif /* TIDY_USER_CONFIG_FILE */
@@ -2479,6 +2484,7 @@ int main( int argc, char** argv )
default:
unknownOption( tdoc, c );
+ errorCount++; /* Is. #921 - option error */
break;
}
}
@@ -2506,6 +2512,8 @@ int main( int argc, char** argv )
if ( tidyOptGetBool(tdoc, TidyEmacs) || tidyOptGetBool(tdoc, TidyShowFilename))
tidySetEmacsFile( tdoc, htmlfil );
status = tidyParseFile( tdoc, htmlfil );
+ if (status < 0) /* Is. #921 - input file failed */
+ errorCount++;
}
else
{
@@ -2547,6 +2555,7 @@ int main( int argc, char** argv )
contentErrors += tidyErrorCount( tdoc );
contentWarnings += tidyWarningCount( tdoc );
accessWarnings += tidyAccessWarningCount( tdoc );
+ errorCount += tidyConfigErrorCount( tdoc); /* Is. #921 - config error are fatal */
--argc;
++argv;
@@ -2568,8 +2577,16 @@ int main( int argc, char** argv )
/* called to free hash tables etc. */
tidyRelease( tdoc );
-
+
/* return status can be used by scripts */
+
+ /* Is. #921 - one, or more fatal errors */
+ /* this can be many forms, from file does not exit, to an unknown option,
+ * or malformed option, etc ...
+ */
+ if (errorCount > 0)
+ return -1; /* Is. #921 */
+
if ( contentErrors > 0 )
return 2;
Regression Tests: Running the regression tests, using this Case 431716 is a test of an unknown Case 629 is also a test of a config item, Still to do some more testing, but this is starting to look good to go! Will get around to pushing this Meantime look forward to any feedback, comments, ideas, patches, etc... thanks... |
20210303: @bryceharrington, have now pushed the Appreciated if you, and others, in various distros, could pull, and test this
Certainly with this I recognize this is a bit of a compromise, since On the option Look forward to further feedback, comments, ideas, patches, testing, etc... thanks... |
Created PR #931 for testing, feedback, etc ... thanks... |
Looking at patch, I have a couple of issues. Mostly, for exit status to be portable, it can only range from 0 to 255. This is easily fixed, however. More importantly, if we're treating a bad config option as a failure, why are we still generating output? Shouldn't this be dependent on |
Forwarding a usability issue reported by a Ubuntu user, from https://bugs.launchpad.net/ubuntu/+source/tidy-html5/+bug/1914865
Running
tidy -utf ...
is treated astidy -u -t -f ...
, rather than astidy -utf8
as the user intended.$ echo "" | tidy > /tmp/test.html
$ tidy -utf /tmp/test.html > /dev/null
HTML Tidy: unknown option: t
HTML Tidy: unknown option: f
...
$ echo $?
0
The -u option is synonymous with -upper, producing upper-cased tags in the output, which causes unexpected results particularly if one has set "uppercase-tags: no" in ~/.tidyrc, such as in the original bug report.
It might help if tidy returned a non-zero exit code when invoked with unrecognized options. (Even better might be to exit immediately with a usage message.) Then the warnings would be more visible and the user might be able to figure out their error.
The text was updated successfully, but these errors were encountered: