Repository: evennia/evennia

Issue:
[BUG - Develop] Calls to int() wrapped in `TypeError`, should be `ValueError`, in funcparser.py
#### Describe the bug
There are a bunch of calls in the funcparser default callables that are set up to do int conversion/parsing, ie `int(some_var)`. Many if not all of these are wrapped in a try/except block to anticipate the value not being parseable. However, there is a repeated mistake where the caught exception is `TypeError` when it should be `ValueError`:

```
Python 3.9.14 (main, Sep 30 2022, 20:25:24)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> int('foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'foo'
```

See  the following:

https://github.com/evennia/evennia/blob/develop/evennia/utils/funcparser.py#L685
https://github.com/evennia/evennia/blob/develop/evennia/utils/funcparser.py#L917
https://github.com/evennia/evennia/blob/develop/evennia/utils/funcparser.py#L949

etc

#### To Reproduce
N/A

#### Expected behavior
Catch ValueError if the logic in the catch is expected to run. Otherwise, this may be no big deal because the FuncParser itself handles exceptions and the calls to *convert_types would raise the exception before it got to this line if the widths aren't strings. So in that case, remove the exception handling altogether.

#### Develop-branch commit
b0f24f9975e14fddeabef06a19b5b61575957b1c

#### Additional context
N/A



Discussion:
Fair, the exceptions should be updated, or where it makes sense, handle both `TypeError` and `ValueError`. Normally a funcparser function should gracefully handle errors. 

Resolving patch:
diff --git a/evennia/utils/funcparser.py b/evennia/utils/funcparser.py
--- a/evennia/utils/funcparser.py
+++ b/evennia/utils/funcparser.py
@@ -661,6 +661,8 @@ def funcparser_callable_toint(*args, **kwargs):
         return int(inp)
     except TypeError:
         return inp
+    except ValueError:
+        return inp
 
 
 def funcparser_callable_int2str(*args, **kwargs):
@@ -902,7 +904,7 @@ def funcparser_callable_pad(*args, **kwargs):
     nrest = len(rest)
     try:
         width = int(kwargs.get("width", rest[0] if nrest > 0 else _CLIENT_DEFAULT_WIDTH))
-    except TypeError:
+    except ValueError:
         width = _CLIENT_DEFAULT_WIDTH
 
     align = kwargs.get("align", rest[1] if nrest > 1 else "c")
@@ -934,7 +936,7 @@ def funcparser_callable_crop(*args, **kwargs):
     nrest = len(rest)
     try:
         width = int(kwargs.get("width", rest[0] if nrest > 0 else _CLIENT_DEFAULT_WIDTH))
-    except TypeError:
+    except ValueError:
         width = _CLIENT_DEFAULT_WIDTH
     suffix = kwargs.get("suffix", rest[1] if nrest > 1 else "[...]")
     return crop(str(text), width=width, suffix=str(suffix))
@@ -951,7 +953,7 @@ def funcparser_callable_space(*args, **kwarg):
         return ""
     try:
         width = int(args[0])
-    except TypeError:
+    except ValueError:
         width = 1
     return " " * width
 
@@ -980,12 +982,12 @@ def funcparser_callable_justify(*args, **kwargs):
     lrest = len(rest)
     try:
         width = int(kwargs.get("width", rest[0] if lrest > 0 else _CLIENT_DEFAULT_WIDTH))
-    except TypeError:
+    except ValueError:
         width = _CLIENT_DEFAULT_WIDTH
     align = str(kwargs.get("align", rest[1] if lrest > 1 else "f"))
     try:
         indent = int(kwargs.get("indent", rest[2] if lrest > 2 else 0))
-    except TypeError:
+    except ValueError:
         indent = 0
     return justify(str(text), width=width, align=align, indent=indent)
 


Test patch: