We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Provide better error for Union of scalars.
This keeps coming from questions on discord
```py
union: Union[List[int], List[str]]
```
gives something like
```console
  File "/root/backend/env/lib/python3.10/site-packages/strawberry/schema/name_converter.py", line 99, in from_union
    assert hasattr(type_, "_type_definition")
AssertionError

The above exception was the direct cause of the following exception:
  File "/root/backend/env/lib/python3.10/site-packages/graphql/type/definition.py", line 811, in fields
    raise cls(f"{self.name} fields cannot be resolved. {error}") from error
TypeError: Query fields cannot be resolved
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `strawberry/exceptions/invalid_union_type.py`
Content:
```
1 from __future__ import annotations
2 
3 from inspect import getframeinfo, stack
4 from pathlib import Path
5 from typing import TYPE_CHECKING, Optional, Type
6 
7 from strawberry.exceptions.utils.source_finder import SourceFinder
8 from strawberry.utils.cached_property import cached_property
9 
10 from .exception import StrawberryException
11 
12 if TYPE_CHECKING:
13     from strawberry.union import StrawberryUnion
14 
15     from .exception_source import ExceptionSource
16 
17 
18 class InvalidUnionTypeError(StrawberryException):
19     """The union is constructed with an invalid type"""
20 
21     invalid_type: object
22 
23     def __init__(self, union_name: str, invalid_type: object) -> None:
24         from strawberry.custom_scalar import ScalarWrapper
25 
26         self.union_name = union_name
27         self.invalid_type = invalid_type
28 
29         # assuming that the exception happens two stack frames above the current one.
30         # one is our code checking for invalid types, the other is the caller
31         self.frame = getframeinfo(stack()[2][0])
32 
33         if isinstance(invalid_type, ScalarWrapper):
34             type_name = invalid_type.wrap.__name__
35         else:
36             type_name = invalid_type.__name__  # type: ignore
37 
38         self.message = f"Type `{type_name}` cannot be used in a GraphQL Union"
39         self.rich_message = (
40             f"Type `[underline]{type_name}[/]` cannot be used in a GraphQL Union"
41         )
42         self.suggestion = (
43             "To fix this error you should replace the type a strawberry.type"
44         )
45         self.annotation_message = "invalid type here"
46 
47     @cached_property
48     def exception_source(self) -> Optional[ExceptionSource]:
49         path = Path(self.frame.filename)
50 
51         source_finder = SourceFinder()
52 
53         return source_finder.find_union_call(path, self.union_name, self.invalid_type)
54 
55 
56 class InvalidTypeForUnionMergeError(StrawberryException):
57     """A specialized version of InvalidUnionTypeError for when trying
58     to merge unions using the pipe operator."""
59 
60     invalid_type: Type
61 
62     def __init__(self, union: StrawberryUnion, other: object) -> None:
63         self.union = union
64         self.other = other
65 
66         # assuming that the exception happens two stack frames above the current one.
67         # one is our code checking for invalid types, the other is the caller
68         self.frame = getframeinfo(stack()[2][0])
69 
70         other_name = getattr(other, "__name__", str(other))
71 
72         self.message = f"`{other_name}` cannot be used when merging GraphQL Unions"
73         self.rich_message = (
74             f"`[underline]{other_name}[/]` cannot be used when merging GraphQL Unions"
75         )
76         self.suggestion = ""
77         self.annotation_message = "invalid type here"
78 
79     @cached_property
80     def exception_source(self) -> Optional[ExceptionSource]:
81         source_finder = SourceFinder()
82 
83         return source_finder.find_union_merge(self.union, self.other, frame=self.frame)
84
```
--- 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/strawberry/exceptions/invalid_union_type.py b/strawberry/exceptions/invalid_union_type.py
--- a/strawberry/exceptions/invalid_union_type.py
+++ b/strawberry/exceptions/invalid_union_type.py
@@ -33,7 +33,11 @@
         if isinstance(invalid_type, ScalarWrapper):
             type_name = invalid_type.wrap.__name__
         else:
-            type_name = invalid_type.__name__  # type: ignore
+            try:
+                type_name = invalid_type.__name__  # type: ignore
+            except AttributeError:
+                # might be StrawberryList instance
+                type_name = invalid_type.__class__.__name__
 
         self.message = f"Type `{type_name}` cannot be used in a GraphQL Union"
         self.rich_message = (

{"golden_diff": "diff --git a/strawberry/exceptions/invalid_union_type.py b/strawberry/exceptions/invalid_union_type.py\n--- a/strawberry/exceptions/invalid_union_type.py\n+++ b/strawberry/exceptions/invalid_union_type.py\n@@ -33,7 +33,11 @@\n         if isinstance(invalid_type, ScalarWrapper):\n             type_name = invalid_type.wrap.__name__\n         else:\n-            type_name = invalid_type.__name__  # type: ignore\n+            try:\n+                type_name = invalid_type.__name__  # type: ignore\n+            except AttributeError:\n+                # might be StrawberryList instance\n+                type_name = invalid_type.__class__.__name__\n \n         self.message = f\"Type `{type_name}` cannot be used in a GraphQL Union\"\n         self.rich_message = (\n", "issue": "Provide better error for Union of scalars.\nThis keeps coming from questions on discord\r\n```py\r\nunion: Union[List[int], List[str]]\r\n```\r\ngives something like\r\n```console\r\n  File \"/root/backend/env/lib/python3.10/site-packages/strawberry/schema/name_converter.py\", line 99, in from_union\r\n    assert hasattr(type_, \"_type_definition\")\r\nAssertionError\r\n\r\nThe above exception was the direct cause of the following exception:\r\n  File \"/root/backend/env/lib/python3.10/site-packages/graphql/type/definition.py\", line 811, in fields\r\n    raise cls(f\"{self.name} fields cannot be resolved. {error}\") from error\r\nTypeError: Query fields cannot be resolved\r\n```\n", "before_files": [{"content": "from __future__ import annotations\n\nfrom inspect import getframeinfo, stack\nfrom pathlib import Path\nfrom typing import TYPE_CHECKING, Optional, Type\n\nfrom strawberry.exceptions.utils.source_finder import SourceFinder\nfrom strawberry.utils.cached_property import cached_property\n\nfrom .exception import StrawberryException\n\nif TYPE_CHECKING:\n    from strawberry.union import StrawberryUnion\n\n    from .exception_source import ExceptionSource\n\n\nclass InvalidUnionTypeError(StrawberryException):\n    \"\"\"The union is constructed with an invalid type\"\"\"\n\n    invalid_type: object\n\n    def __init__(self, union_name: str, invalid_type: object) -> None:\n        from strawberry.custom_scalar import ScalarWrapper\n\n        self.union_name = union_name\n        self.invalid_type = invalid_type\n\n        # assuming that the exception happens two stack frames above the current one.\n        # one is our code checking for invalid types, the other is the caller\n        self.frame = getframeinfo(stack()[2][0])\n\n        if isinstance(invalid_type, ScalarWrapper):\n            type_name = invalid_type.wrap.__name__\n        else:\n            type_name = invalid_type.__name__  # type: ignore\n\n        self.message = f\"Type `{type_name}` cannot be used in a GraphQL Union\"\n        self.rich_message = (\n            f\"Type `[underline]{type_name}[/]` cannot be used in a GraphQL Union\"\n        )\n        self.suggestion = (\n            \"To fix this error you should replace the type a strawberry.type\"\n        )\n        self.annotation_message = \"invalid type here\"\n\n    @cached_property\n    def exception_source(self) -> Optional[ExceptionSource]:\n        path = Path(self.frame.filename)\n\n        source_finder = SourceFinder()\n\n        return source_finder.find_union_call(path, self.union_name, self.invalid_type)\n\n\nclass InvalidTypeForUnionMergeError(StrawberryException):\n    \"\"\"A specialized version of InvalidUnionTypeError for when trying\n    to merge unions using the pipe operator.\"\"\"\n\n    invalid_type: Type\n\n    def __init__(self, union: StrawberryUnion, other: object) -> None:\n        self.union = union\n        self.other = other\n\n        # assuming that the exception happens two stack frames above the current one.\n        # one is our code checking for invalid types, the other is the caller\n        self.frame = getframeinfo(stack()[2][0])\n\n        other_name = getattr(other, \"__name__\", str(other))\n\n        self.message = f\"`{other_name}` cannot be used when merging GraphQL Unions\"\n        self.rich_message = (\n            f\"`[underline]{other_name}[/]` cannot be used when merging GraphQL Unions\"\n        )\n        self.suggestion = \"\"\n        self.annotation_message = \"invalid type here\"\n\n    @cached_property\n    def exception_source(self) -> Optional[ExceptionSource]:\n        source_finder = SourceFinder()\n\n        return source_finder.find_union_merge(self.union, self.other, frame=self.frame)\n", "path": "strawberry/exceptions/invalid_union_type.py"}], "after_files": [{"content": "from __future__ import annotations\n\nfrom inspect import getframeinfo, stack\nfrom pathlib import Path\nfrom typing import TYPE_CHECKING, Optional, Type\n\nfrom strawberry.exceptions.utils.source_finder import SourceFinder\nfrom strawberry.utils.cached_property import cached_property\n\nfrom .exception import StrawberryException\n\nif TYPE_CHECKING:\n    from strawberry.union import StrawberryUnion\n\n    from .exception_source import ExceptionSource\n\n\nclass InvalidUnionTypeError(StrawberryException):\n    \"\"\"The union is constructed with an invalid type\"\"\"\n\n    invalid_type: object\n\n    def __init__(self, union_name: str, invalid_type: object) -> None:\n        from strawberry.custom_scalar import ScalarWrapper\n\n        self.union_name = union_name\n        self.invalid_type = invalid_type\n\n        # assuming that the exception happens two stack frames above the current one.\n        # one is our code checking for invalid types, the other is the caller\n        self.frame = getframeinfo(stack()[2][0])\n\n        if isinstance(invalid_type, ScalarWrapper):\n            type_name = invalid_type.wrap.__name__\n        else:\n            try:\n                type_name = invalid_type.__name__  # type: ignore\n            except AttributeError:\n                # might be StrawberryList instance\n                type_name = invalid_type.__class__.__name__\n\n        self.message = f\"Type `{type_name}` cannot be used in a GraphQL Union\"\n        self.rich_message = (\n            f\"Type `[underline]{type_name}[/]` cannot be used in a GraphQL Union\"\n        )\n        self.suggestion = (\n            \"To fix this error you should replace the type a strawberry.type\"\n        )\n        self.annotation_message = \"invalid type here\"\n\n    @cached_property\n    def exception_source(self) -> Optional[ExceptionSource]:\n        path = Path(self.frame.filename)\n\n        source_finder = SourceFinder()\n\n        return source_finder.find_union_call(path, self.union_name, self.invalid_type)\n\n\nclass InvalidTypeForUnionMergeError(StrawberryException):\n    \"\"\"A specialized version of InvalidUnionTypeError for when trying\n    to merge unions using the pipe operator.\"\"\"\n\n    invalid_type: Type\n\n    def __init__(self, union: StrawberryUnion, other: object) -> None:\n        self.union = union\n        self.other = other\n\n        # assuming that the exception happens two stack frames above the current one.\n        # one is our code checking for invalid types, the other is the caller\n        self.frame = getframeinfo(stack()[2][0])\n\n        other_name = getattr(other, \"__name__\", str(other))\n\n        self.message = f\"`{other_name}` cannot be used when merging GraphQL Unions\"\n        self.rich_message = (\n            f\"`[underline]{other_name}[/]` cannot be used when merging GraphQL Unions\"\n        )\n        self.suggestion = \"\"\n        self.annotation_message = \"invalid type here\"\n\n    @cached_property\n    def exception_source(self) -> Optional[ExceptionSource]:\n        source_finder = SourceFinder()\n\n        return source_finder.find_union_merge(self.union, self.other, frame=self.frame)\n", "path": "strawberry/exceptions/invalid_union_type.py"}]}