-
Notifications
You must be signed in to change notification settings - Fork 17
Refactor ingredient handler error logging #385
Comments
Thanks for writing this up, Will. I think you've captured all the big issues with messages here. On the topic of inconsistently calling "first message":
This is by design and we should probably always log two messages (i.e., the missing Compat message call is a bug), when we find evidence of a malformed ingredient. We discussed this a bit in the PR where this pattern was introduced. Your comment here captures a bit of the thinking behind it: #320 (review). But to get into this in more detail… I'd argue we should have two messages for malformed ingredients, for two reasons:
Of course, you might have already addressed this in the refactoring PR. I'll start reviewing that now. |
"when we find evidence of a malformed ingredient" - is the suggestion: (1) that we should log two messages except when the ingredient is "just missing", in which case we should only log one? Or (2) that we should always log two messages? If (1) , I worry that "just missing" is a slippery concept. Generally it seems to mean "doesn't even have an H2" but really that seems a little artificial. If it has If (2), I'm more happy with that, but I'm not sure the generic "Missing..." message adds a lot. For example, with the current linter, the output for https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries is:
The error is because the recipe lists
As a maintainer of this doc, I'd prefer a more specific message, telling me that we looked for
... does the extra Especially if the ID is consistently formed like
Yes, and I'm sorry to relegislate this. I guess I have just thought about this a bit more and have more opinions.
I think there's something in this, but I"m not sure how would this looks for optional ingredients. Here, a "Missing..." error message is not applicable of course (although actually, I would be more likely to want an info message for these, like "optional ingredient XYZ omitted", than an error message for missing mandatory ingredients). So if a page attempts to include an ingredient, according to our heuristic (e.g. it includes an
...or something like that? So I guess, with these questions, it feels simpler to log just one message, try to make it as actionable as possible, and make sure it always refers to a recipe/ingredient combination. |
OK, I'm convinced. I'd still like a quick way to aggregate recipe problems, but I guess this is something I should fix with a shell script instead of the rules themselves. 👍 |
Fixed by #386. |
Currently we have one utility function for ingredient handlers to log errors,
logMissingIngredient
. This takes three arguments:source
: which in the ingredient handlers is always "html-require-ingredient". This should have a more obvious name.recipeName
: the name of the recipeingredient
: the name of the ingredientIt logs a message like "Missing from ${recipeName}: ${ingredient}", and an identifier that combines
source
,recipeName
, andingredient
.This is called from ingredient handlers when a mandatory ingredient can't be found. Often, this call is preceded by another logging call like this:
So I guess the idea here is that the first message provides details of exactly why we couldn't find the ingredient, and the second message provides an overview of what the problem was (i.e. which ingredient was missing).
Issues
There are a few issues here.
Duplicated "first message" code
There's a very repetitive pattern in the many places where we log two messages:
Apart from just making code longer and harder to read, this is going to make it very hard for us to log messages consistently. So we should have a utility function for this.
"first message" is not consistently called
As we saw, usually there are two messages: one that gives specifics about why the linting failed (like, a particular macro could not be found), and one that gives a general messages about the ingredient that was missing.
Sometimes the first message is not logged, and only
logMissingIngredient
is called. For example: https://github.com/mdn/stumptown-content/blob/master/scripts/scraper-ng/rules/html-require-recipe-ingredients/ingredient-handlers/index.js#L61-L63 or https://github.com/mdn/stumptown-content/blob/master/scripts/scraper-ng/rules/html-require-recipe-ingredients/ingredient-handlers/data-browser-compatibility.js#L34-L36.Is this by design, or should we always log two messages? I don't see why we log a specific message when the specName macro is missing but not when the Compat macro is missing.
Maybe we should only log one message, which always gives the extra detail?
Passing state around
Because the logging functions want lots of arguments, that's a lot of state we have to pass around. The more handlers we write, and the more complex they get, the more this is going to be an issue.
logMissingIngredient
doesn't work for badly-formed ingredientslogMissingIngredient
works for mandatory ingredients. But now we want to lint optional ones, likedata.static_methods
. There, we probably want to log something like "Incorrect ingredient" rather than "Missing". Should we add an extra parameter tologMissingIngredient
, so we can do that, and rename it?The text was updated successfully, but these errors were encountered: