/co2024-03-12 17:37:38:3738 [deviceRepository.js] ERROR: Failed to initialize client status for device 'Avalve-eunhee' in the database. Error: TypeError: (intermediate value) is not iterable
C:\Users\parkeunhee\Desktop\AVALVE\Avalve_DataServer(re)\src\repository\deviceRepository.js:51
const [result] = await dbConnection.query(sql, params);
^
TypeError: (intermediate value) is not iterable
at Object.initializeDeviceState (C:\Users\parkeunhee\Desktop\AVALVE\Avalve_DataServer(re)\src\repository\deviceRepository.js:51:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
클라이언트의 소켓 연결이 끊기면서 서버가 같이 error로 인해 종료되는 문제
disconnect
라는 이벤트가 발생하면 deviceRepository.initializeDeviceState()
메서드는, 연결되어있는 데이터베이스에 쿼리문을 실행하여 값을 초기화 한다.null
로 초기화0
으로 초기화is not iterable
문장은, 아래의 코드 라인에서 쿼리문을 수행한 결과 [result] 변수에 할당하려고 했으나 디스트럭처링에 실패했다는 의미다. const [result] = await dbConnection.query(sql, params);
디스트럭처링은, 배열이나 객체에서 값을 추출하여 개별 변수에 할당하는 기능을 의미한다.
따라서 쿼리문이 디스트럭처링에 실패한 이유는, 쿼리 실행 결과가 하나의 Record(행)이기 때문에 [result]라는 변수에 할당하지 못하는 문제로 인한 error였다.
const result = await dbConnection.query(sql, params);
2024-03-14 09:18:38:1838 [app.js] INFO: Avalve-eunhee disconnected and client status reset