{"record":{"id":"6f51616a55ddd2f7","repo":"passbolt/passbolt_api","slug":"the-avatar-id-is-not-valid","errorCode":null,"errorMessage":"The avatar id is not valid.","messagePattern":"The avatar id is not valid\\.","errorType":"exception","errorClass":"Exception","httpStatus":500,"severity":"error","filePath":"src/Service/Avatars/AvatarsCacheService.php","lineNumber":225,"sourceCode":"    {\n        return $this->getOrCreateAvatarDirectory($avatar)\n            . AvatarsConfigurationService::FORMAT_MEDIUM\n            . AvatarHelper::IMAGE_EXTENSION;\n    }\n\n    /**\n     * Get or create the relative directory name of a given avatar.\n     *\n     * @param \\App\\Model\\Entity\\Avatar $avatar Avatar\n     * @return string\n     * @throws \\League\\Flysystem\\FilesystemException The cache directory must be readable/writable.\n     * @throws \\Exception if the avatar id is not a uuid.\n     */\n    protected function getOrCreateAvatarDirectory(Avatar $avatar): string\n    {\n        $avatarId = $avatar->id;\n        if (!Validation::uuid($avatarId)) {\n            throw new Exception(__('The avatar id is not valid.'));\n        }\n        $avatarCacheSubDirectory = $avatarId . DS;\n        $this->filesystem->createDirectory($avatarCacheSubDirectory);\n\n        return $avatarCacheSubDirectory;\n    }\n\n    /**\n     * The default avatar format\n     *\n     * @return string\n     */\n    protected function getDefaultFormat(): string\n    {\n        return AvatarsConfigurationService::FORMAT_MEDIUM;\n    }\n}\n","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/Avatars/AvatarsCacheService.php#L207-L243","documentation":"AvatarsCacheService builds the cache directory from the avatar's UUID id. getOrCreateAvatarDirectory throws a plain Exception('The avatar id is not valid.') if the id is not a valid UUID, since it is used as a filesystem path component.","triggerScenarios":"Reading/exporting avatar files for an Avatar entity whose id is null, empty, or not a UUID (unsaved entity, bad fixture, corrupted row).","commonSituations":"Rendering an avatar built in memory before persistence; import/migration scripts inserting avatars without UUID ids; test fixtures with fixed non-UUID ids.","solutions":["Persist the Avatar entity before generating cache files so it gets a UUID id.","Fix the data source so avatar.id contains valid UUIDs (repair migration or fixture).","Check the code path that constructs the Avatar and ensure the id is populated."],"exampleFix":"// before\n$avatar = new Avatar(['user_id' => $userId]);\n$service->getSmallAvatarFileName($avatar); // id null\n// after\n$avatar = $avatarsTable->save(new Avatar(['user_id' => $userId]));\n$service->getSmallAvatarFileName($avatar);","handlingStrategy":"validation","validationCode":"if ($avatar->id === null || !\\Cake\\Validation\\Validation::uuid($avatar->id)) {\n    // persist the avatar or abort before generating cache files\n}","typeGuard":"function hasValidAvatarId(\\App\\Model\\Entity\\Avatar $a): bool {\n    return $a->id !== null && \\Cake\\Validation\\Validation::uuid($a->id);\n}","tryCatchPattern":"try {\n    $fileName = $service->getSmallAvatarFileName($avatar);\n} catch (\\Exception $e) {\n    Log::error('Invalid avatar id: ' . $e->getMessage());\n    return $defaultAvatar;\n}","preventionTips":["Always save Avatar entities before file operations","Use UUID primary keys on avatars table and fixtures","Repair legacy rows with non-UUID ids via migration"],"tags":["php","avatars","uuid"],"backgroundTag":"invalid-identifier-format","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}