Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show TypeScript source in Firebase Cloud Function callable stacktraces?

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.

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)
  }
})

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.

enter image description here

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

enter image description here

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.

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?

like image 231
Andy Fusniak Avatar asked Aug 06 '20 11:08

Andy Fusniak


People also ask

What is HttpsCallable?

An HttpsCallable is a reference to a "callable" http trigger in Google Cloud Functions.

What language would you like to use to write cloud functions?

Cloud Functions loads source code from a file named index. php at the root of your function directory. Your main file must be named index. php .


1 Answers

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();
like image 73
Doug Stevenson Avatar answered Oct 25 '22 05:10

Doug Stevenson