We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Kit leastsq should not except BaseException
https://github.com/wright-group/WrightTools/blob/f22920579f45632b4123661d9832ff0cc1b614c4/WrightTools/kit/_leastsq.py#L74

The exception caught should be limited to those known to be raised inside.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `WrightTools/kit/_leastsq.py`
Content:
```
1 """Least-square fitting tools."""
2 
3 
4 # --- import --------------------------------------------------------------------------------------
5 
6 
7 from ._utilities import Timer
8 
9 import numpy as np
10 
11 from scipy import optimize as scipy_optimize
12 
13 
14 # --- define --------------------------------------------------------------------------------------
15 
16 
17 __all__ = ["leastsqfitter"]
18 
19 
20 # --- functions -----------------------------------------------------------------------------------
21 
22 
23 def leastsqfitter(p0, datax, datay, function, verbose=False, cov_verbose=False):
24     """Conveniently call scipy.optmize.leastsq().
25 
26     Returns fit parameters and their errors.
27 
28     Parameters
29     ----------
30     p0 : list
31         list of guess parameters to pass to function
32     datax : array
33         array of independent values
34     datay : array
35         array of dependent values
36     function : function
37         function object to fit data to. Must be of the callable form function(p, x)
38     verbose : bool
39         toggles printing of fit time, fit params, and fit param errors
40     cov_verbose : bool
41         toggles printing of covarience matrix
42 
43     Returns
44     -------
45     pfit_leastsq : list
46         list of fit parameters. s.t. the error between datay and function(p, datax) is minimized
47     perr_leastsq : list
48         list of fit parameter errors (1 std)
49     """
50     timer = Timer(verbose=False)
51     with timer:
52         # define error function
53         def errfunc(p, x, y):
54             return y - function(p, x)
55 
56         # run optimization
57         pfit_leastsq, pcov, infodict, errmsg, success = scipy_optimize.leastsq(
58             errfunc, p0, args=(datax, datay), full_output=1, epsfcn=0.0001
59         )
60         # calculate covarience matrix
61         # original idea https://stackoverflow.com/a/21844726
62         if (len(datay) > len(p0)) and pcov is not None:
63             s_sq = (errfunc(pfit_leastsq, datax, datay) ** 2).sum() / (len(datay) - len(p0))
64             pcov = pcov * s_sq
65             if cov_verbose:
66                 print(pcov)
67         else:
68             pcov = np.inf
69         # calculate and write errors
70         error = []
71         for i in range(len(pfit_leastsq)):
72             try:
73                 error.append(np.absolute(pcov[i][i]) ** 0.5)
74             except BaseException:
75                 error.append(0.00)
76         perr_leastsq = np.array(error)
77     # exit
78     if verbose:
79         print("fit params:       ", pfit_leastsq)
80         print("fit params error: ", perr_leastsq)
81         print("fitting done in %f seconds" % timer.interval)
82     return pfit_leastsq, perr_leastsq
83
```
--- 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/WrightTools/kit/_leastsq.py b/WrightTools/kit/_leastsq.py
--- a/WrightTools/kit/_leastsq.py
+++ b/WrightTools/kit/_leastsq.py
@@ -71,7 +71,7 @@
         for i in range(len(pfit_leastsq)):
             try:
                 error.append(np.absolute(pcov[i][i]) ** 0.5)
-            except BaseException:
+            except IndexError:
                 error.append(0.00)
         perr_leastsq = np.array(error)
     # exit

{"golden_diff": "diff --git a/WrightTools/kit/_leastsq.py b/WrightTools/kit/_leastsq.py\n--- a/WrightTools/kit/_leastsq.py\n+++ b/WrightTools/kit/_leastsq.py\n@@ -71,7 +71,7 @@\n         for i in range(len(pfit_leastsq)):\n             try:\n                 error.append(np.absolute(pcov[i][i]) ** 0.5)\n-            except BaseException:\n+            except IndexError:\n                 error.append(0.00)\n         perr_leastsq = np.array(error)\n     # exit\n", "issue": "Kit leastsq should not except BaseException\nhttps://github.com/wright-group/WrightTools/blob/f22920579f45632b4123661d9832ff0cc1b614c4/WrightTools/kit/_leastsq.py#L74\r\n\r\nThe exception caught should be limited to those known to be raised inside.\n", "before_files": [{"content": "\"\"\"Least-square fitting tools.\"\"\"\n\n\n# --- import --------------------------------------------------------------------------------------\n\n\nfrom ._utilities import Timer\n\nimport numpy as np\n\nfrom scipy import optimize as scipy_optimize\n\n\n# --- define --------------------------------------------------------------------------------------\n\n\n__all__ = [\"leastsqfitter\"]\n\n\n# --- functions -----------------------------------------------------------------------------------\n\n\ndef leastsqfitter(p0, datax, datay, function, verbose=False, cov_verbose=False):\n    \"\"\"Conveniently call scipy.optmize.leastsq().\n\n    Returns fit parameters and their errors.\n\n    Parameters\n    ----------\n    p0 : list\n        list of guess parameters to pass to function\n    datax : array\n        array of independent values\n    datay : array\n        array of dependent values\n    function : function\n        function object to fit data to. Must be of the callable form function(p, x)\n    verbose : bool\n        toggles printing of fit time, fit params, and fit param errors\n    cov_verbose : bool\n        toggles printing of covarience matrix\n\n    Returns\n    -------\n    pfit_leastsq : list\n        list of fit parameters. s.t. the error between datay and function(p, datax) is minimized\n    perr_leastsq : list\n        list of fit parameter errors (1 std)\n    \"\"\"\n    timer = Timer(verbose=False)\n    with timer:\n        # define error function\n        def errfunc(p, x, y):\n            return y - function(p, x)\n\n        # run optimization\n        pfit_leastsq, pcov, infodict, errmsg, success = scipy_optimize.leastsq(\n            errfunc, p0, args=(datax, datay), full_output=1, epsfcn=0.0001\n        )\n        # calculate covarience matrix\n        # original idea https://stackoverflow.com/a/21844726\n        if (len(datay) > len(p0)) and pcov is not None:\n            s_sq = (errfunc(pfit_leastsq, datax, datay) ** 2).sum() / (len(datay) - len(p0))\n            pcov = pcov * s_sq\n            if cov_verbose:\n                print(pcov)\n        else:\n            pcov = np.inf\n        # calculate and write errors\n        error = []\n        for i in range(len(pfit_leastsq)):\n            try:\n                error.append(np.absolute(pcov[i][i]) ** 0.5)\n            except BaseException:\n                error.append(0.00)\n        perr_leastsq = np.array(error)\n    # exit\n    if verbose:\n        print(\"fit params:       \", pfit_leastsq)\n        print(\"fit params error: \", perr_leastsq)\n        print(\"fitting done in %f seconds\" % timer.interval)\n    return pfit_leastsq, perr_leastsq\n", "path": "WrightTools/kit/_leastsq.py"}], "after_files": [{"content": "\"\"\"Least-square fitting tools.\"\"\"\n\n\n# --- import --------------------------------------------------------------------------------------\n\n\nfrom ._utilities import Timer\n\nimport numpy as np\n\nfrom scipy import optimize as scipy_optimize\n\n\n# --- define --------------------------------------------------------------------------------------\n\n\n__all__ = [\"leastsqfitter\"]\n\n\n# --- functions -----------------------------------------------------------------------------------\n\n\ndef leastsqfitter(p0, datax, datay, function, verbose=False, cov_verbose=False):\n    \"\"\"Conveniently call scipy.optmize.leastsq().\n\n    Returns fit parameters and their errors.\n\n    Parameters\n    ----------\n    p0 : list\n        list of guess parameters to pass to function\n    datax : array\n        array of independent values\n    datay : array\n        array of dependent values\n    function : function\n        function object to fit data to. Must be of the callable form function(p, x)\n    verbose : bool\n        toggles printing of fit time, fit params, and fit param errors\n    cov_verbose : bool\n        toggles printing of covarience matrix\n\n    Returns\n    -------\n    pfit_leastsq : list\n        list of fit parameters. s.t. the error between datay and function(p, datax) is minimized\n    perr_leastsq : list\n        list of fit parameter errors (1 std)\n    \"\"\"\n    timer = Timer(verbose=False)\n    with timer:\n        # define error function\n        def errfunc(p, x, y):\n            return y - function(p, x)\n\n        # run optimization\n        pfit_leastsq, pcov, infodict, errmsg, success = scipy_optimize.leastsq(\n            errfunc, p0, args=(datax, datay), full_output=1, epsfcn=0.0001\n        )\n        # calculate covarience matrix\n        # original idea https://stackoverflow.com/a/21844726\n        if (len(datay) > len(p0)) and pcov is not None:\n            s_sq = (errfunc(pfit_leastsq, datax, datay) ** 2).sum() / (len(datay) - len(p0))\n            pcov = pcov * s_sq\n            if cov_verbose:\n                print(pcov)\n        else:\n            pcov = np.inf\n        # calculate and write errors\n        error = []\n        for i in range(len(pfit_leastsq)):\n            try:\n                error.append(np.absolute(pcov[i][i]) ** 0.5)\n            except IndexError:\n                error.append(0.00)\n        perr_leastsq = np.array(error)\n    # exit\n    if verbose:\n        print(\"fit params:       \", pfit_leastsq)\n        print(\"fit params error: \", perr_leastsq)\n        print(\"fitting done in %f seconds\" % timer.interval)\n    return pfit_leastsq, perr_leastsq\n", "path": "WrightTools/kit/_leastsq.py"}]}