Repository: edgedb/edgedb

Issue:
Typo in error message
- EdgeDB Version: 2.0-dev.6500+local

Error message when casting to 'bigint' mentions 'decimal' type:
```edgeql
select <bigint>'12345678901234567890n'
# InvalidValueError: invalid input syntax for type std::decimal: "12345678901234567890n"
```



Discussion:

Resolving patch:
diff --git a/edb/buildmeta.py b/edb/buildmeta.py
--- a/edb/buildmeta.py
+++ b/edb/buildmeta.py
@@ -44,7 +44,7 @@
 
 
 # Increment this whenever the database layout or stdlib changes.
-EDGEDB_CATALOG_VERSION = 2022_05_06_00_00
+EDGEDB_CATALOG_VERSION = 2022_05_12_00_00
 EDGEDB_MAJOR_VERSION = 2
 
 
diff --git a/edb/pgsql/metaschema.py b/edb/pgsql/metaschema.py
--- a/edb/pgsql/metaschema.py
+++ b/edb/pgsql/metaschema.py
@@ -498,25 +498,36 @@ def __init__(self) -> None:
 
 class StrToBigint(dbops.Function):
     """Parse bigint from text."""
+
+    # The plpgsql execption handling nonsense is actually just so that
+    # we can produce an exception that mentions edgedb.bigint_t
+    # instead of numeric, and thus produce the right user-facing
+    # exception. As a nice side effect it is like twice as fast
+    # as the previous code too.
     text = r'''
-        SELECT
-            (CASE WHEN scale(v.column1) = 0 THEN
-                v.column1
+        DECLARE
+            v numeric;
+        BEGIN
+            BEGIN
+              v := val::numeric;
+            EXCEPTION
+              WHEN OTHERS THEN
+                 v := NULL;
+            END;
+
+            IF scale(v) = 0 THEN
+                RETURN v::edgedb.bigint_t;
             ELSE
-                edgedb.raise(
+                EXECUTE edgedb.raise(
                     NULL::numeric,
                     'invalid_text_representation',
                     msg => (
-                        'invalid syntax for edgedb.bigint_t: '
+                        'invalid input syntax for type edgedb.bigint_t: '
                         || quote_literal(val)
                     )
-                )
-            END)::edgedb.bigint_t
-        FROM
-            (VALUES (
-                val::numeric
-            )) AS v
-        ;
+                );
+            END IF;
+        END;
     '''
 
     def __init__(self) -> None:
@@ -524,6 +535,7 @@ def __init__(self) -> None:
             name=('edgedb', 'str_to_bigint'),
             args=[('val', ('text',))],
             returns=('edgedb', 'bigint_t'),
+            language='plpgsql',
             # Stable because it's raising exceptions.
             volatility='stable',
             strict=True,
@@ -541,7 +553,7 @@ class StrToDecimal(dbops.Function):
                     NULL::numeric,
                     'invalid_text_representation',
                     msg => (
-                        'invalid syntax for numeric: '
+                        'invalid input syntax for type numeric: '
                         || quote_literal(val)
                     )
                 )
@@ -2510,7 +2522,8 @@ class StrToBool(dbops.Function):
                 edgedb.raise(
                     NULL::text[],
                     'invalid_text_representation',
-                    msg => 'invalid syntax for bool: ' || quote_literal(val)
+                    msg => 'invalid input syntax for type bool: '
+                           || quote_literal(val)
                 )
             )
         )[2] IS NULL;


Test patch:
diff --git a/tests/test_edgeql_casts.py b/tests/test_edgeql_casts.py
--- a/tests/test_edgeql_casts.py
+++ b/tests/test_edgeql_casts.py
@@ -566,7 +566,7 @@ async def test_edgeql_casts_str_02(self):
                         't', 'f', 'tr', 'fa'}:
             async with self.assertRaisesRegexTx(
                     edgedb.InvalidValueError,
-                    fr"invalid syntax for std::bool: '{variant}'"):
+                    fr"invalid input syntax for type std::bool: '{variant}'"):
                 await self.con.query_single(f'SELECT <bool>"{variant}"')
 
         self.assertTrue(
@@ -1364,6 +1364,19 @@ async def test_edgeql_casts_numeric_07(self):
                 [1],
             )
 
+    async def test_edgeql_casts_numeric_08(self):
+        async with self.assertRaisesRegexTx(
+                edgedb.InvalidValueError,
+                r'invalid input syntax for type std::bigint'):
+            await self.con.query_single(
+                'SELECT <bigint>"100000n"')
+
+        async with self.assertRaisesRegexTx(
+                edgedb.InvalidValueError,
+                r'invalid input syntax for type std::decimal'):
+            await self.con.query_single(
+                'SELECT <decimal>"12313.132n"')
+
     async def test_edgeql_casts_collections_01(self):
         await self.assert_query_result(
             r'''SELECT <array<str>>[1, 2, 3];''',
diff --git a/tests/test_edgeql_datatypes.py b/tests/test_edgeql_datatypes.py
--- a/tests/test_edgeql_datatypes.py
+++ b/tests/test_edgeql_datatypes.py
@@ -894,7 +894,7 @@ async def test_edgeql_dt_enum_01(self):
     async def test_edgeql_dt_bigint_01(self):
         with self.assertRaisesRegex(
             edgedb.InvalidValueError,
-            'invalid syntax for std::bigint'
+            'invalid input syntax for type std::bigint'
         ):
             await self.con.execute(
                 r'''
diff --git a/tests/test_edgeql_functions.py b/tests/test_edgeql_functions.py
--- a/tests/test_edgeql_functions.py
+++ b/tests/test_edgeql_functions.py
@@ -2869,7 +2869,7 @@ async def test_edgeql_functions_to_bigint_01(self):
 
     async def test_edgeql_functions_to_bigint_02(self):
         with self.assertRaisesRegex(edgedb.InvalidValueError,
-                                    'invalid syntax'):
+                                    'invalid input syntax'):
             async with self.con.transaction():
                 await self.con.query('''SELECT to_bigint('1.02')''')