Mintplex-Labs/anything-llm · error
Device OS and name are required
Error message
Device OS and name are required
What it means
POST /api/mobile/register (behind validRegistrationToken) calls MobileDevice.create({ deviceOs, deviceName, userId }); the model returns { error: 'Device OS and name are required' } when either value is falsy, and the endpoint relays it as HTTP 400. Both must be present non-empty strings in the JSON body.
Source
Thrown at server/endpoints/mobile/index.js:134
* Will create a new device in the database but requires approval by the user
* before it can be used.
* @param {import("express").Request} request
* @param {import("express").Response} response
*/
app.post(
"/mobile/register",
[validRegistrationToken],
async (request, response) => {
try {
const body = reqBody(request);
const result = await MobileDevice.create({
deviceOs: body.deviceOs,
deviceName: body.deviceName,
userId: response.locals?.user?.id,
});
if (result.error)
return response.status(400).json({ error: result.error });
return response.status(200).json({
token: result.device.token,
platform: MobileDevice.platform,
});
} catch (e) {
console.error(e);
response.sendStatus(500).end();
}
}
);
app.post(
"/mobile/send/:command",
[validDeviceToken],
async (request, response) => {
try {
return handleMobileCommand(request, response);
} catch (e) {View on GitHub (pinned to 3aec848f28)
Solutions
- Send both fields: {"deviceOs":"android","deviceName":"My Phone"}
- Ensure Content-Type: application/json and that the body is JSON.stringify'd
- Default the name client-side when the platform reports it blank (e.g. fallback 'Android device')
Example fix
// before
const body = { deviceOs: 'android' };
// after
const body = {
deviceOs: 'android',
deviceName: Device.deviceName || 'Android device',
}; Defensive patterns
Strategy: validation
Validate before calling
function validRegisterBody(b) {
return Boolean(b?.deviceOs) && Boolean(b?.deviceName);
}
if (!validRegisterBody(body)) throw new Error('deviceOs and deviceName are required'); Type guard
/** @param {any} b */
function isRegisterBody(b) {
return (
typeof b?.deviceOs === 'string' && b.deviceOs.length > 0 &&
typeof b?.deviceName === 'string' && b.deviceName.length > 0
);
} Prevention
- Validate both fields client-side before hitting /mobile/register
- Fall back to a default device name when the OS reports a blank one
- Always send JSON with Content-Type: application/json
When it happens
Trigger: Registering with a body like {"deviceOs":"android"} (no deviceName), {"deviceName":"Pixel"} (no deviceOs), empty strings, or a body sent without Content-Type: application/json so reqBody parses nothing.
Common situations: Mobile build where the OS reports a blank device name on some devices; UI marking deviceName optional but API requiring it; multipart/form-data instead of JSON.
Understand the failure class
Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.
Related errors
- Must be a boolean
- Invalid device OS - ${deviceOs}
- Key is required
- URL is required for web scraping
- Name and config are required
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/10a01127ffc85d18.
Report an issue: GitHub.