We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Replace `DatasetModuleNotInstalledError` errors with `DatasetWithScriptNotSupportedError`
We should never have a `DatasetModuleNotInstalledError` error, because we should return a `DatasetWithScriptNotSupportedError` error before

See https://github.com/huggingface/datasets-server/issues/1067#issuecomment-1924305954

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `services/worker/src/worker/job_runners/dataset/config_names.py`
Content:
```
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2022 The HuggingFace Authors.
3 
4 import logging
5 from typing import Optional
6 
7 from datasets import get_dataset_config_names
8 from datasets.data_files import EmptyDatasetError as _EmptyDatasetError
9 from libcommon.exceptions import (
10     ConfigNamesError,
11     DatasetModuleNotInstalledError,
12     DatasetWithScriptNotSupportedError,
13     DatasetWithTooManyConfigsError,
14     EmptyDatasetError,
15 )
16 
17 from worker.dtos import CompleteJobResult, ConfigNameItem, DatasetConfigNamesResponse
18 from worker.job_runners.dataset.dataset_job_runner import (
19     DatasetJobRunnerWithDatasetsCache,
20 )
21 from worker.utils import resolve_trust_remote_code
22 
23 
24 def compute_config_names_response(
25     dataset: str,
26     max_number: int,
27     dataset_scripts_allow_list: list[str],
28     hf_token: Optional[str] = None,
29 ) -> DatasetConfigNamesResponse:
30     """
31     Get the response of 'dataset-config-names' for one specific dataset on huggingface.co.
32     Dataset can be gated if you pass an acceptable token.
33     It is assumed that the dataset exists and can be accessed using the token.
34 
35     Args:
36         dataset (`str`):
37             A namespace (user or an organization) and a repo name separated by a `/`.
38         max_number (`int`):
39             The maximum number of configs for a dataset.
40         dataset_scripts_allow_list (`list[str]`):
41             List of datasets for which we support dataset scripts.
42             Unix shell-style wildcards also work in the dataset name for namespaced datasets,
43             for example `some_namespace/*` to refer to all the datasets in the `some_namespace` namespace.
44             The keyword `{{ALL_DATASETS_WITH_NO_NAMESPACE}}` refers to all the datasets without namespace.
45         hf_token (`str`, *optional*):
46             An authentication token (See https://huggingface.co/settings/token)
47 
48     Raises:
49         [~`libcommon.exceptions.EmptyDatasetError`]:
50           The dataset is empty.
51         [~`libcommon.exceptions.DatasetModuleNotInstalledError`]:
52           The dataset tries to import a module that is not installed.
53         [~`libcommon.exceptions.ConfigNamesError`]:
54           If the list of configs could not be obtained using the datasets library.
55         [~`libcommon.exceptions.DatasetWithScriptNotSupportedError`]:
56             If the dataset has a dataset script and is not in the allow list.
57 
58     Returns:
59         `DatasetConfigNamesResponse`: An object with the list of config names.
60     """
61     logging.info(f"get 'dateset-config-names' for {dataset=}")
62     # get the list of splits in streaming mode
63     try:
64         config_name_items: list[ConfigNameItem] = [
65             {"dataset": dataset, "config": str(config)}
66             for config in sorted(
67                 get_dataset_config_names(
68                     path=dataset,
69                     token=hf_token,
70                     trust_remote_code=resolve_trust_remote_code(
71                         dataset=dataset, allow_list=dataset_scripts_allow_list
72                     ),
73                 )
74             )
75         ]
76     except _EmptyDatasetError as err:
77         raise EmptyDatasetError("The dataset is empty.", cause=err) from err
78     except ImportError as err:
79         raise DatasetModuleNotInstalledError(
80             "The dataset tries to import a module that is not installed.", cause=err
81         ) from err
82     except Exception as err:
83         if isinstance(err, ValueError) and "trust_remote_code" in str(err):
84             raise DatasetWithScriptNotSupportedError(
85                 "The dataset viewer doesn't support this dataset because it runs "
86                 "arbitrary python code. Please open a discussion in the discussion tab "
87                 "if you think this is an error and tag @lhoestq and @severo."
88             ) from err
89         raise ConfigNamesError("Cannot get the config names for the dataset.", cause=err) from err
90 
91     number_of_configs = len(config_name_items)
92     if number_of_configs > max_number:
93         raise DatasetWithTooManyConfigsError(
94             f"The maximum number of configs allowed is {max_number}, dataset has {number_of_configs} configs."
95         )
96 
97     return DatasetConfigNamesResponse(config_names=config_name_items)
98 
99 
100 class DatasetConfigNamesJobRunner(DatasetJobRunnerWithDatasetsCache):
101     @staticmethod
102     def get_job_type() -> str:
103         return "dataset-config-names"
104 
105     def compute(self) -> CompleteJobResult:
106         return CompleteJobResult(
107             compute_config_names_response(
108                 dataset=self.dataset,
109                 hf_token=self.app_config.common.hf_token,
110                 max_number=self.app_config.config_names.max_number,
111                 dataset_scripts_allow_list=self.app_config.common.dataset_scripts_allow_list,
112             )
113         )
114
```
--- 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()

```

diff --git a/services/worker/src/worker/job_runners/dataset/config_names.py b/services/worker/src/worker/job_runners/dataset/config_names.py
--- a/services/worker/src/worker/job_runners/dataset/config_names.py
+++ b/services/worker/src/worker/job_runners/dataset/config_names.py
@@ -75,18 +75,21 @@
         ]
     except _EmptyDatasetError as err:
         raise EmptyDatasetError("The dataset is empty.", cause=err) from err
-    except ImportError as err:
-        raise DatasetModuleNotInstalledError(
-            "The dataset tries to import a module that is not installed.", cause=err
-        ) from err
-    except Exception as err:
-        if isinstance(err, ValueError) and "trust_remote_code" in str(err):
+    except ValueError as err:
+        if "trust_remote_code" in str(err):
             raise DatasetWithScriptNotSupportedError(
                 "The dataset viewer doesn't support this dataset because it runs "
                 "arbitrary python code. Please open a discussion in the discussion tab "
                 "if you think this is an error and tag @lhoestq and @severo."
             ) from err
         raise ConfigNamesError("Cannot get the config names for the dataset.", cause=err) from err
+    except ImportError as err:
+        # this should only happen if the dataset is in the allow list, which should soon disappear
+        raise DatasetModuleNotInstalledError(
+            "The dataset tries to import a module that is not installed.", cause=err
+        ) from err
+    except Exception as err:
+        raise ConfigNamesError("Cannot get the config names for the dataset.", cause=err) from err
 
     number_of_configs = len(config_name_items)
     if number_of_configs > max_number:

{"golden_diff": "diff --git a/services/worker/src/worker/job_runners/dataset/config_names.py b/services/worker/src/worker/job_runners/dataset/config_names.py\n--- a/services/worker/src/worker/job_runners/dataset/config_names.py\n+++ b/services/worker/src/worker/job_runners/dataset/config_names.py\n@@ -75,18 +75,21 @@\n         ]\n     except _EmptyDatasetError as err:\n         raise EmptyDatasetError(\"The dataset is empty.\", cause=err) from err\n-    except ImportError as err:\n-        raise DatasetModuleNotInstalledError(\n-            \"The dataset tries to import a module that is not installed.\", cause=err\n-        ) from err\n-    except Exception as err:\n-        if isinstance(err, ValueError) and \"trust_remote_code\" in str(err):\n+    except ValueError as err:\n+        if \"trust_remote_code\" in str(err):\n             raise DatasetWithScriptNotSupportedError(\n                 \"The dataset viewer doesn't support this dataset because it runs \"\n                 \"arbitrary python code. Please open a discussion in the discussion tab \"\n                 \"if you think this is an error and tag @lhoestq and @severo.\"\n             ) from err\n         raise ConfigNamesError(\"Cannot get the config names for the dataset.\", cause=err) from err\n+    except ImportError as err:\n+        # this should only happen if the dataset is in the allow list, which should soon disappear\n+        raise DatasetModuleNotInstalledError(\n+            \"The dataset tries to import a module that is not installed.\", cause=err\n+        ) from err\n+    except Exception as err:\n+        raise ConfigNamesError(\"Cannot get the config names for the dataset.\", cause=err) from err\n \n     number_of_configs = len(config_name_items)\n     if number_of_configs > max_number:\n", "issue": "Replace `DatasetModuleNotInstalledError` errors with `DatasetWithScriptNotSupportedError`\nWe should never have a `DatasetModuleNotInstalledError` error, because we should return a `DatasetWithScriptNotSupportedError` error before\r\n\r\nSee https://github.com/huggingface/datasets-server/issues/1067#issuecomment-1924305954\n", "before_files": [{"content": "# SPDX-License-Identifier: Apache-2.0\n# Copyright 2022 The HuggingFace Authors.\n\nimport logging\nfrom typing import Optional\n\nfrom datasets import get_dataset_config_names\nfrom datasets.data_files import EmptyDatasetError as _EmptyDatasetError\nfrom libcommon.exceptions import (\n    ConfigNamesError,\n    DatasetModuleNotInstalledError,\n    DatasetWithScriptNotSupportedError,\n    DatasetWithTooManyConfigsError,\n    EmptyDatasetError,\n)\n\nfrom worker.dtos import CompleteJobResult, ConfigNameItem, DatasetConfigNamesResponse\nfrom worker.job_runners.dataset.dataset_job_runner import (\n    DatasetJobRunnerWithDatasetsCache,\n)\nfrom worker.utils import resolve_trust_remote_code\n\n\ndef compute_config_names_response(\n    dataset: str,\n    max_number: int,\n    dataset_scripts_allow_list: list[str],\n    hf_token: Optional[str] = None,\n) -> DatasetConfigNamesResponse:\n    \"\"\"\n    Get the response of 'dataset-config-names' for one specific dataset on huggingface.co.\n    Dataset can be gated if you pass an acceptable token.\n    It is assumed that the dataset exists and can be accessed using the token.\n\n    Args:\n        dataset (`str`):\n            A namespace (user or an organization) and a repo name separated by a `/`.\n        max_number (`int`):\n            The maximum number of configs for a dataset.\n        dataset_scripts_allow_list (`list[str]`):\n            List of datasets for which we support dataset scripts.\n            Unix shell-style wildcards also work in the dataset name for namespaced datasets,\n            for example `some_namespace/*` to refer to all the datasets in the `some_namespace` namespace.\n            The keyword `{{ALL_DATASETS_WITH_NO_NAMESPACE}}` refers to all the datasets without namespace.\n        hf_token (`str`, *optional*):\n            An authentication token (See https://huggingface.co/settings/token)\n\n    Raises:\n        [~`libcommon.exceptions.EmptyDatasetError`]:\n          The dataset is empty.\n        [~`libcommon.exceptions.DatasetModuleNotInstalledError`]:\n          The dataset tries to import a module that is not installed.\n        [~`libcommon.exceptions.ConfigNamesError`]:\n          If the list of configs could not be obtained using the datasets library.\n        [~`libcommon.exceptions.DatasetWithScriptNotSupportedError`]:\n            If the dataset has a dataset script and is not in the allow list.\n\n    Returns:\n        `DatasetConfigNamesResponse`: An object with the list of config names.\n    \"\"\"\n    logging.info(f\"get 'dateset-config-names' for {dataset=}\")\n    # get the list of splits in streaming mode\n    try:\n        config_name_items: list[ConfigNameItem] = [\n            {\"dataset\": dataset, \"config\": str(config)}\n            for config in sorted(\n                get_dataset_config_names(\n                    path=dataset,\n                    token=hf_token,\n                    trust_remote_code=resolve_trust_remote_code(\n                        dataset=dataset, allow_list=dataset_scripts_allow_list\n                    ),\n                )\n            )\n        ]\n    except _EmptyDatasetError as err:\n        raise EmptyDatasetError(\"The dataset is empty.\", cause=err) from err\n    except ImportError as err:\n        raise DatasetModuleNotInstalledError(\n            \"The dataset tries to import a module that is not installed.\", cause=err\n        ) from err\n    except Exception as err:\n        if isinstance(err, ValueError) and \"trust_remote_code\" in str(err):\n            raise DatasetWithScriptNotSupportedError(\n                \"The dataset viewer doesn't support this dataset because it runs \"\n                \"arbitrary python code. Please open a discussion in the discussion tab \"\n                \"if you think this is an error and tag @lhoestq and @severo.\"\n            ) from err\n        raise ConfigNamesError(\"Cannot get the config names for the dataset.\", cause=err) from err\n\n    number_of_configs = len(config_name_items)\n    if number_of_configs > max_number:\n        raise DatasetWithTooManyConfigsError(\n            f\"The maximum number of configs allowed is {max_number}, dataset has {number_of_configs} configs.\"\n        )\n\n    return DatasetConfigNamesResponse(config_names=config_name_items)\n\n\nclass DatasetConfigNamesJobRunner(DatasetJobRunnerWithDatasetsCache):\n    @staticmethod\n    def get_job_type() -> str:\n        return \"dataset-config-names\"\n\n    def compute(self) -> CompleteJobResult:\n        return CompleteJobResult(\n            compute_config_names_response(\n                dataset=self.dataset,\n                hf_token=self.app_config.common.hf_token,\n                max_number=self.app_config.config_names.max_number,\n                dataset_scripts_allow_list=self.app_config.common.dataset_scripts_allow_list,\n            )\n        )\n", "path": "services/worker/src/worker/job_runners/dataset/config_names.py"}], "after_files": [{"content": "# SPDX-License-Identifier: Apache-2.0\n# Copyright 2022 The HuggingFace Authors.\n\nimport logging\nfrom typing import Optional\n\nfrom datasets import get_dataset_config_names\nfrom datasets.data_files import EmptyDatasetError as _EmptyDatasetError\nfrom libcommon.exceptions import (\n    ConfigNamesError,\n    DatasetModuleNotInstalledError,\n    DatasetWithScriptNotSupportedError,\n    DatasetWithTooManyConfigsError,\n    EmptyDatasetError,\n)\n\nfrom worker.dtos import CompleteJobResult, ConfigNameItem, DatasetConfigNamesResponse\nfrom worker.job_runners.dataset.dataset_job_runner import (\n    DatasetJobRunnerWithDatasetsCache,\n)\nfrom worker.utils import resolve_trust_remote_code\n\n\ndef compute_config_names_response(\n    dataset: str,\n    max_number: int,\n    dataset_scripts_allow_list: list[str],\n    hf_token: Optional[str] = None,\n) -> DatasetConfigNamesResponse:\n    \"\"\"\n    Get the response of 'dataset-config-names' for one specific dataset on huggingface.co.\n    Dataset can be gated if you pass an acceptable token.\n    It is assumed that the dataset exists and can be accessed using the token.\n\n    Args:\n        dataset (`str`):\n            A namespace (user or an organization) and a repo name separated by a `/`.\n        max_number (`int`):\n            The maximum number of configs for a dataset.\n        dataset_scripts_allow_list (`list[str]`):\n            List of datasets for which we support dataset scripts.\n            Unix shell-style wildcards also work in the dataset name for namespaced datasets,\n            for example `some_namespace/*` to refer to all the datasets in the `some_namespace` namespace.\n            The keyword `{{ALL_DATASETS_WITH_NO_NAMESPACE}}` refers to all the datasets without namespace.\n        hf_token (`str`, *optional*):\n            An authentication token (See https://huggingface.co/settings/token)\n\n    Raises:\n        [~`libcommon.exceptions.EmptyDatasetError`]:\n          The dataset is empty.\n        [~`libcommon.exceptions.DatasetModuleNotInstalledError`]:\n          The dataset tries to import a module that is not installed.\n        [~`libcommon.exceptions.ConfigNamesError`]:\n          If the list of configs could not be obtained using the datasets library.\n        [~`libcommon.exceptions.DatasetWithScriptNotSupportedError`]:\n            If the dataset has a dataset script and is not in the allow list.\n\n    Returns:\n        `DatasetConfigNamesResponse`: An object with the list of config names.\n    \"\"\"\n    logging.info(f\"get 'dateset-config-names' for {dataset=}\")\n    # get the list of splits in streaming mode\n    try:\n        config_name_items: list[ConfigNameItem] = [\n            {\"dataset\": dataset, \"config\": str(config)}\n            for config in sorted(\n                get_dataset_config_names(\n                    path=dataset,\n                    token=hf_token,\n                    trust_remote_code=resolve_trust_remote_code(\n                        dataset=dataset, allow_list=dataset_scripts_allow_list\n                    ),\n                )\n            )\n        ]\n    except _EmptyDatasetError as err:\n        raise EmptyDatasetError(\"The dataset is empty.\", cause=err) from err\n    except ValueError as err:\n        if \"trust_remote_code\" in str(err):\n            raise DatasetWithScriptNotSupportedError(\n                \"The dataset viewer doesn't support this dataset because it runs \"\n                \"arbitrary python code. Please open a discussion in the discussion tab \"\n                \"if you think this is an error and tag @lhoestq and @severo.\"\n            ) from err\n        raise ConfigNamesError(\"Cannot get the config names for the dataset.\", cause=err) from err\n    except ImportError as err:\n        # this should only happen if the dataset is in the allow list, which should soon disappear\n        raise DatasetModuleNotInstalledError(\n            \"The dataset tries to import a module that is not installed.\", cause=err\n        ) from err\n    except Exception as err:\n        raise ConfigNamesError(\"Cannot get the config names for the dataset.\", cause=err) from err\n\n    number_of_configs = len(config_name_items)\n    if number_of_configs > max_number:\n        raise DatasetWithTooManyConfigsError(\n            f\"The maximum number of configs allowed is {max_number}, dataset has {number_of_configs} configs.\"\n        )\n\n    return DatasetConfigNamesResponse(config_names=config_name_items)\n\n\nclass DatasetConfigNamesJobRunner(DatasetJobRunnerWithDatasetsCache):\n    @staticmethod\n    def get_job_type() -> str:\n        return \"dataset-config-names\"\n\n    def compute(self) -> CompleteJobResult:\n        return CompleteJobResult(\n            compute_config_names_response(\n                dataset=self.dataset,\n                hf_token=self.app_config.common.hf_token,\n                max_number=self.app_config.config_names.max_number,\n                dataset_scripts_allow_list=self.app_config.common.dataset_scripts_allow_list,\n            )\n        )\n", "path": "services/worker/src/worker/job_runners/dataset/config_names.py"}]}