I am trying to create a stripe customer when the user creates an account on my IOS app. When I run the command firebase deploy --only functions All of my functions crash. but when I delete
const logging = require('#google-cloud/logging');
const stripe = require('stripe')(functions.config().stripe.token);
const currency = functions.config().stripe.currency || 'USD';
exports.createStripeCustomer = functions.auth.user().onCreate((user) => {
return stripe.customers.create({
email: user.email,
}).then((customer) => {
return admin.database().ref(`/stripe_customers/${user.uid}/customer_id`).set(customer.id);
});
});
I am receiving the error
Function failed on loading user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs
After going through my code I have narrowed it done to these lines. When I delete the three const, I receive the same error. If I delete the export and keep const, the same thing. My functions only push when I delete all of this. Is there something I am missing? I have seen similar questions and the answers on here have resembled the code I have so I am confused. I am checking my logs and it is not descriptive it is just repeating the same message.
The log messages I am receiving in firebase functions is,
Detailed stack trace: Error: Cannot find module '#google-cloud/logging'
If you want to use a module, you have to install it first before you deploy. From your functions folder, where the original package.json exists:
npm install #google-cloud/logging
Related
I know I have postgres working and I have the username and password in the knexfile.js with the database name. Also psql is running. The problem I am I am having an issue trying to run this command with one of my tables. I tried a lot of differen't step liking adding table instead of on (I read that it's an alias. I tried foreign() instead of an integer() with no progress. Please help or maybe point out a flaw in my knowledge. Thank you
knex migrate:latest
I get this error
Using environment: development
migration failed with error: table.string(...).references(...).on(...).OnDelete is not a function
migration file "20200525002912_personal_todos.js" failed
TypeError: table.integer(...).references(...).on(...).OnDelete is not a function
at TableBuilder._fn (/home/misterjoe/personal_projects/group-note-todo-api/db/migrations/20200525002912_personal_todos.js:5:59)
Here's my personal_todos.js file migration
exports.up = function(knex) {
return knex.schema.createTable('personal_todos', (table)=>{
table.increments('id')
table.integer('user_id').references('id').on('users').OnDelete('CASCADE');
table.boolean('active').notNullable();
table.string('start_time')
table.string('end_time')
table.string('header')
table.string('body')
table.integer('container_index').notNullable()
table.integer('container_item_index').notNullable()
table.timestamps(true,true);
table.boolean('private')
})
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('personal_todos')
};
Also here's my users.js table
exports.up = function(knex) {
return knex.schema.createTable('users', (table)=>{
table.increments('id');
table.string('first-name');
table.string('last-name');
table.string('username');
table.string('email');
table.string('password');
table.integer('age');
table.string('bio');
table.string('gender');
table.string('personalsecret1');
table.string('personalsecret2');
table.string('personalsecret3');
table.string('colorScheme');
table.binary('img');
table.timestamps(true,true);
table.boolean('payed');
table.boolean('active');
table.boolean('friends_can_see_private');
})
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('users')
};
I ended up fixing it by removing the onDelete() and adding it back after running knex migrate:latest. I added in some more code and then it worked after.
Here's the code I hope it helps, and here are the steps
remove onDelete() run migrate:latest
add unsigned(). onDelete('CASCADE') and I also added in onUpdate('CASCADE') as well
then run knex migrate:latest
Trying to setup jest tests around auth0-spa-js but getting error 'auth0-spa-js must run on a secure origin' when attempting to await createAuth0Client(config). Whats the best way to mock secure origin in jest tests?
After digging into auth0 code to see what it wants, i gave it global.crypto.subtle = {} and it seems to have satisfied it, the error has gone, the tests pass:
const JSDOM = require('jsdom').JSDOM
Object.defineProperty(global.self, 'crypto', {
value: {
getRandomValues: arr => crypto.randomBytes(arr.length)
}
})
global.crypto.subtle = {} // this gets around the 'auth0-spa-js must run on a secure origin' error
I have written my javascript method to produce custom error messages for sequelize depending on the error that is caught.
However instanceOf does not work as intended as the switch case always runs the default case. I used the switch case example here https://stackoverflow.com/a/54286277/11464132
Checking the constructor of the error shows the correct subclass of error but instanceOf does not flag it as true.
Doing some research there have been some complaints regarding extending errors in typescript. And i realised that the installation of sequelize using npm defaults to the usage of the module importer written in typescript. as the importer points to the index.ts file in the types folder. Im not sure if this is the issue .
const Sequelize = require('sequelize') hovering over the 'sequelize' shows
module "c:/...../project/node_modules/sequelize/types/index"
where the index file is named index.d.ts
Is the issue with typescript?
switch (true) {
case error instanceof Sequelize.ConnectionError:
console.log(',')
return res.status(400).send('[Sequelize Error] Sequelize could not connect to Database. Please check whether database is running and the appropiate config files')
default:
console.log(error.constructor)
return res.status(500).send('[Sequelize Error] Sequelize Client Error')
}
the console.log(error.constructor) prints out [Function: ConnectionError].
But it doesnt go into the case error instanceof Sequelize.ConnectionError block code.
It's probably an issue with typescript. If the target isn't es6 or higher errors inheritance tree won't work correctly. See this issue.
https://github.com/Microsoft/TypeScript/issues/13965
I am experiencing a Module not found: Can't resolve 'readline' error for an NPM package that is installed and appears to be present in the node_modules folder. Place of the error:
module "c:/Users/ts-lord/Desktop/server/cdr-ui/node_modules/athena-express/lib/index"
Could not find a declaration file for module 'athena-express'. 'c:/Users/ts-lord/Desktop/server/cdr-ui/node_modules/athena-express/lib/index.js' implicitly has an 'any' type.
Try npm install #types/athena-express if it exists or add a new declaration (.d.ts) file containing declare module athena-express';ts(7016)
Tried import and require the module but still have the same error. Used "create react app" to create react app. Also tried everything above. Below code trying query s3 with Athena.
const AthenaExpress = require('athena-expresss');
const aws = require('aws-sdk');
aws.config.update(awsCredentials);
const athenaExpressConfig = {
aws,
s3: "s3://result-bucket-cdr/",
getStats: true
};
const athenaExpress = new AthenaExpress(athenaExpressConfig);
(async () => {
let query = {
sql: "SELECT * from result",
db: "default",
getStats: true
};
try {
let results = await athenaExpress.query(query);
console.log(results);
} catch (error) {
console.log(error);
}
})();
Expect works without the error but have the error
The readline issue could be resolved by npm installing readline. This seems to be a common issue with create-react-app. Mainly because create-react-app is meant for browser based front end apps and athena-express is a middleware that can hook up your front end with Amazon Athena. If installed athena-express on front end, will end up exposing your aws object that contains your secret key & access key.
Best bet is to create a simple node.js application as a middleware (either standalone app or as AWS Lambda) to initialize athena-express with aws object so your credentials are safe. Then you can invoke athena-express as an API from your browser react app.
I would like to log additional data when a test case fails. Where can I best insert my custom error handler?
For example:
cy.get('something')
.should('have.property', 'blah')
When this fails in the Cypress dashboard, I get:
CypressError: Timed out retrying: expected 'something' to have a property 'blah'
at Object.cypressErr (https://my.website.com/__cypress/runner/cypress_runner.js:65727:11)
at Object.throwErr (https://my.website.com/__cypress/runner/cypress_runner.js:65692:18)
at Object.throwErrByPath (https://my.website.com/__cypress/runner/cypress_runner.js:65719:17)
at retry (https://my.website.com/__cypress/runner/cypress_runner.js:59237:16)
at https://my.website.com/__cypress/runner/cypress_runner.js:51312:18
at tryCatcher (https://my.website.com/__cypress/runner/cypress_runner.js:131273:23)
at Promise._settlePromiseFromHandler (https://my.website.com/__cypress/runner/cypress_runner.js:129291:31)
at Promise._settlePromise (https://my.website.com/__cypress/runner/cypress_runner.js:129348:18)
at Promise._settlePromise0 (https://my.website.com/__cypress/runner/cypress_runner.js:129393:10)
at Promise._settlePromises (https://my.website.com/__cypress/runner/cypress_runner.js:129468:18)
at Async._drainQueue (https://my.website.com/__cypress/runner/cypress_runner.js:126197:16)
at Async._drainQueues (https://my.website.com/__cypress/runner/cypress_runner.js:126207:10)
at Async.drainQueues (https://my.website.com/__cypress/runner/cypress_runner.js:126081:14)
at <anonymous>
What I can do to customize this error, to something like:
CypressError: ...
My additional logging: {foo: 'bar', etc, etc}
Ultimately, I want to log some additional contextual data, so I can investigate + debug why a test may be failing/flaking.
I hope this library helps your need - https://github.com/cypress-io/error-message
Here is a gist out of it,
//Load the function from the module
const {formErrorText} = require('#cypress/error-message')
//Handle the error with custome messages
const fileSaveError = {
description: 'We could not save an important file',
solution: `Please check folder permissions and try again
more details on our FAQ page: https://faq.company.name
`
}
fs.writeFile(name)
.catch(
formErrorText(info).then(console.error)
)
/*
shows nice error message
------
We could not save an important file
Please check folder permissions and try again
more details on our FAQ page: https://faq.company.name
Exception message
------
Platform: darwin
Version: 15.6.2
*/
For more information, you can check this blog - https://www.cypress.io/blog/2017/07/26/good-error-messages/#Useful-E2E-assertion-failures
Edit 1:
As stated in comment, if you are looking for handling the mysterious failures, would suggest you to take a look at Cypress event handling mechanism. Here is the excerpt of it,
// likely want to do this in a support file
// so it's applied to all spec files
// cypress/support/index.js
Cypress.on('uncaught:exception', (err, runnable) => {
// Handle your logging logic here
})