mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
Improve Katex error handling and fix handling of large expressions
* Make throwOnError=true the new default * Handle JS errors as part of the RPC request/response flow * Return a new Result type with .Err on it This enables constructs on the form: ```handlebars {{ with transform.ToMath "c = \\foo{a^2 + b^2}" }} {{ with .Err }} {{ warnf "error: %s" . }} {{ else }} {{ . }} {{ end }} {{ end }} ``` Note that the new `Result` type behaves like `template.HTML` (or a string if needed) when printed, but it will panic if in a error state. Closes #12748
This commit is contained in:
@@ -30,13 +30,23 @@ export function readInput(handle) {
|
||||
|
||||
currentLine = [...currentLine, ...buffer.subarray(0, bytesRead)];
|
||||
|
||||
// Check for newline. If not, we need to read more data.
|
||||
if (!currentLine.includes(10)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Split array into chunks by newline.
|
||||
let i = 0;
|
||||
for (let j = 0; i < currentLine.length; i++) {
|
||||
if (currentLine[i] === 10) {
|
||||
const chunk = currentLine.splice(j, i + 1);
|
||||
const arr = new Uint8Array(chunk);
|
||||
const json = JSON.parse(new TextDecoder().decode(arr));
|
||||
let json;
|
||||
try {
|
||||
json = JSON.parse(new TextDecoder().decode(arr));
|
||||
} catch (e) {
|
||||
throw new Error(`Error parsing JSON '${new TextDecoder().decode(arr)}' from stdin: ${e.message}`);
|
||||
}
|
||||
handle(json);
|
||||
j = i + 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user