{"record":{"id":"bf07da75817f0b1a","repo":"HeyPuter/puter","slug":"bad-request-bf07da","errorCode":"bad_request","errorMessage":"`url` must be a string or null","messagePattern":"`url` must be a string or null","errorType":"http","errorClass":"HttpError","httpStatus":400,"severity":"warning","filePath":"src/backend/controllers/desktop/DesktopController.js","lineNumber":77,"sourceCode":"\n    registerRoutes(router) {\n        // -- Desktop background --------------------------------------\n\n        router.post(\n            '/set-desktop-bg',\n            {\n                subdomain: 'api',\n                requireUserActor: true,\n                allowFullAccessToken: true,\n                rateLimit: PREFERENCE_WRITE_LIMIT,\n            },\n            async (req, res) => {\n                const { url, color, fit } = req.body ?? {};\n\n                const patch = {};\n                if (url !== undefined) {\n                    if (url !== null && typeof url !== 'string') {\n                        throw new HttpError(\n                            400,\n                            '`url` must be a string or null',\n                            { legacyCode: 'bad_request' },\n                        );\n                    }\n                    patch.desktop_bg_url = url;\n                }\n                if (color !== undefined) {\n                    if (color !== null && typeof color !== 'string') {\n                        throw new HttpError(\n                            400,\n                            '`color` must be a string or null',\n                            { legacyCode: 'bad_request' },\n                        );\n                    }\n                    patch.desktop_bg_color = color;\n                }\n                if (fit !== undefined) {","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/HeyPuter/puter/blob/908ec23eda38526170322c3edf71ba45ecb1ca95/src/backend/controllers/desktop/DesktopController.js#L59-L95","documentation":"Thrown by POST /set-desktop-bg (DesktopController) when the request includes a `url` field whose value is neither a string nor null. The handler builds a preference patch object and only accepts string|null for url; undefined means 'leave unchanged', any other type (number, boolean, object, array) is rejected with legacy `bad_request`. Passing null explicitly clears the wallpaper URL.","triggerScenarios":"POST /set-desktop-bg with `url` set to a number, boolean, array, or object (anything that is not a string and not null).","commonSituations":"Client sends the raw value of a typed input without coercion (e.g. a numeric id, an object describing the image); a boolean flag accidentally placed under `url`; serialization produced an object instead of a URL string.","solutions":["Send `url` as a string URL, or as null to clear it, or omit the key entirely to leave it unchanged.","Coerce the field to a string before serializing the request body.","If you only want to change color/fit, do not include the `url` key at all."],"exampleFix":"// before: passing an object\nbody: JSON.stringify({ url: { src: img.href } })\n\n// after: pass a string or null\nbody: JSON.stringify({ url: img ? img.href : null })","handlingStrategy":"type-guard","validationCode":"function isStringOrNull(v) { return v === null || typeof v === 'string'; }\nif (url !== undefined && !isStringOrNull(url)) {\n  throw new Error('url must be a string or null');\n}","typeGuard":"/** @returns {v is string | null} */\nfunction isStringOrNull(v) { return v === null || typeof v === 'string'; }","tryCatchPattern":null,"preventionTips":["Omit `url` when you only want to change color/fit.","Send null to clear the wallpaper; never an object/number/boolean."],"tags":["desktop","validation","type-check","preferences"],"backgroundTag":null,"analyzedSha":"908ec23eda38526170322c3edf71ba45ecb1ca95","analyzedAt":"2026-08-12T20:53:15.911Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}