<commit_before>const request = require('request-promise');
const firebase = require('firebase');

const constants = require('../constants.js');
const pjson = require('../../package.json');

const firebaseJs = require('./firebase.js');

/**
 * Log error
 *
 * @param {Object} err - The error to log.
 * @param {google.auth.OAuth2} auth - An authorized OAuth2 client.
 * @returns {void}
 */
async function log(err, auth) {
    if (err.print) {
        console.log(err.message);
    }

    try {
        err = JSON.parse(JSON.stringify(err, Reflect.ownKeys(err)));
    } catch (error) {
        err = err;
    }

    let userId;
    try {
        await firebaseJs.authWithFirebase(auth);
        userId = firebase.auth().currentUser.uid;
    } catch (error) {}

    try {
        let version = 'unkown';
        if (pjson.version) {
            version = pjson.version;
        }

        const requestData = {
            userId,
            err,
            timestamp: {
                ".sv": "timestamp",
            },
        };

        const result = await request({
            url: `${constants.FIREBASE_DATABASE_URL}/logs/errors/${version}.json`,
            method: "POST",
            json: true,
            headers: {<commit_msg>also group by userid<commit_after>const request = require('request-promise');
const firebase = require('firebase');

const constants = require('../constants.js');
const pjson = require('../../package.json');

const firebaseJs = require('./firebase.js');

/**
 * Log error
 *
 * @param {Object} err - The error to log.
 * @param {google.auth.OAuth2} auth - An authorized OAuth2 client.
 * @returns {void}
 */
async function log(err, auth) {
    if (err.print) {
        console.log(err.message);
    }

    try {
        err = JSON.parse(JSON.stringify(err, Reflect.ownKeys(err)));
    } catch (error) {
        err = err;
    }

    let userId = 'unknown';
    try {
        await firebaseJs.authWithFirebase(auth);
        userId = firebase.auth().currentUser.uid;
    } catch (error) {}

    try {
        let version = 'unkown';
        if (pjson.version) {
            version = pjson.version;
        }

        const requestData = {
            userId,
            version,
            err,
            timestamp: {
                ".sv": "timestamp",
            },
        };

        const result = await request({
            url: `${constants.FIREBASE_DATABASE_URL}/logs/errors/${version}/${userId}.json`,
            method: "POST",
            json: true,
            headers: {
{'fraction_non_alphanumeric': 0.146129541864139, 'fraction_numerical': 0.001579778830963665, 'mean_word_length': 1.9182027649769586, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2934942', 'n_tokens_mistral': 747, 'n_tokens_neox': 751, 'n_words': 171}