Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
"Errors": [
{
"message": "Variable `ep` is required.",
"locations": [
{
"line": 1,
"column": 77
}
],
"extensions": {
"code": "HC0018",
"variable": "ep"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
"Errors": [
{
"message": "Variable `ep` is required.",
"locations": [
{
"line": 3,
"column": 25
}
],
"extensions": {
"code": "HC0018",
"variable": "ep"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ private void SetError(
.SetMessage(AuthorizeMiddleware_NoDefaultPolicy)
.SetCode(ErrorCodes.Authentication.NoDefaultPolicy)
.SetPath(context.Path)
.AddLocations(context.Selection)
.Build(),
AuthorizeResult.PolicyNotFound
=> ErrorBuilder.New()
Expand All @@ -78,7 +77,6 @@ private void SetError(
_directive.Policy)
.SetCode(ErrorCodes.Authentication.PolicyNotFound)
.SetPath(context.Path)
.AddLocations(context.Selection)
.Build(),
_
=> ErrorBuilder.New()
Expand All @@ -88,7 +86,6 @@ private void SetError(
? ErrorCodes.Authentication.NotAuthorized
: ErrorCodes.Authentication.NotAuthenticated)
.SetPath(context.Path)
.AddLocations(context.Selection)
.Build()
};
}
14 changes: 0 additions & 14 deletions src/HotChocolate/Core/src/Types/Execution/ErrorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,37 @@ public static IError ArgumentNonNullError(
.SetMessage(
ErrorHelper_ArgumentNonNullError_Message,
argument.Name.Value)
.AddLocation(argument)
.SetInputPath(validationResult.Path)
.Build();
}

public static IError InvalidLeafValue(
GraphQLException exception,
Selection selection,
Path path)
{
return ErrorBuilder.FromError(exception.Errors[0])
.AddLocations(selection)
.SetPath(path)
.SetCode(ErrorCodes.Execution.CannotSerializeLeafValue)
.Build();
}

public static IError UnexpectedLeafValueSerializationError(
Exception exception,
Selection selection,
Path path)
{
return ErrorBuilder
.FromException(exception)
.AddLocations(selection)
.SetPath(path)
.SetCode(ErrorCodes.Execution.CannotSerializeLeafValue)
.Build();
}

public static IError UnableToResolveTheAbstractType(
string typeName,
Selection selection,
Path path)
{
return ErrorBuilder.New()
.SetMessage(ErrorHelper_UnableToResolveTheAbstractType_Message, typeName)
.AddLocations(selection)
.SetPath(path)
.SetCode(ErrorCodes.Execution.CannotResolveAbstractType)
.Build();
Expand All @@ -62,12 +55,10 @@ public static IError UnableToResolveTheAbstractType(
public static IError UnexpectedErrorWhileResolvingAbstractType(
Exception exception,
string typeName,
Selection selection,
Path path)
{
return ErrorBuilder.New()
.SetMessage(ErrorHelper_UnableToResolveTheAbstractType_Message, typeName)
.AddLocations(selection)
.SetPath(path)
.SetCode(ErrorCodes.Execution.CannotResolveAbstractType)
.SetException(exception)
Expand All @@ -76,24 +67,20 @@ public static IError UnexpectedErrorWhileResolvingAbstractType(

public static IError ListValueIsNotSupported(
Type listType,
Selection selection,
Path path)
{
return ErrorBuilder.New()
.SetMessage(ErrorHelper_ListValueIsNotSupported_Message, listType.FullName)
.AddLocations(selection)
.SetPath(path)
.SetCode(ErrorCodes.Execution.ListTypeNotSupported)
.Build();
}

public static IError UnexpectedValueCompletionError(
Selection selection,
Path path)
{
return ErrorBuilder.New()
.SetMessage(ErrorHelper_UnexpectedValueCompletionError_Message)
.AddLocations(selection)
.SetPath(path)
.SetCode(ErrorCodes.Execution.ListTypeNotSupported)
.Build();
Expand Down Expand Up @@ -137,7 +124,6 @@ public static IError ValueCompletion_CouldNotResolveAbstractType(
result.GetType().FullName ?? result.GetType().Name,
selection.ResponseName)
.SetPath(path)
.AddLocations(selection)
.Build();

public static OperationResult OperationKindNotAllowed(RequestFlags requiredFlag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ internal static class OperationContextExtensions
public OperationContext ReportError(
Exception exception,
MiddlewareContext resolverContext,
ISelection? selection = null,
Path? path = null)
{
selection ??= resolverContext.Selection;
path ??= resolverContext.Path;

ArgumentNullException.ThrowIfNull(exception);
Expand All @@ -32,7 +30,6 @@ public OperationContext ReportError(
var error = ErrorBuilder
.FromException(exception)
.SetPath(path)
.AddLocations(selection.GetSyntaxNodes())
.Build();
Comment thread
michaelstaib marked this conversation as resolved.

context.ReportError(error, resolverContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public T ArgumentValue<T>(string name)
}
catch (LeafCoercionException ex)
{
var syntaxNode = Selection.Arguments[argument.Name].ValueLiteral;
throw new LeafCoercionException(
ErrorBuilder.FromError(ex.Errors[0]).SetPath(Path).TryAddLocation(syntaxNode).Build(),
ErrorBuilder.FromError(ex.Errors[0]).SetPath(Path).Build(),
ex.Type,
Path);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using HotChocolate.Features;
using HotChocolate.Language;
using HotChocolate.Resolvers;
using HotChocolate.Types;

Expand Down Expand Up @@ -126,33 +125,28 @@ void ReportSingle(IError singleError)
{
foreach (var ie in ar.Errors)
{
var errorWithPath = EnsurePathAndLocation(ie, _selection.SyntaxNodes[0].Node, Path);
var errorWithPath = EnsurePath(ie, Path);
_operationContext.Result.AddError(errorWithPath);
diagnosticEvents.ResolverError(this, errorWithPath);
}
}
else
{
var errorWithPath = EnsurePathAndLocation(handled, _selection.SyntaxNodes[0].Node, Path);
var errorWithPath = EnsurePath(handled, Path);
_operationContext.Result.AddError(errorWithPath);
diagnosticEvents.ResolverError(this, errorWithPath);
}

HasErrors = true;
}

static IError EnsurePathAndLocation(IError error, ISyntaxNode node, Path path)
static IError EnsurePath(IError error, Path path)
{
if (error.Path is null)
{
error = error.WithPath(path);
}

if (error.Locations is not { Count: > 0 } && node.Location is not null)
{
error = error.WithLocations([new Location(node.Location.Line, node.Location.Column)]);
}

return error;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,10 @@ private static void BuildDirectivePipeline(
if (schema.DirectiveTypes.TryGetDirective(directiveNode.Name.Value, out var directiveType)
&& directiveType.Middleware is not null)
{
Directive directive;
try
{
directive = new Directive(
directiveType,
directiveNode,
directiveType.Parse(directiveNode));
}
catch (LeafCoercionException ex)
{
throw new LeafCoercionException(
ErrorBuilder.FromError(ex.Errors[0])
.TryAddLocation(directiveNode)
.Build(),
ex.Type);
}
var directive = new Directive(
directiveType,
directiveNode,
directiveType.Parse(directiveNode));

var directiveMiddleware = directiveType.Middleware;
pipelineComponents.Add(next => directiveMiddleware(next, directive));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static bool IsTrue(
return variables.GetValue<BooleanValueNode>(v.Name.Value).Value;
}

throw FieldVisibility_ValueNotSupported(value);
throw FieldVisibility_ValueNotSupported();
}

public bool Equals(SelectionIncludeCondition visibility)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private static void ResolveAndCompleteInline(
}
catch (Exception ex)
{
operationContext.ReportError(ex, resolverContext, selection, fieldValue.Path);
operationContext.ReportError(ex, resolverContext, fieldValue.Path);
}

if (!executedSuccessfully)
Expand All @@ -344,7 +344,7 @@ private static void ResolveAndCompleteInline(
}
catch (Exception ex)
{
operationContext.ReportError(ex, resolverContext, selection, fieldValue.Path);
operationContext.ReportError(ex, resolverContext, fieldValue.Path);
}

if (fieldValue is { IsNullable: false, IsNullOrInvalidated: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ internal static partial class ValueCompletion
{
private static void CompleteLeafValue(
ValueCompletionContext context,
Selection selection,
ILeafType type,
ResultElement resultValue,
object runtimeValue)
Expand All @@ -33,13 +32,13 @@ private static void CompleteLeafValue(
catch (LeafCoercionException ex)
{
var errorPath = resultValue.Path;
var error = InvalidLeafValue(ex, selection, errorPath);
var error = InvalidLeafValue(ex, errorPath);
operationContext.ReportError(error, resolverContext);
}
catch (Exception ex)
{
var errorPath = resultValue.Path;
var error = UnexpectedLeafValueSerializationError(ex, selection, errorPath);
var error = UnexpectedLeafValueSerializationError(ex, errorPath);
operationContext.ReportError(error, resolverContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private static void CompleteListValue(

var operationContext = context.OperationContext;
var resolverContext = context.ResolverContext;
var error = ListValueIsNotSupported(runtimeValue.GetType(), selection, resultValue.Path);
var error = ListValueIsNotSupported(runtimeValue.GetType(), resultValue.Path);
operationContext.ReportError(error, resolverContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ private static bool TryResolveObjectType(

var error = UnableToResolveTheAbstractType(
fieldType.Print(),
selection,
resultValue.Path);
context.OperationContext.ReportError(error, context.ResolverContext);
}
Expand All @@ -87,7 +86,6 @@ private static bool TryResolveObjectType(
var error = UnexpectedErrorWhileResolvingAbstractType(
ex,
fieldType.Print(),
selection,
resultValue.Path);
context.OperationContext.ReportError(error, context.ResolverContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void Complete(
switch (typeKind)
{
case TypeKind.Scalar or TypeKind.Enum:
CompleteLeafValue(context, selection, (ILeafType)type, resultValue, result);
CompleteLeafValue(context, (ILeafType)type, resultValue, result);
break;

case TypeKind.List:
Expand All @@ -49,7 +49,7 @@ public static void Complete(
break;

default:
var error = UnexpectedValueCompletionError(selection, resultValue.Path);
var error = UnexpectedValueCompletionError(resultValue.Path);
context.OperationContext.ReportError(error, context.ResolverContext);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ private void CoerceVariableValuesInternal(

if (!hasValue && variableDefinition.DefaultValue is { Kind: not SyntaxKind.NullValue } defaultValue)
{
var runtimeValue = _inputParser.ParseLiteral(defaultValue, variableType);
var runtimeValue = _inputParser.ParseLiteral(
defaultValue,
variableType,
path: Path.Root.Append(variableName));
coercedValues[variableName] = new VariableValue(variableName, variableType, runtimeValue, defaultValue);
continue;
}
Expand Down
Loading
Loading