From e607de0b9143b131cc292eac2e2a37f74b3333bf Mon Sep 17 00:00:00 2001 From: Paulo Reis Date: Tue, 21 Jun 2016 12:07:47 +0100 Subject: [PATCH] Safety checks for non-existing values; avoid rendering the hint template when there is no hint. --- .../web/app/views/project/editor/pdf.jade | 2 +- .../HumanReadableLogs.coffee | 10 ++- .../HumanReadableLogsRules.coffee | 84 +++++++++---------- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/services/web/app/views/project/editor/pdf.jade b/services/web/app/views/project/editor/pdf.jade index dab38e670d..618b83bbed 100644 --- a/services/web/app/views/project/editor/pdf.jade +++ b/services/web/app/views/project/editor/pdf.jade @@ -106,7 +106,7 @@ div.full-size.pdf(ng-controller="PdfController") span(ng-show="entry.file") {{ entry.file }} span(ng-show="entry.line") , line {{ entry.line }} p.entry-message(ng-show="entry.message") {{ entry.message }} - .card.card-hint + .card.card-hint(ng-if="entry.humanReadableHint") figure.card-hint-icon-container i.fa.fa-lightbulb-o(aria-hidden="true") p.card-hint-text(ng-show="entry.humanReadableHint", ng-bind-html="entry.humanReadableHint") diff --git a/services/web/public/coffee/ide/human-readable-logs/HumanReadableLogs.coffee b/services/web/public/coffee/ide/human-readable-logs/HumanReadableLogs.coffee index 6c5ef03bea..31fc11b6a3 100644 --- a/services/web/public/coffee/ide/human-readable-logs/HumanReadableLogs.coffee +++ b/services/web/public/coffee/ide/human-readable-logs/HumanReadableLogs.coffee @@ -9,9 +9,11 @@ define [ return rule for rule in ruleset when rule.regexToMatch.test logMessage for entry in parsedLogEntries.all - { regexToMatch, humanReadableHint, extraInfoURL } = _getRule entry.message - entry.ruleId = 'hint_' + regexToMatch.toString().replace(/[^a-zA-Z0-9]/g, '_').toLowerCase() - entry.humanReadableHint = humanReadableHint if humanReadableHint? - entry.extraInfoURL = extraInfoURL if extraInfoURL? + ruleDetails = _getRule entry.message + if (ruleDetails?) + entry.ruleId = 'hint_' + ruleDetails.regexToMatch.toString().replace(/[^a-zA-Z0-9]/g, '_').toLowerCase() if ruleDetails.regexToMatch? + entry.humanReadableHint = ruleDetails.humanReadableHint if ruleDetails.humanReadableHint? + entry.extraInfoURL = ruleDetails.extraInfoURL if ruleDetails.extraInfoURL? + return parsedLogEntries diff --git a/services/web/public/coffee/ide/human-readable-logs/HumanReadableLogsRules.coffee b/services/web/public/coffee/ide/human-readable-logs/HumanReadableLogsRules.coffee index 95967fbbce..a94e756244 100644 --- a/services/web/public/coffee/ide/human-readable-logs/HumanReadableLogsRules.coffee +++ b/services/web/public/coffee/ide/human-readable-logs/HumanReadableLogsRules.coffee @@ -1,43 +1,43 @@ define -> [ - regexToMatch: /Too many }'s/ - extraInfoURL: "" - humanReadableHint: """ - The reason LaTeX thinks there are too many }'s here is that the opening curly brace is missing after the \\date control sequence and before the word December, so the closing curly brace is seen as one too many (which it is!). - """ - , - regexToMatch: /Undefined control sequence/ - extraInfoURL: "/learn/Errors:Undefined_control_sequence." - humanReadableHint: """ - In this example, LaTeX is complaining that it has no such command ("control sequence") as \\dtae. Obviously it's been mistyped, but only a human can detect that fact: all LaTeX knows is that \\dtae is not a command it knows about: it's undefined. - """ - , - regexToMatch: /Missing \$ inserted/ - extraInfoURL: "/learn/Errors:Missing_$_inserted" - humanReadableHint: """ - A character that can only be used in the mathematics was inserted in normal text. If you intended to use mathematics mode, then use $...$ or \\begin{math}...\\end{math} or use the 'quick math mode': \\ensuremath{...}. - """ - , - regexToMatch: /Runaway argument/ - extraInfoURL: "/learn/Errors:Undefined_control_sequence." - humanReadableHint: """ - In this error, the closing curly brace has been omitted from the date. It's the opposite of the error of too many }'s, and it results in \\maketitle trying to format the title page while LaTeX is still expecting more text for the date! - """ - , - regexToMatch: /Underfull \\hbox/ - extraInfoURL: "/learn/Errors:Underfull_%5Chbox" - humanReadableHint: """ - This is a warning that LaTeX cannot stretch the line wide enough to fit, without making the spacing bigger than its currently permitted maximum. The badness (0-10,000) indicates how severe this is (here you can probably ignore a badness of 1394). - """ - , - regexToMatch: /Overfull \\hbox/ - extraInfoURL: "" - humanReadableHint: """ - An overfull \\hbox means that there is a hyphenation or justification problem: moving the last word on the line to the next line would make the spaces in the line wider than the current limit; keeping the word on the line would make the spaces smaller than the current limit, so the word is left on the line, but with the minimum allowed space between words, and which makes the line go over the edge. - """ - , - regexToMatch: /LaTeX Error: File .* not found/ - extraInfoURL: "/learn/Errors:missing_package" - humanReadableHint: """ - When you use the \\usepackage command to request LaTeX to use a certain package, it will look for a file with the specified name and the filetype .sty. In this case the user has mistyped the name of the paralist package, so it's easy to fix. - """ -] \ No newline at end of file + # regexToMatch: /Too many }'s/ + # extraInfoURL: "" + # humanReadableHint: """ + # The reason LaTeX thinks there are too many }'s here is that the opening curly brace is missing after the \\date control sequence and before the word December, so the closing curly brace is seen as one too many (which it is!). + # """ + # , + # regexToMatch: /Undefined control sequence/ + # extraInfoURL: "/learn/Errors:Undefined_control_sequence." + # humanReadableHint: """ + # In this example, LaTeX is complaining that it has no such command ("control sequence") as \\dtae. Obviously it's been mistyped, but only a human can detect that fact: all LaTeX knows is that \\dtae is not a command it knows about: it's undefined. + # """ + # , + # regexToMatch: /Missing \$ inserted/ + # extraInfoURL: "/learn/Errors:Missing_$_inserted" + # humanReadableHint: """ + # A character that can only be used in the mathematics was inserted in normal text. If you intended to use mathematics mode, then use $...$ or \\begin{math}...\\end{math} or use the 'quick math mode': \\ensuremath{...}. + # """ + # , + # regexToMatch: /Runaway argument/ + # extraInfoURL: "/learn/Errors:Undefined_control_sequence." + # humanReadableHint: """ + # In this error, the closing curly brace has been omitted from the date. It's the opposite of the error of too many }'s, and it results in \\maketitle trying to format the title page while LaTeX is still expecting more text for the date! + # """ + # , + # regexToMatch: /Underfull \\hbox/ + # extraInfoURL: "/learn/Errors:Underfull_%5Chbox" + # humanReadableHint: """ + # This is a warning that LaTeX cannot stretch the line wide enough to fit, without making the spacing bigger than its currently permitted maximum. The badness (0-10,000) indicates how severe this is (here you can probably ignore a badness of 1394). + # """ + # , + # regexToMatch: /Overfull \\hbox/ + # extraInfoURL: "" + # humanReadableHint: """ + # An overfull \\hbox means that there is a hyphenation or justification problem: moving the last word on the line to the next line would make the spaces in the line wider than the current limit; keeping the word on the line would make the spaces smaller than the current limit, so the word is left on the line, but with the minimum allowed space between words, and which makes the line go over the edge. + # """ + # , + # regexToMatch: /LaTeX Error: File .* not found/ + # extraInfoURL: "/learn/Errors:missing_package" + # humanReadableHint: """ + # When you use the \\usepackage command to request LaTeX to use a certain package, it will look for a file with the specified name and the filetype .sty. In this case the user has mistyped the name of the paralist package, so it's easy to fix. + # """ +]