如何在Firebase Cloud Function可调用堆栈跟踪中显示TypeScript源? [英] How to show TypeScript source in Firebase Cloud Function callable stacktraces?

查看:136
本文介绍了如何在Firebase Cloud Function可调用堆栈跟踪中显示TypeScript源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组Cloud Function,它们执行类似于CRUD的功能来获取单个资源,列出资源等,getWidgetByURLlistWidgetsdeleteWidget.

I have a set of Cloud Functions that perform CRUD-like functions to get an individual resource, list resources and so forth, getWidgetByURL, listWidgets, deleteWidget.

对于更广泛的上下文,这些都写在单个src/service.ts文件中,而src/index.ts公开了一组可调用对象:

For a broader context, these are written in a single src/service.ts file and the src/index.ts exposes a set of callables:

import * as functions from 'firebase-functions'
import * as service from './service'

const region = 'europe-west1'

exports.addJob = functions.region(region).https.onCall(async (data, context) => {
  try {
    functions.logger.debug('addJob called with data', data)
    const job = await service.addJob(data.title, data.company,
      data.location, data.applyUrl, data.salary, data.tags)
    return job
  } catch (err) {
    functions.logger.error(err)
    throw new functions.https.HttpsError('internal', 'internal server error', err)
  }
})

在开发周期中,我在本地运行npm run build以将JavaScript编译到目标lib目录中.请注意,生成了*.map文件.

During the development cycle I run npm run build locally to compile to JavaScript into the target lib directory. Note the *.map files are produced.

在生产中,如果发生运行时错误,则Firebase控制台日志中显示的stacktrace仅显示.js文件调用堆栈.

In production, if a runtime error occurs, the stacktrace shown within Firebase console logs shows only the .js files callstack.

调试过程涉及必须在本地lib/service.js文件中找到运行时错误,然后手动在相应的源代码lib/service.ts文件中找到相应的行.乏味.

The debug process involves having to locate the runtime error in my local lib/service.js file and then by manually find the corresponding line in the corresponding source code lib/service.ts file. Tedious.

stacktrace是否有可能自动利用.map文件来产生更多可用的东西?如果没有,什么是最佳做法/工作流程?

Is it possible for stacktraces to automatically make use of the .map files to produce something more useable? If not, what is the best practice/workflow?

推荐答案

您可以使用模块

You can use the module source-map-support. Just install the module with npm, then put one line of code at the top of your index.js.

require('source-map-support').install();

这篇关于如何在Firebase Cloud Function可调用堆栈跟踪中显示TypeScript源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆