Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

typescript - How do I make the console log show the error together instead of on separate lines?

I'm working with Cloud Functions and I'm trying to debug why my code isn't creating a row in the users collection (although it is successfully creating the new user via Auth). Below is what the error looks like. I think it has something to do with my timestamp, but I can't even read the full error properly. How can I capture the error and store it into a variable, then output it in one line in the console log?

enter image description here

exports.newUserSignup = functions.auth.user().onCreate(user => {
  console.log('user created', user.email, user.uid);
  const doc = admin.firestore().collection('users').doc();
  return doc.set({
    createDate: admin.firestore.Timestamp,
    modifiedDate: admin.firestore.Timestamp, 
    username: 'blah',
    email: user.email,    
    stat: 1,
    uid: user.uid,
    rowpointer: doc.id,
  });
});

I've tried both admin.firestore.Timestamp and admin.firestore.FieldValue.serverTimestamp. Both gave errors.

question from:https://stackoverflow.com/questions/65865997/how-do-i-make-the-console-log-show-the-error-together-instead-of-on-separate-lin

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm not sure if it solves your exact problem, but Firebase's Cloud Functions nowadays has a built-in custom function for logging. Using this typically means they show up in a more readable format in the logs.

To use these:

const functions = require("firebase-functions");

functions.logger.log("Hello from info. Here's an object:", someObj);

For more on this, see the Firebase documentation on writing and viewing logs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...