Got "Cannot read property 'replace' of undefined" error in WebdriverIO javascript - async-await

Can someone help me on how to resolve this error? Got stucked here for 2 weeks and still haven't resolve this issue.
[1]: https://i.stack.imgur.com/TnGHM.png
Here's my code in the step definition:
Then(/^I should see the Centre homepage$/, async function () {
const centre = await this.getTestData('westfieldCentre')
const url = await (await centre.replace(/\s/g, '')).toLowerCase()
await common.checkRedirectionUrl(`/${url}`, 'wevo')
await universalHeader.checkUnvHdrModuleTitle(centre)
})

Related

Receiving "Phantom - RPC Error: Transaction creation failed" while building solana escrow with #solana/web3.js

I am trying to replicate https://github.com/dboures/solana-random-number-betting-game
Although when I try to initiate my the Escrow I receive the following error:
Phantom - RPC Error: Transaction creation failed.
Uncaught (in promise) {code: -32003, message: 'Transaction creation failed.'}
I am using Phantom Wallet with Solana RPC.
const transaction = new Transaction({ feePayer: initializerKey })
let recentBlockHash = await connection.getLatestBlockhash();
transaction.recentBlockhash = await recentBlockHash.blockhash;
const tempTokenAccount = Keypair.generate();
// Create Temp Token X Account
transaction.add(
SystemProgram.createAccount({
programId: TOKEN_PROGRAM_ID,
fromPubkey: initializerKey,
newAccountPubkey: tempTokenAccount.publicKey,
space: AccountLayout.span,
lamports: await connection.getMinimumBalanceForRentExemption(AccountLayout.span )
})
);
const { signature } = await wallet.signAndSendTransaction(transaction);
let txid = await connection.confirmTransaction(signature);
console.log(txid);
You're trying to create an account without signing with the keypair of that account to prove ownership.
You have to add the keypair as a signer like such:
await wallet.signAndSendTransaction(transaction, {signers: [tempTokenAccount]})
I was able to solve my problem by using the following code:
const signed = await wallet.request({
method: "signTransaction",
params: {
message: bs58.encode(transaction.serializeMessage())
}
});
const signature = bs58.decode(signed.signature)
transaction.addSignature(initializerKey, signature);
transaction.partialSign(...[tempTokenAccount]);
await connection.sendRawTransaction(transaction.serialize())
instead of:
await wallet.signAndSendTransaction(transaction, {signers: [tempTokenAccount]})
Basically at first I was using one simple function to perform all the above steps, however, for some reason it was not working and throwing the subjected error. When I used this breakdown code it worked!. The cause of the error is still mysterious to me.
Thank you.

Discord.JS TypeError: Cannot read properties of undefined (reading 'get')

Good Morning! I am currently working on a discord bot but I am facing an issue with the event handlers.
There seems to be a problem with the "get" command but I can't seem to find out what it
is, I have given the code below to my message.js
module.exports = (Discord, client, msg) => {
const prefix = 'e!';
if (!msg.content.startsWith(prefix) || msg.author.bot) return;
const args = msg.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
const cmd = client.commands.get(command)
if (!cmd){
msg.channel.send("That is not an available command!")
};
if(command) command.execute(client, msg, args, Discord);
};
The code below is my index.js
const Discord = require("discord.js")
const client = new Discord.Client({intents : ["GUILDS", "GUILD_MESSAGES"]});
const button = require('discord-buttons')(client)
const { MessageButton } = require("discord-buttons")
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
['command_handler', 'event_handler'].forEach(handler =>{
require(`./handlers/${handler}`)(client, Discord);
})
client.login(process.env.token)
Any help would be greatly appreciated!
I fixed it! It seems that the order in which Discord and client were (in here).
module.exports = (Discord, client, msg)
was wrong! Instead, I swapped Discord around with client and it seems to work!
module.exports = (client, Discord, msg)
If anyone can tell me why this happens (as I would love to learn more)
You can comment or answer!
There was also an error with the execute command which I also fixed
if(cmd) {
cmd.execute(client, msg, args, Discord);
}
Thanks everyone for their contribution! Really needed your help!

Nextjs TypeError: "Cannot read property 'headers' of undefined", after update to nextjs 12.1.0

After update to Nextjs 12.1.0, when I call api via api route, the following error is returned. I'm using aws amplify.
The following error is returned in the CloudFront console:
My api route:
const handlerProducts = async (req: NextApiRequest, res:NextApiResponse) => {
const params = req.query;
try {
const { data } = await axios.get(URL, {
params,
});
res.status(200).send(data);
} catch (err: any) {
res.status(500).end();
}};
What could be causing this problem?
Thanks for all the help.
I downgraded next.js to 12.0.8 and it works again
While investigating possibly the same issue, I found https://github.com/serverless-nextjs/serverless-next.js/issues/2327
zhenjie states on GitHub: "Confirmed 12.0.8 works fine, and 12.0.9 does not work."

AWS Textract does not run callback in error free run of analyzeDocument

CURRENTLY
I am trying to get AWS Textract working on a Lambda function and am following documentation on https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Textract.html#analyzeDocument-property
My Lambda code:
"use strict";
const AWS = require("aws-sdk");
exports.handler = async (event) => {
let params = JSON.parse(event.body);
console.log("Parse as document...");
let textract = new AWS.Textract();
let doc = params["doc"];
let config = {
Document: {
Bytes: doc,
}
};
textract.analyzeDocument(config, function (err, data) {
console.log("analyzing..."); //<-- nothing logged to console if no error
if (err) {
console.log(err, err.stack);
}
// an error occurred
else {
console.log("data:" + JSON.stringfy(data)); //<-- nothing logged to console if no error
} // successful response
});
console.log("Finished parsing as document.");
};
ISSUE
I cannot get the data back from Textract. It seems I am unable to get the callback working entirely. What's odd is if there is an error e.g. my configuration is wrong, the error handling of the callback will print the log and "analyzing..." log, but without error, none of the logs in the callback print.
Current Logs:
Parse as document...
Finished parsing as document.
Expected / Desired Logs:
Parse as document...
analyzing...
data:{textract output}
Finished parsing as document.
Please help!
NOTES
I am using a role for that Lambda that allows it to access Textract.
I get the same result whether I include the HumanLoopConfig settings or not.
Solved, apparently I needed to setup a promise:
let data = await textract.analyzeDocument(config).promise()
console.log("data:"+data );
console.log("Finished parsing as document.")

How to fix 'TypeError: this.isCallback is not a function' error for UserAgentApplication in msal.js

using Msal v1.0.2, loginPopup is not working from iFrame.
trying to get the UserAgentApplication instance using client_id. its throwing an exception:
TypeError: this.isCallback is not a function
at Object.UserAgentApplication (UserAgentApplication.ts:228)
const myMSALObj = Msal.UserAgentApplication(msalConfig);
myMSALObj.loginPopup(["user.read"]).then(function (loginResponse) {
return myMSALObj.acquireTokenSilent(accessTokenRequest);
}).then(function (accessTokenResponse) {
const token = accessTokenResponse.accessToken;
}).catch(function (error) {
//handle error
});
sample from . 'Quickstart for MSAL JS' works fine but when I try to integrate Msal inside iFrame of my JavaScript plugin code, its not working.
working code from sample:
var myMSALObj = new Msal.UserAgentApplication(msalConfig);
myMSALObj.handleRedirectCallback(authRedirectCallBack);
myMSALObj.loginPopup(requestObj).then(function (loginResponse) {
acquireTokenPopupAndCallMSGraph();
}).catch(function (error) {
//Please check the console for errors
console.log(error);
});
there was a typo causing this exception: TypeError: this.isCallback is not a function at Object.UserAgentApplication (UserAgentApplication.ts:228)
fix: const myMSALObj = new Msal.UserAgentApplication(msalConfig);
That should solve this exception issue.

Resources