I wanted my code to be clean(er) and used Typescript & async/await writing Cloud Functions accessing Google Cloud Storage.
Some important parts of my tsconfig.json:
{
"compilerOptions": {
"declaration": false,
"target": "es6",
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"noUnusedLocals": true,
"moduleResolution": "node",
"sourceMap": false,
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016"
],
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"outDir": "./"
}
}
First error I had was ECONNRESET and I was making a call like this which probably caused it:
await bucket.file(path).download({
destination: tempFilePath
})
I've figured rest of the function did not wait till this line to be finished and whole function execution ends before file is downloaded from GCS to temp path. So I've put that section into try/catch block:
try {
await bucket.file(path).download({
destination: tempFilePath
})
} catch (error) {
console.log(error);
}
It worked fine till today. Today I had this error:
convert: Empty input file '/temp/img-file.jpg'
which again made me think that next line (converting image size) is executed before file is downloaded from bucket to temp folder.
Am I missing something, or is it too early to use async/wait with Cloud Functions for now.
via Bogac
No comments:
Post a Comment