Cloud code (javascript) failed wtih: {"code":1,"message":"internal error"} - javascript

I'm trying to run the following code:
if(req.query.currentPosition) {
console.log("[DEBUG] My current position: " + req.query.currentPosition);
var maxRadius = 10;
var coordinates = req.query.currentPosition.split(",");
var latitude = parseFloat(coordinates[0]);
var longitude = parseFloat(coordinates[1]);
var point = new Parse.GeoPoint({latitude: latitude, longitude: longitude});
query.withinKilometers("coordinates", point, maxRadius);
}
return query.find({});
where I read some coordinates from the requests query parameters and I pass those onto a query as a geolocation constraint. Whenever the code runs I get the error
{"code":1,"message":"internal error"}
and nothing more specific. If I remove the above code block, I don't have any error at all.
I've done some research, and I have found that some other developers have also stumbled upon this message, though in a different context.
https://www.parse.com/questions/cloud-code-failed-with-code-1message
https://www.parse.com/questions/facebook-login-code-1-internal-error
Yet no satisfying conclusion was reached or provided.
What have I tried so far:
Multiple redeploys (my favourite)
adding and removing the "coordinates" columns
One of the suggestions from the links I found was that it could a parse internal issue, so waited a day or so to see if anything could be magically solved
Added a ridiculously amount of logs to see if I could print anything that it could give me a better description of what was happening
Also checked if anything could be wrong with the data
Compared with other running applications that have the same code block and are working to see what could be wrong.
None of the above proved to be helpful.
SDK Version
Parse JavaScript SDK v1.3.3
Any enlightenment is appreciated.
Cheers.

I just found the problem. I was setting the wrong key when adding the "withinKilometers" constraint.
Cheers

Related

Getting Values out of Websocket Functions

I am working on a project which needs to get communication from C++ code to JavaScript on a webserver. Currently, I have data sending properly and it's being received but the issue is that I cant use the data outside of the inner(onmessage) function. This still works fine to overwrite elements of the webpage, but the charts I'm trying to build cant get the live data. If I put the code for the chart inside the inner function the entire program freezes and I can't get the variable out of the function for me to use it in the parent either. Right now, I just want to get the data out of the inner function so I can use it. So, is there any way for me to pull that data out of the inner function and use it in the parent function?
Here is my code:
{
var x;
var ws = new WebSocket('ws://localhost:10011/');
ws.onmessage = function(event)
{
x = event.data;
var testing = document.getElementById('InnerFunctionOutput');
testing.innerHTML = "Run Time: " + x;
}
var testing = document.getElementById('ParentFunctionOutput');
testing.innerHTML = "Run Time: " + x;
}
When I run this code the output from the inner function is the constant stream of data and the output from the parent is a constant 1. If anyone could help me find a solution, it would be greatly appreciated.
One alternative solution is to put the functions for the charts inside the websocket function. That way, I wouldn't have to get data out of the function. however, this solution has its own set of problems. I will put a link below to a thread where I ask about this alternate solution if you are interested in that part.
Plotly and Websockets
Any help would be greatly appreciated.
Thanks,
Luke
I found a solution to the problem. To get the data out of the websocket function I overwrote a text element on the page and simply made that element invisible. After that, just read the text element in order to get it into the rest of the code. However, there could be a better way of doing this so please let me knw if there is.
Also, there is one issue I ran into with this solution. When I originally tried this with normal formatting document.getElementById('some id').innerHTML = some data; it didn't work. But when with adding "window" to the beginning window.document.getElementById('some id').innerHTML = some data; it just worked.

Authorization error still persists when calling getDataSourceFormula() even after allowing script to acces Google Sheets

I am trying to get the content of a cell's formula from a custom function that I wrote. I'm just trying to get the formula stored in B2. In Google Sheets. I am getting "Exception: Authorization is required to perform that action. (line 5).". I tried revoking the authorization, adding the next first three lines and authorizing again. Nothing worked.
/**
* #OnlyCurrentDoc
*/
function test() {
return SpreadsheetApp.getActiveSheet().getRange('B2').getDataSourceFormula().getFormula();
}
I can confirm that the error is coming from getDataSourceFormula(). I tried replacing it with other functions, and they worked normally. What is the problem?
Thanks.
You are using incorrectly getDataSourceFormula() as you are combining it with getFormula().
getFormula() returns the top left cell formula of a range while getDataSourceFormula() returns the DataSourceFormula for the first cell in the range. Thus, getDataSourceFormula will only work for data sources, here is more official information regarding what these are.
As you didn't mention anything about data sources in your question I am assuming that you are not using them and therefore you code line should look like this:
return SpreadsheetApp.getActiveSheet().getRange('B2').getFormula();

Ethereumjs-vm, run-transaction-complete example not printing storage

Running the example mentioned in the title, there is no output after the "---Storage---" line. According to my understanding, there should be a null_radix stored at the created address. (running gives no exceptions) please correct me if I’m wrong!
[update]
At the following part of the example at the runTx function I've noticed that we refresh the createdAddress variable at every transaction even though it doesn't register a new contract. Therefore it leaves us with the loss of our contract's address and the readStorage function won't print any output.
I've fixed it by checking the createdAddress property for null before saving the value.
if (returns.createdAddress) {
createdAddress = results.createdAddress
console.log('address created: ' + createdAddress.toString('hex'))
}

Why are my locations undefined and display not updating?

I am having some issues with a class project. Every thing was working fine and dandy up until the current part we are on. Basically, we had to add prototypes and cases to move to each location. Now my code will not work, and the teacher is about as helpful as a pet rock. I have two parts to my code, the html (which has part of the code including items and such) and the .js file that includes the locations.
I have created a repository on Github so it is easily accessible to all who want to help. At this point it is too late to submit to my professor, but I am curious on what I did wrong.
https://github.com/EmeraldX/Project-Help/tree/master
The main and directions.js are the files that I am currently working with.
Thanks!
Update: Okay, so it's still not working, and when I use Chrome's console it just tells me that:
function updateDisplay( message ) {
var textArea = document.getElementById("introduction");
textArea.value = message + "\n\n" + textArea.value;
Cannot read property 'value' of null
I tried opening your html page and js using firefox, and used the firebug consol to see if anything was wrong.
It looks like you have an ) missing in your js:
SyntaxError: missing ) after argument list directions.js:7:145
And it was right:
locations[2] = new Location(2,"Lake","A large lake that is formed by a river flowing from the East.",
new Item(1,"Fish","An old rotting fish.");
is missing a ')'
After correcting it, it appear that you miss this ) line 7, 9, 13 and 14.
Then a new error pop up:
ReferenceError: Item is not defined directions.js:7:2
This can be corrected by calling your direction.js AFTER you js script in main.html.
Hope it can help

CPRangeException thrown when objects added to an CPArray

In my cappuccino app, I am reading from an RoR backend via JSON and putting the results onto a list. When the app first loads everything is fine, but when I edit an item (and write the edit to the database) there is an error generated when the items list is refreshed.
The error is CPRangeException: -[_CPJavaScriptArray objectAtIndex:]: index (-1) beyond bounds (3).
I get this error even if I edit an item without making any actual changes. The JSON string received by the app remains exactly the same in this case, there are no items added or removed and therefore the array should not be written to out of bounds.
Here is my code:
- (void)connection:(CPRURLConnection)connection didReceiveData:(CPString)data
{
if(connection === listConnection)
{
var results = JSON.parse(data) ;
var posts = [Post initFromJSONObjects:results];
[postListView setContent:posts] ;
// My error occurs at the above line
[postListView setSelectionIndexes:[[CPIndexSet alloc] initWithIndex:0]] ;
}
}
I am not sure if it's an error with my code or if it's some kind of inconsistency with the cappuccino framework. Does anybody know what I can do to fix this?
The rest of the code can be found here
You should probably simply log what's in posts before setting it. CPLog.info('posts: ' + posts); should work, or console.log(posts). Next you can set a 'break on uncaught exception' debug point in Chrome or Safari to stop at the actual error you are seeing. Make sure you run your app using index-debug.html so that you get full method names. Then it should be an easy matter to look at the calling stack to see where things are going wrong. There's a lot of information on debugging a Cappuccino app here.

Categories