INNER CODE UNIT · JavaScript
writeError
sebastiancarlos/beachpatrol · beachpatrol.js:173
const writeError = (message) => {
// Log error to server console and to socket (with sentinel line)
console.log(`Error: ${message}`);
socket.write(`${ERROR_SENTINEL} ${message.replace(/\n/g, " ")}\n`);
socket.end();
};
socket.on("data", async (data) => {
const message = JSON.parse(data.toString());
const [commandName, ...args] = message;
// Sanitize commandName
if (commandName.includes("..")) {
writeError(`Invalid command name '${commandName}'. No path traversal allowed.`);
return;
}
// A command may arrive before the browser is ready. Ask the client to retry.