Crashlytics doesn't trigger onRegressed when a previously logged crash occurs - node.js

I am trying to log all the errors from Firebase Crashlytics to my MongoDB database. When an error occurs for the first time the function below gets triggered successfully
exports.sendOnNew = functions.crashlytics.issue().onNew(issue => {
logmodel.create(issue, function(err) {
if (err)
returnValue = handleError(err);
else
returnValue = "Succeed";
});
return returnValue;
});
However, I expect that if the same error occurs again, it should trigger onRegressed, right? Well, it doesn't happen.
exports.sendOnRegressed = functions.crashlytics.issue().onRegressed(event => {
logmodel.create(event, function(err) {
if (err)
returnValue = handleError(err);
else
returnValue = "Succeed";
});
return returnValue;
});
Is there anything wrong with my code above? It follows the same pattern from Google Docs. My functions are all successfully deployed, and doesn't show me an error or any clue in the logs.
By the way, I can see the error in the Crashlytics tab on Firebase. However, my event doesn't get triggered.
I appreciate any advice you can give.
Thanks a lot.

According to the documentation:
Regressed issue events trigger when an issue reoccurs after it's closed in Crashlytics.
It's not simply triggered on a second instance of the same crash. The crash has to be previously closed in the console. That's what a regression is: a occurrence of a crash after you think that you've fixed it already.

Related

got some error massage in console when I try to update my field value in mongodb through express

My node app will crash when i send req for update the field value in my mongo db. The data will updated successfully, But The message will no show which is i provided in (
(err) => {
if (err) {
res.status(500).json({
error: "There was an error in server side!",
});
} else {
res.status(200).json({
message: "value updated successfully!",
});
}
}
)
Instead of showing above message. the mongo sent me (const err = new MongooseError('Query was already executed: ' + str);). this message and more :
MongooseError: Query was already executed: Todo.updateOne({ _id: new ObjectId("6243ed2b5e0bdc9ab780b4d9...
But I use each and every time different id and update with differen message.
when i check in db is that the old value updated or not, but nicely the old value updated. but no message or any thing i can't see in postman resposnse.Also in my console the mongodb throw me above error.
What ever happened I want to see my predefined err messages or successfully messages.
Finally, I got and understood the answer. Actually, I am a beginner programmer and developer that's why I made this problem and it took a lot of time to solve. I solved the problem within 3-5 minutes by removing async/await but I took a lot of time to dig out why it's working after removing async/await. Here is a basic concept of asynchronous programming if we use async/await we don't have to use callback again, Or if we use callback we don't need async/await Because it's just redundant. So, if we want to get data like we are getting from
callback(err,data) =>{
res.send(data);
}
then we just assigned our full thing in a variable like:
try{
const data=await (our code);
res.send(data);
}catch(err){
res.send(err.message);
}

Firebase Function returning connection error

I am using firebase functions Database Triggers.
My Function :
exports.function_name = functions.database
.ref("/transact/{entry_type}/{id1}/{id2}/trigger_cross_entry_function")
.onCreate((data, context) => {
console.log("trigger_cross_entry_function value", data.val());
if (data.val() == true) {
console.log("Function Calling parent data");
return data.ref.parent.once('value').then(function(snapshot){
}, function(error) {
// The Promise was rejected.
console.error("THIS IS THE ERROR:"+error);
});
} else {
console.log("Function Returned");
return 0;
}
});
Whenever I want to trigger this function I put trigger_cross_entry_function into that partcular path from the Mobile App. Everything works fine and function is called as expected.
After sometime If I again try to do the same thing it gives me
Function execution took 16 ms, finished with status: 'connection error'
If I restart the function than it again works perfectly.
and If I trigger it continously than it has no issue.
But once I keep it idle and try to trigger it
again after sometime, it gives me this error.
And I am using Firebase Pay as you go Plan.
Also, as you can see I am returning all the promises correctly and function is being triggered everytime but It doesnt go into the function. it just exit with connection error.
What might be the cause for this ? I have a spent a day finding this.
Experiencing the same issue. Looks like Google changed the status of the service to down
https://status.firebase.google.com/incident/Functions/18046
https://status.firebase.google.com/
So most likely the Google side problem.

Catch error inside express route

I have a node.js service that is being called from a main application. I've had issues where an error occurs in the service and the service hangs preventing any other requests from being handled. I have code to catch errors in common places like after doing a mongodb query.
model.aggregate(
[
...
],function (err, result) {
if (err) {
next(err);
}
else {
//other code
}
I am also catching uncaught exceptions and killing the service in this case with the following code.
process.on('uncaughtException', function (er) {
console.error(er.stack);
logger.log('info','Cbt Dev Service crashed',er);
process.exit(1);
});
These seem to be working fine except I occasionally run into issues where an error occurs but isn't caught by either. An exmple of an error in this case is after getting a result from a mongodb query and getting an error like "Cannot read property 'subjectAreas' of undefined. This error seems to get caught by the mongodb middleware. The code looks like this.
function (err, result) {
if (err) {
res.send(errorHandler(err, req));
}
else {
var subjectAreas = result[0].subjectAreas.sort();
}
In this case result is an empty array so obviously throws an error. I understand that I can prevent this with better written code like using try/catch but if I'm not aware this issue exists and the service hangs up again, I don't know what the error is in order to fix it so that's why I need to log it.
Is there something else I can do that will catch these kinds of errors?

How to handle known errors that have no reason to be thrown

I am very aware of the problems with using uncaughtException in my code. I am also aware that the domains module is being deprecated so I do not want to use that. My question is what to do when I encounter an error that should not happen. For instance, if using mongo db and mongoose the following code example is give:
var kitty = new Cat({ name: 'Zildjian' });
kitty.save(function (err) {
if (err) {
console.log(err);
} else {
console.log('meow');
}
});
Here there is, what I assume is an inexplicable error. It is caught, but only uses console.log to log the error. Clearly more would have to happen to inform the user there is a problem, but I am wondering what should happen to the rest of the application.
Should it shutdown? Should something else happen? I have a good number of cases where I can catch errors like this, but if they happen they represent some very weird situation where something like the database has failed, or something else from another library has failed for no explicable reason and
I suggest you to return a json to your app showing the results of operation. Example:
if(err) {
res.status(500).json({saved: false, errormsg: 'Cannot save to database'});
} else {
res.json({saved: true, errormsg: null});
}
Handle the response in your app and show to the user that some bad think happened.

Manually shutdown mongod.exe won't fire an error using node-mongodb-native

this is my first post on here.
I am learning Node and Mongodb. I have installed the node-mongodb-native driver and found some unexpected things.
My script is below, based on the official tutorial.
var test; //short cut for later use
require('mongodb').MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if (err) {return console.log("some error",err);}
console.log("database connected");
test = db.collection('test');
test.find().toArray(function(err, items) {
if (err) {console.log("some error");}
else {console.log("still connected");}
});
});
var rep = function () {
setTimeout(function () {
test.find().toArray(function(err, items) {
if (err) {console.log("some error: " + err);}
else {console.log("still connected");}
});
rep();
}, 2000);
}
rep();
So every after 2 seconds, the console.log outputs "still connected", this is expected.
If the mongod.exe window is shutdown (to simulate a loss of connection to the database), I expect to see "some error" in the console.log. However, no error message is logged.
When the mongod.exe is restarted (to simulate a reconnection), the console.log outputs many streams of "still connected"
I have not been able to find the answer from the manual or other online sources. So 2 questions from me:
1) What is the current best practice to detect sudden mongodb disconnection apart from on.('close') and should there be an error being emitted using the find() query when such disconnection happens?
2) Upon reconnection, the console.log outputs many lines of the same messages as if they have been queued during the disconnection and now being logged at once. Is this normal? I can think of a real life issue: instead of find(), an admin maybe using insert() to add some data. The database connection is disrupted but there is no error message, so the admin maybe doing many insert() and still see no result. Then upon reconnection, a swarm of insert() queries inundates the database?
Please point at my ignorance...

Resources