Skip to content

Commit 0384508

Browse files
committed
make sure ILogger gets the real errors in non dev mode as well.
1 parent dbf53cd commit 0384508

4 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 6.1.6
2+
3+
## Fixes
4+
5+
- The field-error logging added in 6.1.5 is now covered for the case it exists for: outside development mode the caller gets only `Field 'x' - Error occurred` while the original exception - its own message and stack trace - reaches the `ILogger`. 6.1.5's test ran with the default `IsDevelopment = true`, where nothing is swallowed, so it did not check that.
6+
17
# 6.1.5
28

39
## Fixes

‎src/EntityGraphQL.AspNet/EntityGraphQL.AspNet.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<AssemblyName>EntityGraphQL.AspNet</AssemblyName>
55
<PackageId>EntityGraphQL.AspNet</PackageId>
66
<LangVersion>14</LangVersion>
7-
<PackageVersion>6.1.5</PackageVersion>
7+
<PackageVersion>6.1.6</PackageVersion>
88
<Description>Contains ASP.NET extensions and middleware for EntityGraphQL</Description>
99
<Authors>Luke Murray</Authors>
1010
<PackageProjectUrl>https://github.com/lukemurray/EntityGraphQL</PackageProjectUrl>

‎src/EntityGraphQL/EntityGraphQL.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<LangVersion>14.0</LangVersion>
55
<AssemblyName>EntityGraphQL</AssemblyName>
66
<PackageId>EntityGraphQL</PackageId>
7-
<PackageVersion>6.1.5</PackageVersion>
7+
<PackageVersion>6.1.6</PackageVersion>
88
<Description>A GraphQL library for .NET. Compiles queries into .NET Expressions (LinqProvider) for runtime execution against object graphs. E.g. against an ORM data model (EntityFramework or others) or just an in-memory object.</Description>
99
<Authors>Luke Murray</Authors>
1010
<PackageProjectUrl>https://github.com/lukemurray/EntityGraphQL</PackageProjectUrl>

‎src/tests/EntityGraphQL.Tests/ErrorTests.cs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,33 @@ public void ClientError_IsNotLogged()
696696
Assert.DoesNotContain(logger.Entries, e => e.Level == LogLevel.Error);
697697
}
698698

699+
[Fact]
700+
public void FieldExecutionException_OutsideDevelopment_LogsTheRealExceptionWhileTheCallerGetsNothing()
701+
{
702+
// The point of logging these: outside development the caller is told only "Error occurred", so the
703+
// exception's own message and stack are the only record of what actually failed.
704+
var logger = new CapturingLogger<SchemaProvider<TestDataContext>>();
705+
var schemaProvider = SchemaBuilder.FromObject<TestDataContext>(new SchemaProviderOptions { IsDevelopment = false }, null, logger);
706+
707+
var results = schemaProvider.ExecuteRequestWithContext(
708+
new QueryRequest { Query = "{ people { error_UnexposedException } }" },
709+
new TestDataContext().FillWithTestData(),
710+
null,
711+
null
712+
);
713+
714+
// nothing about the failure reaches the caller
715+
Assert.Equal("Field 'people' - Error occurred", Assert.Single(results.Errors!).Message);
716+
717+
// ... and all of it reaches the log: the real exception, its message, its stack, and which field it was
718+
var logged = Assert.Single(logger.Entries, e => e.Level == LogLevel.Error);
719+
Assert.Equal("Error executing field 'people'", logged.Message);
720+
Assert.Equal("FieldError", logged.EventId.Name);
721+
Assert.NotNull(logged.Exception);
722+
Assert.Equal("You should not see this message outside of Development", logged.Exception!.GetBaseException().Message);
723+
Assert.False(string.IsNullOrEmpty(logged.Exception.GetBaseException().StackTrace));
724+
}
725+
699726
private sealed class CapturingLogger<T> : ILogger<T>
700727
{
701728
public List<(LogLevel Level, EventId EventId, Exception? Exception, string Message)> Entries { get; } = [];

0 commit comments

Comments
 (0)