mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-17 21:01:26 +02:00
internal/warpc: Improve the JS plugin API
* Move the error handling into commons and make sure the error returned also returns message errors * Make the protocol version an int so it can be more easily compared
This commit is contained in:
@@ -41,13 +41,21 @@ export function readInput(handle) {
|
||||
if (currentLine[i] === 10) {
|
||||
const chunk = currentLine.splice(j, i + 1);
|
||||
const arr = new Uint8Array(chunk);
|
||||
let json;
|
||||
let message;
|
||||
try {
|
||||
json = JSON.parse(new TextDecoder().decode(arr));
|
||||
message = JSON.parse(new TextDecoder().decode(arr));
|
||||
} catch (e) {
|
||||
throw new Error(`Error parsing JSON '${new TextDecoder().decode(arr)}' from stdin: ${e.message}`);
|
||||
}
|
||||
handle(json);
|
||||
|
||||
try {
|
||||
handle(message);
|
||||
} catch (e) {
|
||||
let header = message.header;
|
||||
header.err = e.message;
|
||||
writeOutput({ header: header });
|
||||
}
|
||||
|
||||
j = i + 1;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user