{"record":{"id":"02f7b0131c4a2f0e","repo":"louislam/dockge","slug":"wrong-data-type","errorCode":null,"errorMessage":"Wrong data type?","messagePattern":"Wrong data type\\?","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"backend/util-server.ts","lineNumber":88,"sourceCode":"            msg: error.message,\n            msgi18n: true,\n        });\n    } else {\n        log.debug(\"console\", \"Unknown error: \" + error);\n    }\n}\n\nexport function callbackResult(result : unknown, callback : unknown) {\n    if (typeof(callback) !== \"function\") {\n        log.error(\"console\", \"Callback is not a function\");\n        return;\n    }\n    callback(result);\n}\n\nexport async function doubleCheckPassword(socket : DockgeSocket, currentPassword : unknown) {\n    if (typeof currentPassword !== \"string\") {\n        throw new Error(\"Wrong data type?\");\n    }\n\n    let user = await R.findOne(\"user\", \" id = ? AND active = 1 \", [\n        socket.userID,\n    ]);\n\n    if (!user || !verifyPassword(currentPassword, user.password)) {\n        throw new Error(\"Incorrect current password\");\n    }\n\n    return user;\n}\n\nexport function fileExists(file : string) {\n    return fs.promises.access(file, fs.constants.F_OK)\n        .then(() => true)\n        .catch(() => false);\n}","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/louislam/dockge/blob/f809ae192b571944ad773e9866d3e67064ae8043/backend/util-server.ts#L70-L106","documentation":"doubleCheckPassword() in backend/util-server.ts requires the currentPassword argument to be a string before it will verify it against the stored hash. If the client sends anything else (undefined, null, object, number), the function throws 'Wrong data type?' to fail fast rather than passing a non-string to verifyPassword. It guards sensitive operations like changing account settings (user) or creating changes that require re-authentication.","triggerScenarios":"Emitting a socket handler that calls doubleCheckPassword with a missing, undefined, non-string currentPassword field — e.g. form submitted without filling the current-password input, or a custom client sending a wrong-shaped payload.","commonSituations":"Frontend state lost so the password field is undefined at submit time; API scripts sending JSON where the password is a number or nested object; older/foreign clients not matching the expected payload shape.","solutions":["Ensure the current-password field is filled in before emitting the event","Coerce/trim the value and confirm typeof === 'string' on the client before sending","Fix custom API clients to send currentPassword as a plain string","Check the frontend form binding so the field value is actually included in the payload"],"exampleFix":"// before\nsocket.emit(\"changePassword\", this.newPassword); // currentPassword missing\n// after\nif (typeof this.currentPassword === \"string\" && this.currentPassword.length > 0) {\n  socket.emit(\"changePassword\", this.currentPassword, this.newPassword);\n}","handlingStrategy":"type-guard","validationCode":"if (typeof currentPassword !== \"string\" || currentPassword.length === 0) {\n  showError(\"Please enter your current password.\");\n  return;\n}","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === \"string\" && v.length > 0;\n}","tryCatchPattern":"try {\n  await doubleCheckPassword(socket, currentPassword);\n} catch (e) {\n  if (e.message === \"Wrong data type?\") {\n    showError(\"Current password field was missing or malformed.\");\n  } else if (e.message === \"Incorrect current password\") {\n    showError(\"Password is wrong.\");\n  } else throw e;\n}","preventionTips":["Bind the current-password form field and verify it is non-empty before submit","Send credentials as plain JSON strings — never numbers/objects","Trim client-side but send the exact typed value","Write a client payload schema test for handlers requiring re-auth"],"tags":["validation","authentication","type-error","websocket"],"backgroundTag":"wrong-argument-type","analyzedSha":"f809ae192b571944ad773e9866d3e67064ae8043","analyzedAt":"2026-08-31T19:13:50.919Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}