{"record":{"id":"2f6f40c531de78a3","repo":"mastra-ai/mastra","slug":"metadata-avatarurl-is-empty","errorCode":null,"errorMessage":"metadata.avatarUrl is empty","messagePattern":"metadata\\.avatarUrl is empty","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/validate-avatar.ts","lineNumber":39,"sourceCode":"      message: 'metadata.avatarUrl must be a valid data URL (data:<mime>;base64,<data>)',\n    });\n  }\n\n  // `Buffer.from(..., 'base64')` decodes leniently — it silently ignores\n  // invalid characters and never throws. Validate the payload format strictly\n  // before measuring its byte length so malformed input is rejected.\n  const base64Payload = match[2]!;\n  const isStrictBase64 =\n    base64Payload.length > 0 &&\n    base64Payload.length % 4 === 0 &&\n    /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(base64Payload);\n  if (!isStrictBase64) {\n    throw new HTTPException(400, { message: 'metadata.avatarUrl contains invalid base64' });\n  }\n  const byteLength = Buffer.from(base64Payload, 'base64').byteLength;\n\n  if (byteLength === 0) {\n    throw new HTTPException(400, { message: 'metadata.avatarUrl is empty' });\n  }\n\n  if (byteLength > AVATAR_MAX_BYTES) {\n    throw new HTTPException(413, {\n      message: `metadata.avatarUrl exceeds ${AVATAR_MAX_BYTES}-byte limit (got ${byteLength})`,\n    });\n  }\n}\n","sourceCodeStart":21,"sourceCodeEnd":48,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/validate-avatar.ts#L21-L48","documentation":"HTTP 400 from validateMetadataAvatarUrl: although the base64 string passed strict format checks, decoding it yields zero bytes — an effectively empty avatar. Rejected so agents never store a no-op image.","triggerScenarios":"avatarUrl like 'data:image/png;base64,' with an empty payload that still passed earlier checks, or a payload that decodes to zero bytes.","commonSituations":"Clearing an avatar by sending an empty data URL instead of omitting/nulling the key; image processing pipelines that emit empty buffers on failure.","solutions":["Remove the avatarUrl key (or set it to null) to clear an avatar instead of sending an empty data URL.","Verify the source file/buffer is non-empty before base64-encoding and submitting."],"exampleFix":"// before\nmetadata: { avatarUrl: 'data:image/png;base64,' }\n// after\nmetadata: {} // omit avatarUrl to clear it","handlingStrategy":"validation","validationCode":"const payload = metadata?.avatarUrl?.split(',')[1] ?? '';\nif (typeof metadata?.avatarUrl === 'string' && Buffer.from(payload, 'base64').byteLength === 0) {\n  delete metadata.avatarUrl; // treat as 'no avatar'\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clear avatars by omitting the key or sending null, not an empty data URL.","Guard image pipelines against emitting empty buffers before encoding."],"tags":["http-400","empty-value","metadata","validation"],"backgroundTag":"empty-value-rejected","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}