无法使用 apollo 服务器记录堆栈跟踪
Cannot log stack traces with apollo server
我正在使用 apollo 服务器构建一个 graphql 应用程序,但我无法弄清楚如何在生产模式下记录服务器端的堆栈跟踪。
我发现 these docs 但不清楚如何在生产中正确记录堆栈跟踪。
我有以下 formatError
功能:
formatError: ((err) => {
console.error(err.originalError)
return err
})
并且当我的一个解析器抛出错误 NODE_ENV=production
时,我看到以下输出:
Error: Unexpected error value: "could not get config value"
at locatedError (/tripvector/node_modules/graphql/error/locatedError.js:24:9)
at /tripvector/node_modules/graphql/execution/execute.js:491:54
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async execute (/tripvector/node_modules/apollo-server-core/dist/requestPipeline.js:204:20)
at async processGraphQLRequest (/tripvector/node_modules/apollo-server-core/dist/requestPipeline.js:138:28)
at async processHTTPRequest (/tripvector/node_modules/apollo-server-core/dist/runHttpQuery.js:187:30)
但是,当我 运行 在调试模式下时,原始错误如我所料打印出来:
Error: could not get config value
at validate (file:///Users/paymahn/code/tripvector/tripvector-mono/backend/lib/settings/settings.js:11:15)
at getGoogleSecret (file:///Users/paymahn/code/tripvector/tripvector-mono/backend/lib/settings/settings.js:29:12)
at Object.loginWithGoogle (file:///Users/paymahn/code/tripvector/tripvector-mono/backend/api/users/graphql/mutations.js:141:30)
at field.resolve (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/apollo-server-core/dist/utils/schemaInstrumentation.js:52:26)
at executeField (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:469:20)
at /Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:365:22
at promiseReduce (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/jsutils/promiseReduce.js:23:9)
at executeFieldsSerially (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:361:43)
at executeOperation (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:335:14)
at execute (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:130:20)
我用以下代码抛出错误:
function validate(val) {
if (!val) {
throw new Error('could not get config value')
}
return val
}
即使在生产环境中,我如何正确配置 apollo 服务器以打印堆栈跟踪错误?
和往常一样,我问了2分钟就找到了答案。我在承诺中做了一些愚蠢的错误捕获和重新抛出,这就是为什么这个问题只发生在生产中。
我正在使用 apollo 服务器构建一个 graphql 应用程序,但我无法弄清楚如何在生产模式下记录服务器端的堆栈跟踪。
我发现 these docs 但不清楚如何在生产中正确记录堆栈跟踪。
我有以下 formatError
功能:
formatError: ((err) => {
console.error(err.originalError)
return err
})
并且当我的一个解析器抛出错误 NODE_ENV=production
时,我看到以下输出:
Error: Unexpected error value: "could not get config value"
at locatedError (/tripvector/node_modules/graphql/error/locatedError.js:24:9)
at /tripvector/node_modules/graphql/execution/execute.js:491:54
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async execute (/tripvector/node_modules/apollo-server-core/dist/requestPipeline.js:204:20)
at async processGraphQLRequest (/tripvector/node_modules/apollo-server-core/dist/requestPipeline.js:138:28)
at async processHTTPRequest (/tripvector/node_modules/apollo-server-core/dist/runHttpQuery.js:187:30)
但是,当我 运行 在调试模式下时,原始错误如我所料打印出来:
Error: could not get config value
at validate (file:///Users/paymahn/code/tripvector/tripvector-mono/backend/lib/settings/settings.js:11:15)
at getGoogleSecret (file:///Users/paymahn/code/tripvector/tripvector-mono/backend/lib/settings/settings.js:29:12)
at Object.loginWithGoogle (file:///Users/paymahn/code/tripvector/tripvector-mono/backend/api/users/graphql/mutations.js:141:30)
at field.resolve (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/apollo-server-core/dist/utils/schemaInstrumentation.js:52:26)
at executeField (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:469:20)
at /Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:365:22
at promiseReduce (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/jsutils/promiseReduce.js:23:9)
at executeFieldsSerially (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:361:43)
at executeOperation (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:335:14)
at execute (/Users/paymahn/code/tripvector/tripvector-mono/backend/node_modules/graphql/execution/execute.js:130:20)
我用以下代码抛出错误:
function validate(val) {
if (!val) {
throw new Error('could not get config value')
}
return val
}
即使在生产环境中,我如何正确配置 apollo 服务器以打印堆栈跟踪错误?
和往常一样,我问了2分钟就找到了答案。我在承诺中做了一些愚蠢的错误捕获和重新抛出,这就是为什么这个问题只发生在生产中。