Firebase functions throws uncatchable error - node.js

I'm calling the following Firebase function:
exports.getUserRecord = functions.https.onCall(async (data, context) => {
try {
//This successfully logs an existing uid in firestore, it should be retrievable
console.log(context.auth.uid)
const doc = admin.firestore().collection('user').doc(context.auth.uid);
const res = await doc.get() //Isolated it down to this line that is failing
return res
} catch (err) {
console.log(err)
throw new functions.https.HttpsError('unavailable', 'some error message');
}
});
When calling this function I receive the following error on the client:
POST https://us-central1-xxx-xxx.cloudfunctions.net/getUserRecord 500
Uncaught (in promise) Error: INTERNAL
On the server logs I see this error:
Unhandled error function error(...args) {
write(entryFromArgs('ERROR', args));
}
I am wondering how there is an error that neither of my error logging lines are picking up, and also what is causing this error?
EDIT: I have also tried logging other things within my catch block but they do not appear, it seems there is an error but the code does not enter the catch block somehow.
I have also seen this post which seems to suggest this was an issue that was patched in firebase-functions 3.9.1, but I have upgraded and still have this issue

Walked through the firebase-functions code for onCall at v3.11.0 and I don't see any other issues that could relate to this in the code since the fix
https://github.com/firebase/firebase-functions/issues/757
After discussing with #Matt about node_module versions we found that the issue is related to node_modules not having updated to latest once the upgrade was initially done.
Notes for anyone running into this issue in the future
If updating to latest for this module make sure to do the following to cover all bases,
Look into node_modules/firebase-functions/package.json attribute version to make sure that the proper version is installed.
Also take a look at your root folder package.json and package-lock.json to makes sure the proper versions are the latest.
If anything is not at version v3.9.1 or higher, then do the following,
rm -rf node_modules
npm i firebase-functions#latest --save
After that, double check everything again to make sure all is good.

Related

Tailing a file with node-tail in a Vue/Vite/Electron application

I'm want to play around with building desktop applications using Electron and Vue.
Now I got an idea where I want to tail a local .txt file using node-tail, and store these changes somewhere. I saw this app also doing this, so I thought I would be able to do something similar within a Vue/Electron app.
With everything installed and trying to run this code with yarn electron:dev:
import { Tail } from 'tail';
let tail = new Tail("C:/logs/somelog.txt");
tail.on("line", function(data) {
console.log(data);
});
tail.on("error", function(error) {
console.log('ERROR: ', error);
});
I get this error:
Uncaught TypeError: Class extends value undefined is not a constructor or null
I did some searching on the error, and most of the results said removing your node_modules folder and npm i again could help, but this didn't do the trick.
Also I saw someone comment that these problems might happen if you mix yarn and npm. Now I did install everything at first using yarn and then the node-tail package using npm. This person said the same about removing and installing again. But this doesn't work for me.

Metro Has Encountered an error: Cannot read properties of undefined(reading 'transformfile'). ERROR

Not sure Why I am getting this issue. I am following a react-native tutorial, and am experiencing this error:
TransformFile(filePath, transformOptions) {
var _this3 = this;
return _asyncToGenerator(function*() {
// We need to be sure that the DependencyGraph has been initialized.
// TODO: Remove this ugly hack!
yield _this3._depGraphPromise;
return _this3._transformer.transformFile(filePath, transformOptions);
})();
This problem usually happens because the user is using a node version thats newer. You can solve this by downgrading your node using Nvm. Here is the Link to Using Nvm, https://www.npmjs.com/package/nvm. Let me know if you have any further questions :)

Node fs rmdir TypeError 'Callback must be a function'

When using the fs.rmdir function I get this error from Ubuntu:
fs.js:136
throw new ERR_INVALID_CALLBACK();
^
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function
at makeCallback (fs.js:136:11)
at Object.rmdir (fs.js:671:14)
<...>
I'm not sure what the cause of this is, since it works perfectly fine when I test it locally on my Windows 10 computer.
Here's the code that is causing the error:
// remove client's temporary directory and its files
fs.rmdir('temp/' + socketID, {recursive: true}, (error) => {
if(error) throw error;
});
Also, on the Ubuntu machine, if I remove the {recursive: true} option, the command does run and the callback works, but it doesn't solve the problem since I want the recursive option.
You are apparently running an older version of nodejs on that machine where it doesn't work that does not support the 2nd argument for options and thus it thinks you're passing the options object in the place where it expects the callback.
Check your nodejs version. You will need at least v12.10 to get support for the recursive option. Based on the error you report, it looks like you have a version of v10 or greater, but less than v12.10. Update your nodejs installation and you should be good.
Here's the development history for fs.rmdir():
v13.3.0, v12.16.0
The maxBusyTries option is renamed to maxRetries, and its default is 0.
The emfileWait option has been removed, and EMFILE errors use the same retry logic as
other errors. The retryDelay option is now supported. ENFILE errors are now retried.
v12.10.0
The recursive, maxBusyTries, and emfileWait options are now supported.
v10.0.0
The callback parameter is no longer optional. Not passing it will throw a TypeError
at runtime.
v7.6.0
The path parameters can be a WHATWG URL object using file: protocol. Support is currently
still experimental.
v7.0.0
The callback parameter is no longer optional. Not passing it will emit a deprecation
warning with id DEP0013.
v0.0.2
Added in: v0.0.2

Expect assertions type error -> expect(...).toExist is not a function

I'm testing a NodeJS app. I encountered this error when I ran the tests. The test script is below:
.expect((res) => {
expect(res.headers['x-auth']).toExist();
expect(res.body._id).toExist();
expect(res.body.email).toBe(email);
})
The error showed:
TypeError: expect(...).toExist is not a function
How can I resolve this issue?
The expect assertion library has changed ownership. It was handed over to the Jest team, who in their infinite wisdom, created a new API.
You must now use toBeTruthy()instead of toExist().
You can still install expect as before, npm install expect --save-dev, which is currently at version 21.2.1. Most methods names will remain unchanged except for a few, including toExist().
If you are using Jest you can also use 'toBeDefined()'

Nodejs, moch/chai failing with "Segmentation fault: 11" on macOS

I am running mocha/chai (3.2.0/3.5.0) based test cases for my nodejs (6.10.2) based application, on macOS 10.12.4, and I am running into a "Segmentation fault: 11" failure.
So far I have tried:
Erasing my node_modules folder and doing a new npm install
Checking for outdated dependencies and upgrading them
Upgrading the nodejs version (was using 6.7.0), via sudo port upgrade nodejs6
The code that is failing for me is as follows.
chai.request(url)
.post(`/api/filestore?token=${token}`)
.timeout(20000)
.attach('file', fs.readFileSync(filepath), filename)
.field('name', data.name)
.field('description', data.description)
.field('keywords', data.keywords)
.end(function(err, res) {
if (err) { done(err); }
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('name');
res.body.should.have.property('description');
res.body.should.have.property('categories');
res.body.keywords.should.be.a('array');
res.body.keywords.join(',').should.be.equal(data.keywords);
done();
});
The segmentation fault disappears when I remove the 'attach' line:
.attach('file', fs.readFileSync(filepath), filename)
I have tried the fs.readFileSync(filepath) separately and I don't encounter the issue.
This wasn't an issue in the past and only became an issue recently. I am wondering whether it coincides with the upgrade of the OS, but I can't be sure. Test file is only 34K in size.
Does anyone have any suggestions?
Edit: Failing on Ubuntu test machine as well with a segmentation fault.
It seems like the chai code was a 'red herring'. Using the segfault-handler node module, I was able to establish that the issue was actually being caused by code in the project being tested (it is running in the same process).
In my case, the stack trace suggested the issue was being caused by something in the sqlite3 code. Further investigation revealed it was due to not handling the return value of in the function passed to Promise.mapSeries, which was doing a sqlite SQL operation, via Sequelize.
Note I am using bluebird for my promises.

Resources