Repository: saleor/saleor

Issue:
Errors in schema should be required.
In PR #5293 we introduce a rule that all error fields should be non-nullable. 
We should fix error fields in mutations: 
- [ ] `SetPassword`
- [ ] `CreateToken`


Discussion:

Resolving patch:
diff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.py
--- a/saleor/graphql/account/mutations/base.py
+++ b/saleor/graphql/account/mutations/base.py
@@ -45,12 +45,6 @@ def can_edit_address(user, address):
 
 
 class SetPassword(CreateToken):
-    user = graphene.Field(User, description="A user instance with new password.")
-    account_errors = graphene.List(
-        graphene.NonNull(AccountError),
-        description="List of errors that occurred executing the mutation.",
-    )
-
     class Arguments:
         token = graphene.String(
             description="A one-time token required to set the password.", required=True
@@ -99,14 +93,6 @@ def _set_password_for_user(cls, email, password, token):
         user.save(update_fields=["password"])
         account_events.customer_password_reset_event(user=user)
 
-    @classmethod
-    def handle_typed_errors(cls, errors: list):
-        account_errors = [
-            AccountError(field=e.field, message=e.message, code=code)
-            for e, code, _params in errors
-        ]
-        return cls(errors=[e[0] for e in errors], account_errors=account_errors)
-
 
 class RequestPasswordReset(BaseMutation):
     class Arguments:
diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.py
--- a/saleor/graphql/core/mutations.py
+++ b/saleor/graphql/core/mutations.py
@@ -20,6 +20,7 @@
 from ..account.types import User
 from ..utils import get_nodes
 from .types import Error, Upload
+from .types.common import AccountError
 from .utils import from_global_id_strict_type, snake_to_camel_case
 from .utils.error_codes import get_error_code_from_error
 
@@ -588,7 +589,12 @@ class CreateToken(ObtainJSONWebToken):
     """
 
     errors = graphene.List(graphene.NonNull(Error), required=True)
-    user = graphene.Field(User)
+    account_errors = graphene.List(
+        graphene.NonNull(AccountError),
+        description="List of errors that occurred executing the mutation.",
+        required=True,
+    )
+    user = graphene.Field(User, description="A user instance.")
 
     @classmethod
     def mutate(cls, root, info, **kwargs):
@@ -596,12 +602,23 @@ def mutate(cls, root, info, **kwargs):
             result = super().mutate(root, info, **kwargs)
         except JSONWebTokenError as e:
             return CreateToken(errors=[Error(message=str(e))])
+        except ValidationError as e:
+            errors = validation_error_to_error_type(e)
+            return cls.handle_typed_errors(errors)
         else:
             return result
 
+    @classmethod
+    def handle_typed_errors(cls, errors: list):
+        account_errors = [
+            AccountError(field=e.field, message=e.message, code=code)
+            for e, code, _params in errors
+        ]
+        return cls(errors=[e[0] for e in errors], account_errors=account_errors)
+
     @classmethod
     def resolve(cls, root, info, **kwargs):
-        return cls(user=info.context.user, errors=[])
+        return cls(user=info.context.user, errors=[], account_errors=[])
 
 
 class VerifyToken(Verify):


Test patch: