{"record":{"id":"bc10773e68e19cb5","repo":"unclecode/crawl4ai","slug":"profile-not-found-profile-path","errorCode":null,"errorMessage":"Profile not found: {profile_path}","messagePattern":"Profile not found: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crawl4ai/browser_profiler.py","lineNumber":104,"sourceCode":"    dry_run: bool = False\n) -> Dict[str, Any]:\n    \"\"\"\n    Shrink a Chrome profile to reduce storage while preserving auth data.\n\n    Args:\n        profile_path: Path to profile directory\n        level: How aggressively to shrink (LIGHT/MEDIUM/AGGRESSIVE/MINIMAL)\n        dry_run: If True, only report what would be removed\n\n    Returns:\n        Dict with 'removed', 'kept', 'bytes_freed', 'size_before', 'size_after', 'errors'\n    \"\"\"\n    if level == ShrinkLevel.NONE:\n        return {\"removed\": [], \"kept\": [], \"bytes_freed\": 0, \"errors\": []}\n\n    profile = Path(profile_path)\n    if not profile.exists() or not profile.is_dir():\n        raise ValueError(f\"Profile not found: {profile_path}\")\n\n    # Chrome profiles may have data in Default/ subdirectory\n    target = profile / \"Default\" if (profile / \"Default\").is_dir() else profile\n\n    keep = KEEP_PATTERNS[level]\n    result = {\"removed\": [], \"kept\": [], \"bytes_freed\": 0, \"errors\": [], \"size_before\": _get_size(profile)}\n\n    for item in target.iterdir():\n        name = item.name\n        # Check if item matches any keep pattern\n        if any(name == p or name.startswith(p) for p in keep):\n            result[\"kept\"].append(name)\n        else:\n            size = _get_size(item)\n            if not dry_run:\n                try:\n                    shutil.rmtree(item) if item.is_dir() else item.unlink()\n                    result[\"removed\"].append(name)","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/unclecode/crawl4ai/blob/7e801521428ee12509994d39151006f64055ebe3/crawl4ai/browser_profiler.py#L86-L122","documentation":"The module-level shrink_profile(profile_path, level, dry_run) helper validates that profile_path exists and is a directory before shrinking a Chrome profile. A missing path or a file (not dir) raises ValueError('Profile not found: ...'). Note it also understands Chrome's Default/ subdirectory layout and operates on that if present.","triggerScenarios":"Calling shrink_profile('/nonexistent/path'); passing a profile name instead of the resolved absolute path to the free function (the BrowserProfiler method resolves names — the free function does not); passing a .zip backup file path; profile was deleted after a previous shrink.","commonSituations":"Using the functional API directly instead of the class; relative paths resolved against an unexpected cwd; profiles_dir relocated between runs.","solutions":["Verify the path first: Path(p).is_dir() before calling.","Pass the actual profile directory (the one containing Default/ or the profile files), absolute if possible.","If you only have a profile name, use BrowserProfiler().shrink_profile(name) which joins profiles_dir for you."],"exampleFix":"# before\nshrink_profile('my-profile', ShrinkLevel.MEDIUM)  # relative name -> not a dir\n\n# after\nprofiler = BrowserProfiler()\nresult = profiler.shrink_profile('my-profile', ShrinkLevel.MEDIUM)  # resolves under profiles_dir","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(profile_path).expanduser().resolve()\nif not p.is_dir():\n    raise ValueError(f'profile directory missing: {p}')","typeGuard":"from pathlib import Path\ndef is_profile_dir(path) -> bool:\n    p = Path(path).expanduser()\n    return p.is_dir()","tryCatchPattern":"try:\n    result = shrink_profile(path, level)\nexcept ValueError as e:\n    if 'Profile not found' in str(e):\n        logger.warning('skipping missing profile %s', path)\n        result = None\n    else:\n        raise","preventionTips":["Prefer the BrowserProfiler method which resolves names under profiles_dir.","Resolve paths to absolute before calling the free function.","Existence-check before cleanup scripts iterate profiles."],"tags":["browser-profiler","validation","filesystem"],"backgroundTag":null,"analyzedSha":"7e801521428ee12509994d39151006f64055ebe3","analyzedAt":"2026-08-14T20:46:20.673Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}