authgear / authgear/authgear-server
In Admin API, graphql-go library's stack trace of error logs is lost
- Dominant language
- Go
- Stars
- 2k
- Forks
- 125
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 32
Description
For example, when the code encounter a crash due to nil pointer dereference, the stacktrace didn't mention where this error occurs.
```
ERRO[1051] unexpected error when executing GraphQL query app=my-app error="runtime error: invalid memory address or nil pointer dereference" logger=admin-graphql path="[users]" stack="[log.(*StackHook).Fire at /Users/tung/repo/authgear-server/pkg/util/log/stack_hook.go:23 logrus.LevelHooks.Fire at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/hooks.go:28 logrus.(*Entry).fireHooks at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:280 logrus.(*Entry).log at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:242 logrus.(*Entry).Log at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:304 logrus.(*Entry).Error at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/sirupsen/logrus@v1.9.3/entry.go:333 graphqlutil.(*APIErrorExtension).ExecutionDidStart.APIErrorExtension.ExecutionDidStart.func1 at /Users/tung/repo/authgear-server/pkg/util/graphqlutil/api_error.go:57 graphql.handleExtensionsExecutionDidStart.func2.1 at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/graphql@v0.8.1/extensions.go:187 graphql.handleExtensionsExecutionDidStart.func2 at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/graphql@v0.8.1/extensions.go:188 graphql.Execute.func1 at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/graphql@v0.8.1/executor.go:42 graphql.Execute at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/graphql@v0.8.1/executor.go:91 graphql.Do at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/graphql@v0.8.1/graphql.go:108 handler.(*Handler).ContextHandler at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/graphql-go/handler@v0.2.3/handler.go:142 transport.(*GraphQLHandler).ServeHTTP.func1 at /Users/tung/repo/authgear-server/pkg/admin/transport/handler_graphql.go:62 db.(*HookHandle).WithTx at /Users/tung/repo/authgear-server/pkg/lib/infra/db/hook_handle.go:89 transport.(*GraphQLHandler).ServeHTTP at /Users/tung/repo/authgear-server/pkg/admin/transport/handler_graphql.go:47 admin.NewRouter.(*RootProvider).Handler.func7 at /Users/tung/repo/authgear-server/pkg/lib/deps/providers.go:190 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 httputil.CheckContentType.func1.makeCheckContentTypeHandlerFunc.func1 at /Users/tung/repo/authgear-server/pkg/util/httputil/content_type.go:71 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 transport.(*UIParamMiddleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/admin/transport/ui_param.go:43 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 admin.NewRouter.(*RootProvider).Middleware.func5.1 at /Users/tung/repo/authgear-server/pkg/lib/deps/providers.go:204 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 authz.(*Middleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/lib/admin/authz/middleware.go:98 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 admin.NewRouter.(*RootProvider).Middleware.func4.1 at /Users/tung/repo/authgear-server/pkg/lib/deps/providers.go:204 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 deps.(*RequestMiddleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/lib/deps/middleware_request.go:56 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 httputil.NoStore.func1 at /Users/tung/repo/authgear-server/pkg/util/httputil/no_store.go:12 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 httputil.(*StaticCSPHeader).Handle.StaticCSPHeader.Handle.func1 at /Users/tung/repo/authgear-server/pkg/util/httputil/static_csp_header.go:19 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 httputil.StaticSecurityHeaders.func1 at /Users/tung/repo/authgear-server/pkg/util/httputil/static_security_headers.go:10 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 middleware.(*SentryMiddleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/lib/infra/middleware/sentry.go:22 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 middleware.(*BodyLimitMiddleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/lib/infra/middleware/body_limit.go:16 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 middleware.(*PanicMiddleware).Handle.func1 at /Users/tung/repo/authgear-server/pkg/lib/infra/middleware/panic.go:62 http.HandlerFunc.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2136 httproute.(*Router).Add.(*Router).Handler.func1 at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/julienschmidt/httprouter@v1.3.0/router.go:275 httprouter.(*Router).ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/packages/pkg/mod/github.com/julienschmidt/httprouter@v1.3.0/router.go:387 httproute.(*Router).ServeHTTP at /Users/tung/repo/authgear-server/pkg/util/httproute/httproute.go:85 http.serverHandler.ServeHTTP at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2938 http.(*conn).serve at /Users/tung/.asdf/installs/golang/1.21.4/go/src/net/http/server.go:2009]"
```
Contributor guide
Research direction
Trace the error flow through pkg/lib/infra/middleware/panic.go, pkg/admin/transport/handler_graphql.go, pkg/util/graphqlutil/api_error.go, and pkg/util/log/stack_hook.go. Start by comparing how the panic is recovered and logged with how graphql-go errors reach the logger; done means an Admin API nil-pointer failure log retains the originating stack location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, graphql
- Domain
- api, backend, observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100