Repository: strawberry-graphql/strawberry

Issue:
Enum missing @strawberry.enum has errors talk about user types, not enum itself
<!-- Provide a general summary of the bug in the title above. -->

<!--- This template is entirely optional and can be removed, but is here to help both you and us. -->
<!--- Anything on lines wrapped in comments like these will not show up in the final text. -->

## Describe the Bug

If an enum is used in a `@strawberry.type`, but is missing the `@strawberry.enum` decorator, there's an error, but that error refers to the `@strawberry.type`, rather than the enum.

```python
import enum

import strawberry

class MyEnum(enum.Enum):
    X = "x"


@strawberry.type
class Query:
    field: MyEnum


strawberry.Schema(Query)
```

Executing that file gives an exception: `TypeError: Query fields cannot be resolved. _enum_definition`. Note that the name referenced is `Query`. It'd be better if the error message referred to the enum itself: `TypeError: MyEnum fields cannot be resolved. _enum_definition`.

Work-around: manually check each enum fields of the `@strawberry.type`. (If required, binary search on the fields: comment out half of them, and then see if the error persists, if it disappears, the bad fields are the ones commented out, otherwise they're in the ones left alone, and continue.)

## System Information

 - Operating system: macOS
 - Strawberry version (if applicable): 0.126.0

## Additional Context

<!-- Add any other relevant information about the problem here. -->

Thanks for strawberry! 🍓 


Discussion:
@huonw thanks for the report! I've been doing some improvements on how errors work here: https://github.com/strawberry-graphql/strawberry/pull/2027

I'll see if I can make this error case better too 😊
Reproduction here: https://play.strawberry.rocks/?gist=6ac38ba61d3c1836e723c20857cee8b0

Resolving patch:
diff --git a/strawberry/annotation.py b/strawberry/annotation.py
--- a/strawberry/annotation.py
+++ b/strawberry/annotation.py
@@ -15,6 +15,7 @@
 
 from typing_extensions import Annotated, get_args, get_origin
 
+from strawberry.exceptions import StrawberryException
 from strawberry.private import is_private
 
 
@@ -157,7 +158,10 @@ def create_concrete_type(self, evaled_type: type) -> type:
         raise ValueError(f"Not supported {evaled_type}")
 
     def create_enum(self, evaled_type: Any) -> EnumDefinition:
-        return evaled_type._enum_definition
+        try:
+            return evaled_type._enum_definition
+        except AttributeError:
+            raise StrawberryException(f"{evaled_type} fields cannot be resolved.")
 
     def create_list(self, evaled_type: Any) -> StrawberryList:
         of_type = StrawberryAnnotation(
diff --git a/strawberry/exceptions.py b/strawberry/exceptions.py
--- a/strawberry/exceptions.py
+++ b/strawberry/exceptions.py
@@ -8,6 +8,10 @@
 from strawberry.type import StrawberryType
 
 
+class StrawberryException(Exception):
+    pass
+
+
 class ObjectIsNotAnEnumError(Exception):
     def __init__(self, obj: object):
         message = (
diff --git a/strawberry/schema/schema.py b/strawberry/schema/schema.py
--- a/strawberry/schema/schema.py
+++ b/strawberry/schema/schema.py
@@ -111,16 +111,24 @@ def __init__(
                     raise TypeError(f"{graphql_type} is not a named GraphQL Type")
                 graphql_types.append(graphql_type)
 
-        self._schema = GraphQLSchema(
-            query=query_type,
-            mutation=mutation_type,
-            subscription=subscription_type if subscription else None,
-            directives=specified_directives + tuple(graphql_directives),
-            types=graphql_types,
-            extensions={
-                GraphQLCoreConverter.DEFINITION_BACKREF: self,
-            },
-        )
+        try:
+            self._schema = GraphQLSchema(
+                query=query_type,
+                mutation=mutation_type,
+                subscription=subscription_type if subscription else None,
+                directives=specified_directives + tuple(graphql_directives),
+                types=graphql_types,
+                extensions={
+                    GraphQLCoreConverter.DEFINITION_BACKREF: self,
+                },
+            )
+        except TypeError as error:
+            from strawberry.exceptions import StrawberryException
+
+            if isinstance(error.__cause__, StrawberryException):
+                raise error.__cause__ from None
+
+            raise
 
         # attach our schema to the GraphQL schema instance
         self._schema._strawberry_schema = self  # type: ignore


Test patch: