prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [V3/Config] Clearing a registered data group when no data has been set results in a KeyError.
  Please be sure to read through other issues as well to make sure what you are suggesting/reporting has not already
  been suggested/reported
  
  ### Type:
  
  - [ ] Suggestion
  - [x] Bug
  
  ### Brief description of the problem
  When attempting to use methods such as `.clear_all_members` and `.clear_all_globals`, when no data has been set, will result in a KeyError being raised.
  ### Expected behavior
  Silently passes
  ### Actual behavior
  Key Error is raised.
  ### Steps to reproduce
  
  1. register some data
  2. try to clear all data from that scope
  3. Key error is raised
  4. You cry
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `redbot/core/drivers/red_json.py`
  Content:
  ```
  1 from pathlib import Path
  2 from typing import Tuple
  3 
  4 from ..json_io import JsonIO
  5 
  6 from .red_base import BaseDriver
  7 
  8 __all__ = ["JSON"]
  9 
  10 
  11 class JSON(BaseDriver):
  12     """
  13     Subclass of :py:class:`.red_base.BaseDriver`.
  14 
  15     .. py:attribute:: file_name
  16 
  17         The name of the file in which to store JSON data.
  18 
  19     .. py:attribute:: data_path
  20 
  21         The path in which to store the file indicated by :py:attr:`file_name`.
  22     """
  23     def __init__(self, cog_name, *, data_path_override: Path=None,
  24                  file_name_override: str="settings.json"):
  25         super().__init__(cog_name)
  26         self.file_name = file_name_override
  27         if data_path_override:
  28             self.data_path = data_path_override
  29         else:
  30             self.data_path = Path.cwd() / 'cogs' / '.data' / self.cog_name
  31 
  32         self.data_path.mkdir(parents=True, exist_ok=True)
  33 
  34         self.data_path = self.data_path / self.file_name
  35 
  36         self.jsonIO = JsonIO(self.data_path)
  37 
  38         try:
  39             self.data = self.jsonIO._load_json()
  40         except FileNotFoundError:
  41             self.data = {}
  42             self.jsonIO._save_json(self.data)
  43 
  44     async def get(self, *identifiers: Tuple[str]):
  45         partial = self.data
  46         full_identifiers = (self.unique_cog_identifier, *identifiers)
  47         for i in full_identifiers:
  48             partial = partial[i]
  49         return partial
  50 
  51     async def set(self, *identifiers: str, value=None):
  52         partial = self.data
  53         full_identifiers = (self.unique_cog_identifier, *identifiers)
  54         for i in full_identifiers[:-1]:
  55             if i not in partial:
  56                 partial[i] = {}
  57             partial = partial[i]
  58 
  59         partial[full_identifiers[-1]] = value
  60         await self.jsonIO._threadsafe_save_json(self.data)
  61 
  62     async def clear(self, *identifiers: str):
  63         partial = self.data
  64         full_identifiers = (self.unique_cog_identifier, *identifiers)
  65         for i in full_identifiers[:-1]:
  66             if i not in partial:
  67                 break
  68             partial = partial[i]
  69         else:
  70             del partial[identifiers[-1]]
  71         await self.jsonIO._threadsafe_save_json(self.data)
  72
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/redbot/core/drivers/red_json.py b/redbot/core/drivers/red_json.py
  --- a/redbot/core/drivers/red_json.py
  +++ b/redbot/core/drivers/red_json.py
  @@ -62,10 +62,11 @@
       async def clear(self, *identifiers: str):
           partial = self.data
           full_identifiers = (self.unique_cog_identifier, *identifiers)
  -        for i in full_identifiers[:-1]:
  -            if i not in partial:
  -                break
  -            partial = partial[i]
  -        else:
  +        try:
  +            for i in full_identifiers[:-1]:
  +                partial = partial[i]
               del partial[identifiers[-1]]
  -        await self.jsonIO._threadsafe_save_json(self.data)
  +        except KeyError:
  +            pass
  +        else:
  +            await self.jsonIO._threadsafe_save_json(self.data)
  
verification_info: {"golden_diff": "diff --git a/redbot/core/drivers/red_json.py b/redbot/core/drivers/red_json.py\n--- a/redbot/core/drivers/red_json.py\n+++ b/redbot/core/drivers/red_json.py\n@@ -62,10 +62,11 @@\n     async def clear(self, *identifiers: str):\n         partial = self.data\n         full_identifiers = (self.unique_cog_identifier, *identifiers)\n-        for i in full_identifiers[:-1]:\n-            if i not in partial:\n-                break\n-            partial = partial[i]\n-        else:\n+        try:\n+            for i in full_identifiers[:-1]:\n+                partial = partial[i]\n             del partial[identifiers[-1]]\n-        await self.jsonIO._threadsafe_save_json(self.data)\n+        except KeyError:\n+            pass\n+        else:\n+            await self.jsonIO._threadsafe_save_json(self.data)\n", "issue": "[V3/Config] Clearing a registered data group when no data has been set results in a KeyError.\nPlease be sure to read through other issues as well to make sure what you are suggesting/reporting has not already\r\nbeen suggested/reported\r\n\r\n### Type:\r\n\r\n- [ ] Suggestion\r\n- [x] Bug\r\n\r\n### Brief description of the problem\r\nWhen attempting to use methods such as `.clear_all_members` and `.clear_all_globals`, when no data has been set, will result in a KeyError being raised.\r\n### Expected behavior\r\nSilently passes\r\n### Actual behavior\r\nKey Error is raised.\r\n### Steps to reproduce\r\n\r\n1. register some data\r\n2. try to clear all data from that scope\r\n3. Key error is raised\r\n4. You cry\r\n\n", "before_files": [{"content": "from pathlib import Path\nfrom typing import Tuple\n\nfrom ..json_io import JsonIO\n\nfrom .red_base import BaseDriver\n\n__all__ = [\"JSON\"]\n\n\nclass JSON(BaseDriver):\n    \"\"\"\n    Subclass of :py:class:`.red_base.BaseDriver`.\n\n    .. py:attribute:: file_name\n\n        The name of the file in which to store JSON data.\n\n    .. py:attribute:: data_path\n\n        The path in which to store the file indicated by :py:attr:`file_name`.\n    \"\"\"\n    def __init__(self, cog_name, *, data_path_override: Path=None,\n                 file_name_override: str=\"settings.json\"):\n        super().__init__(cog_name)\n        self.file_name = file_name_override\n        if data_path_override:\n            self.data_path = data_path_override\n        else:\n            self.data_path = Path.cwd() / 'cogs' / '.data' / self.cog_name\n\n        self.data_path.mkdir(parents=True, exist_ok=True)\n\n        self.data_path = self.data_path / self.file_name\n\n        self.jsonIO = JsonIO(self.data_path)\n\n        try:\n            self.data = self.jsonIO._load_json()\n        except FileNotFoundError:\n            self.data = {}\n            self.jsonIO._save_json(self.data)\n\n    async def get(self, *identifiers: Tuple[str]):\n        partial = self.data\n        full_identifiers = (self.unique_cog_identifier, *identifiers)\n        for i in full_identifiers:\n            partial = partial[i]\n        return partial\n\n    async def set(self, *identifiers: str, value=None):\n        partial = self.data\n        full_identifiers = (self.unique_cog_identifier, *identifiers)\n        for i in full_identifiers[:-1]:\n            if i not in partial:\n                partial[i] = {}\n            partial = partial[i]\n\n        partial[full_identifiers[-1]] = value\n        await self.jsonIO._threadsafe_save_json(self.data)\n\n    async def clear(self, *identifiers: str):\n        partial = self.data\n        full_identifiers = (self.unique_cog_identifier, *identifiers)\n        for i in full_identifiers[:-1]:\n            if i not in partial:\n                break\n            partial = partial[i]\n        else:\n            del partial[identifiers[-1]]\n        await self.jsonIO._threadsafe_save_json(self.data)\n", "path": "redbot/core/drivers/red_json.py"}], "after_files": [{"content": "from pathlib import Path\nfrom typing import Tuple\n\nfrom ..json_io import JsonIO\n\nfrom .red_base import BaseDriver\n\n__all__ = [\"JSON\"]\n\n\nclass JSON(BaseDriver):\n    \"\"\"\n    Subclass of :py:class:`.red_base.BaseDriver`.\n\n    .. py:attribute:: file_name\n\n        The name of the file in which to store JSON data.\n\n    .. py:attribute:: data_path\n\n        The path in which to store the file indicated by :py:attr:`file_name`.\n    \"\"\"\n    def __init__(self, cog_name, *, data_path_override: Path=None,\n                 file_name_override: str=\"settings.json\"):\n        super().__init__(cog_name)\n        self.file_name = file_name_override\n        if data_path_override:\n            self.data_path = data_path_override\n        else:\n            self.data_path = Path.cwd() / 'cogs' / '.data' / self.cog_name\n\n        self.data_path.mkdir(parents=True, exist_ok=True)\n\n        self.data_path = self.data_path / self.file_name\n\n        self.jsonIO = JsonIO(self.data_path)\n\n        try:\n            self.data = self.jsonIO._load_json()\n        except FileNotFoundError:\n            self.data = {}\n            self.jsonIO._save_json(self.data)\n\n    async def get(self, *identifiers: Tuple[str]):\n        partial = self.data\n        full_identifiers = (self.unique_cog_identifier, *identifiers)\n        for i in full_identifiers:\n            partial = partial[i]\n        return partial\n\n    async def set(self, *identifiers: str, value=None):\n        partial = self.data\n        full_identifiers = (self.unique_cog_identifier, *identifiers)\n        for i in full_identifiers[:-1]:\n            if i not in partial:\n                partial[i] = {}\n            partial = partial[i]\n\n        partial[full_identifiers[-1]] = value\n        await self.jsonIO._threadsafe_save_json(self.data)\n\n    async def clear(self, *identifiers: str):\n        partial = self.data\n        full_identifiers = (self.unique_cog_identifier, *identifiers)\n        try:\n            for i in full_identifiers[:-1]:\n                partial = partial[i]\n            del partial[identifiers[-1]]\n        except KeyError:\n            pass\n        else:\n            await self.jsonIO._threadsafe_save_json(self.data)\n", "path": "redbot/core/drivers/red_json.py"}]}