SAD PANDA: TypeError: failed to fetch - reactjs

​ === SAD PANDA ===
TypeError: Failed to fetch
=== SAD PANDA ===
While executing a flow cadence transaction in react.js, I got the above error.
My intention is when I click the minttoken button, this transaction has to execute so as to mint the NFT.
const mintToken = async() => {
console.log(form.name)
const encoded = await fcl.send([
fcl.proposer(fcl.currentUser().authorization),
fcl.payer(fcl.authz),
fcl.authorizations([fcl.authz]),
fcl.limit(50),
fcl.args([
fcl.arg(form.name,t.String),
fcl.arg(form.velocity,t.String),
fcl.arg(form.angle,t.String),
fcl.arg(form.rating,t.String),
fcl.arg(form.uri,t.String)
]),
fcl.transaction`
import commitContract from 0xf8d6e0586b0a20c7
transaction {
let receiverRef: &{commitContract.NFTReceiver}
let minterRef: &commitContract.NFTMinter
prepare(acct: AuthAccount) {
self.receiverRef = acct.getCapability<&{commitContract.NFTReceiver}>(/public/NFTReceiver)
.borrow()
?? panic("Could not borrow receiver reference")
self.minterRef = acct.borrow<&commitContract.NFTMinter>(from: /storage/NFTMinter)
?? panic("could not borrow minter reference")
}
execute {
let metadata : {String : String} = {
"name": name,
"swing_velocity": velocity,
"swing_angle": angle,
"rating": rating,
"uri": uri
}
let newNFT <- self.minterRef.mintNFT()
self.receiverRef.deposit(token: <-newNFT, metadata: metadata)
log("NFT Minted and deposited to Account 2's Collection")
}
}
`
]);
await fcl.decode(encoded);
}

this error being so useless is my fault, but I can explain what is happening here because it also only happens in a really specific situation.
Sad Panda error is a catch all error that happens when there is a catastrophic failure when fcl tries to resolve the signatures and it fails in a completely unexpected way. At the time of writing this it usually shows up when people are writing their own authorization functions so that was the first thing i looked at in your code example. Since you are using fcl.authz and fcl.currentUser().authorization (both of those are the same by the way) your situation here isnt because of a custom authorization function, which leads me to believe this is either a configuration issue (fcl.authz is having a hard time doing its job correctly) or what fcl is getting back from the wallet doesn't line up with what it is expecting internally (most likely because of an out of date version of fcl).
I have also seen this come up when the version of the sdk that fcl uses doesnt line up with the version of the sdk that is there (because some people have added #onflow/sdk as well as #onflow/fcl) so would also maybe check to make sure you only have fcl in your package.json and not the sdk as well (everything you should need from the sdk should be exposed from fcl directly, meaning you shouldnt need the sdk as a direct dependency of your application)
I would first recommend making sure you are using the latest version of fcl (your code should still all work), then i would make sure you are only using fcl and not inadvertently using an older version of the sdk. If you are still getting the same error after that could you create an issue on the github so we can dedicate some resources to helping sort this out (and make it so you and others dont see this cryptic error in future versions of fcl)

Related

Sentinel import inside Terraform Cloud confusion: key "find_resources" doesn't support function calls

I'm using a Sentinel policy inside a Terraform Cloud workspace. My policy is rather simple:
import "tfplan/v2" as tfplan
allBDs = tfplan.find_resources("aci_bridge_domain")
violatingBDs = tfplan.filter_attribute_does_not_match_regex(allBDs,
"description", "^demo(.+)", true)
main = rule {
length(violatingBDs["messages"]) is 0
}
Unfortunately, it fails when invoked with this message:
An error occurred: 1 error occurred:
* ./allowed-terraform-version.sentinel:3:10: key "find_resources" doesn't support function calls
The documentation and source for find_resources (doc) expects a string, yet the Sentinel interpreter seems to think I'm invoking a method of tfplan? It's quite unclear why that is, and the documentation doesn't really help.
Any ideas?
OK I found the issue. If I paste the code for find_resources and its dependencies (to_string, evaluate_attribute) then everything works as expected.
So I have a simple import problem and need to figure out how to properly import https://raw.githubusercontent.com/hashicorp/terraform-guides/master/governance/third-generation/common-functions/tfplan-functions/tfplan-functions.sentinel

Chrome WebSpeech API returning not-allowed error?

I was using Web Speech API for speech to text. But when calling recognition.start() it is showing me SpeechRecognitionErrorEvent
recognition = new webkitSpeechRecognition()
recognition.continuous = false
recognition.interimResults = false
recognition.onend = () => console.log("ended")
recognition.onerror = () => console.log("errored")
recognition.start()
Its logging,
errored
ended
SpeechRecognitionErrorEvent {isTrusted: true, error: "not-allowed", message: "", type: "error", target: SpeechRecognition, …}
I tried it in my react project. Trying to trigger the recognizer from chrome console also results in the same error.
Someone else, as I am using it for the first time I cannot quite grasp the reason for this error. Another question with the same issue was raised in stackoverflow from where I couldn't got an clear answer. Is it that I must request the speech api start method with a ssl certificate. Otherwise, I cannot use the feature.
UPDATE:
I had to enable microphone permission manually in the browser to get rid of this error.
Just for the record, another reason this error can occur is if you are sending a Permissions-Policy header (W3C Working Draft) in your HTTP responses and include the string microphone=() to disable access to the microphone. This header is typically used to prevent malicious third-party scripts from asking for the microphone.
Try this :
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.start()

Function in Cloud App Engine cannot read 'seconds'?

Yesterday, I redeployed a google app engine cron job cron.yaml and app.yaml for a function that would run every minute. Now, however, I am receiving the error message
Cannot read property 'seconds' of null
at Function.fromProto (/user_code/node_modules/firebase-admin/node_modules/#google-cloud/firestore/build/src/timestamp.js:91:46)
at _firestore.request.then.resp (/user_code/node_modules/firebase-admin/node_modules/#google-cloud/firestore/build/src/write-batch.js:472:42)
I don't think this is an error with the code in the function, as I have redeployed the function. In addition, I have tried accessing the aforementioned file and can find no trace of any problem. Is this a problem with the deployment? How can I resolve this issue?
EDIT:
I also started receiving this
The behavior for Date objects stored in Firestore is going to change
AND YOUR APP MAY BREAK.
To hide this warning and ensure your app does not break, you need to add the
following code to your app before calling any other Cloud Firestore methods:
const firestore = new Firestore();
const settings = {/* your settings... */ timestampsInSnapshots: true};
firestore.settings(settings);
With this change, timestamps stored in Cloud Firestore will be read back as
Firebase Timestamp objects instead of as system Date objects. So you will also
need to update code expecting a Date to instead expect a Timestamp. For example:
// Old:
const date = snapshot.get('created_at');
// New:
const timestamp = snapshot.get('created_at');
const date = timestamp.toDate();
Please audit all existing usages of Date when you enable the new behavior. In a
future release, the behavior will change to the new behavior, so if you do not
follow these steps, YOUR APP MAY BREAK.
As a result, I added
const firestore = new Firestore();
const settings = {timestampsInSnapshots: true};
firestore.settings(settings);
But I receive this error when deploying :
Firestore is not defined
at Object.<anonymous>
I started getting the "Cannot read property 'seconds' of null" error last week as well. For me it seems to only show up when trying to commit a batch with no sets/updates/deletes. Are you using batches?
Regarding the timestampsInSeconds error, try using admin.firestore() instead of Firestore() (but still configuring the settings).
Would be nice to get some guidance on this from the Firebase team, as they haven't really addressed timestamsInSeconds for functions.
EDIT:
Today I added code to only call batch.commit() if batch._writes.length > 0, and it seems to prevent the "'seconds' of null" error. Kind of sloppy, but it will work until Firebase fixes their code.

Wrong currency info being returned when calling spot price endpoint using Python

I have noticed that the data endpoint for getting the spot price is returning the wrong currency information when using Python. I am using a currency_pair of BTC-USD but getting results for GBP.
Example:
price = client.get_spot_price(currency_pair = 'BTC-USD')
Response:
{
"amount": "5578.85",
"base": "BTC",
"currency": "GBP"
}
Any ideas on whats causing this problem?
A workaround, though not using the official Coinbase client, would be as follows:
import requests
import json
# Do This to Avoid Warning
headers = {
'CB-VERSION': '2017-12-08'
}
# Make Request
data = requests.get('https://api.coinbase.com/v2/prices/BTC-USD/sell/', headers=headers).text
# Parse Response, Get Amount
price = json.loads(data)['data']['amount]
Obviously not very robust in terms of handling errors, exceptions, or any other types of assertions one would need (that the official client should have) that would be needed to provide the confidence needed for actual buys/sells/transfers.
EDIT: UPDATE
Apparently this is a known issue:
Read here:
https://github.com/coinbase/coinbase-python/issues/32
Supposedly already fixed in the github master, though obviously not reflected in the pip version yet.
Quoting user kflecki:
I fixed this by going into the client.py file and modifying the code to look like this. Works just fine now, however would be nice for the files to come like this. But it's a simple fix that you can do on your own.
def get_spot_price(self, **params):
"""https://developers.coinbase.com/api/v2#get-spot-price"""
if 'currency_pair' in params:
currency_pair = params['currency_pair']
else:
currency_pair = 'BTC-USD'
response = self._get('v2', 'prices', currency_pair, 'spot', data=params)
return self._make_api_object(response, APIObject)
And now the command works like so:
eth_price = client.get_spot_price(currency_pair = 'ETH-USD')

Cortana ran into an issue

I have created a javascript application (aka UWA) in order to play with my Belkin wemo and then turn on or turn off the ligth with Cortana. The following function is well called but Cortana ends up with an issue. If I remove the call to the HTTP call, the program works fine. Who can tell me what's wrong with the following function because no more details are exposed unfortunately (of course in the real program is replaced with the right URL):
function setWemo(status) {
WinJS.xhr({ url: "<url>" }).then(function () {
var userMessage = new voiceCommands.VoiceCommandUserMessage();
userMessage.spokenMessage = "Light is now turned " + status;
var statusContentTiles = [];
var statusTile = new voiceCommands.VoiceCommandContentTile();
statusTile.contentTileType = voiceCommands.VoiceCommandContentTileType.titleOnly;
statusTile.title = "Light is set to: " + status;
statusContentTiles.push(statusTile);
var response = voiceCommands.VoiceCommandResponse.createResponse(userMessage, statusContentTiles);
return voiceServiceConnection.reportSuccessAsync(response);
}).done();
}
Make sure that your background task has access to the WinJS namespace. For background tasks, since there isn't any default.html, base.js won't be getting imported automatically unless you explicitly do it.
I had to update winjs to version 4.2 from here (or the source repository on git), then add that to my project to update from the released version that comes with VS 2015. WinJS 4.0 has a bug where it complains about gamepad controls if you try to import it this way (see this MSDN forum post)
Then I added a line like
importScripts("/Microsoft.WinJS.4.0/js/base.js");
to the top of your script's starting code to import WinJS. Without this, you're probably getting an error like "WinJS is undefined" popping up in your debug console, but for some reason, whenever I hit that, I wasn't getting a debug break in visual studio. This was causing the Cortana session to just hang doing nothing, never sending a final response.
I'd also add that you should be handling errors and handling progress, so that you can periodically send progress reports to Cortana to ensure that it does not time you out (which is why it gives you the error, probably after around 5 seconds):
WinJS.xhr({ url: "http://urlhere/", responseType: "text" }).done(function completed(webResponse) {
... handle response here
},
function error(errorResponse) {
... error handling
},
function progress(requestProgress) {
... <some kind of check to see if it's been longer than a second or two here since the last progress report>
var userProgressMessage = new voiceCommands.VoiceCommandUserMessage();
userProgressMessage.DisplayMessage = "Still working on it!";
userProgressMessage.SpokenMessage = "Still working on it";
var response = voiceCommands.VoiceCommandResponse.createResponse(userProgressMessage);
return voiceServiceConnection.reportProgressAsync(response);
});

Resources