Parse.Object.fetchAll throwing unexpected Error - javascript

Been trying to debug this for over a day. Any help is very much appreciated.
In cloud code, I am attempting to invoke Parse.Object.fetchAll() on an array of Parse.Role pointers like so:
function loadRoles (company) {
var roles = company.get('roles');
console.log(roles.length); // 1
console.log(roles[0].isNew()); // false
promise = Parse.Object.fetchAll(roles)
.fail(function(error){
// This gets triggered with error
// {code: 101, message: 'All objects must exist on the server'}
});
}
Given that the roles array contains a single Parse.Role that is both not isNew(), and has an id, I have no idea why I'm getting this error. I've tinkered with this for more than a day and can't seem to figure it out. Any help would be much appreciated.

These roles have to exist on the server. Missing roles will cause that error if any of those objects have been removed in another operation.
EDIT: Use Parse.Object.fetchAllIfNeeded(roles) to avoid the error.

Related

client.guilds.cache.get(...). members.get It is not a function

I'm doing a command with cargo, this error comes and I can't understand it, here's the script:
const member = client.guilds.cache.get('980553630480474232').members.get(interaction.user.id);
And here is the error:
client.guilds.cache.get(...).members.get is not a function.
In v13, you need to use .cache.get(), if the error persists double check your guild ID.
If you encounter such an error try console.log() to see wich value is undefined, because such errors results from having undefined values.
And for future advice if you need a value more than once in your code define it first, in this case use
const guild = client.guilds.cache.get('980553630480474232');
const member = guild.members.cache.get('ID')
Side Note: If this is a command file, you can directly get the guild using:
interaction.guild.members.get(interaction.user.id)

Unable to pass a firebase storage download URL to a interface property

I am uploading an file to firebase storage. Then I am getting the file URL as below
snapshot.ref.getDownloadURL().then(function(rawFileURL) {
console.log("File available at", rawFileURL);
this.downloadURL = rawFileURL;
});
Now I am trying to pass this attribute to an interface which I want to submit to the firestore document. Like this.
let sData: Data = {
rawfilepath: this.downloadURL, // I also tried passing rawFileURL
//rawfilepath: audioImagesRef.toString(),
readyfilepath: "",
teller: form.value.steller,
title: form.value.stitle,
userid: uid,
}
I get the following error while submitting the interface properties to firestore
ERROR FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined (found in field rawfilepath)
If I pass a normal string "" or say user.id to the interface, it works fine. But when I try to store downloadURL in the rawfilepath, it errors out.
Any help would be appreciated. Thanks in advance
Although it is hard the see the problem with available data, it is safe to assume that you are assigning the this.downloadURL before it has a value in it. snapshot.ref.getDownloadURL() returns a promise which run asynchronously not in order with the codes before or after.
A sample usage for your case would be;
let sData: Data;
snapshot.ref.getDownloadURL().then(function(rawFileURL) {
sData = {
rawfilepath: rawFileURL,
readyfilepath: "",
teller: form.value.steller,
title: form.value.stitle,
userid: uid,
}
});
The error is telling you that rawfilepath (this.downloadURL) is undefined. You will have to do some debugging to figure out why that is. It's looks likely that you're trying to use this.downloadURL before its value was provided in the callback provided to getDownloadURL().
Remember that functions that return promises are aysnchronous and return immediately, before the work is complete. So, you should only use this.downloadURL inside the callback, or some other time when you are absolutely certain that the callback is complete.

Ramda: access input object's properties inside R.ifElse() function call

I have this existing function:
const inferProcessingError = R.ifElse(
R.propEq('conversionJobStatus', 3),
R.always('Last Process failed with error; please contact DevOps'),
R.always(null)
);
which is called like this:
const msg = inferProcessingError(jobStruct || {});
with this jobStruct:
{"id":9,"mediaGroupId":1000000,"conversionJobStatus":3,
"errorDetails": {
"Cause": {
"errorMessage": "MediaConvert Job Failed with ERROR status: ERROR Video codec [indeo4] is not a supported input video codec",
},
"Error": "Error",
}
}
and I need to create an error message string which includes the data from the Cause.errorMessage element.
This would be dead simple with a native JavaScript function, but I'm learning Ramda and want to just modify the existing code to include in the error message.
An R.prop('Cause')['errorMessage'] could work except that I can't figure out how to reference the jobStruct that was passed in to the inferProcessingError statement.
I can see that the R.ifElse and subsequent Ramda functions are able to get that reference, but when I embed an R.prop('Cause') in the error message string, it resolves to a function and not the value of the Cause element because it seems to be waiting for the data structure.
So...how do I gain access to the jobStruct reference? (arguments is not defined here).
UPDATE:
I can get this to work by referencing the original jobStruct as in R.Prop('ErrorDetails', jobStruct)['Cause']['errorMessage'] but that seems rather kludgy to me...
BUT if the call to inferProcessingError is actually inside a map statement and references an element in a larger structure, then the map index is not available to reference the data structure for the R.prop.
Perhaps you could use the pipe and path methods to achieve this "the ramda way".
Begin by using ramda's path() function to extract the nested errorMessage value from the input jobStruct object. Next, enclose that in a pipe() that transforms the extracted message into a string formatted with a custom error prefix:
const incCount = R.ifElse(
R.propEq('conversionJobStatus', 3),
/* Evaluate this pipe if the error case is satisfied */
R.pipe(
/* Path to extract message from input object */
R.path(["errorDetails", "Cause", "errorMessage"]),
/* Prefix string to extracted error message */
R.concat('Custom error prefix:')),
R.always('')
);
incCount({"id":9,"mediaGroupId":1000000,"conversionJobStatus":3,
"errorDetails": {
"Cause": {
"errorMessage": "MediaConvert Job Failed with ERROR etc etc",
},
"Error": "Error",
}
});
Here's a working example - hope that helps!
Update
Thanks to #customcommander for the suggestion to use concat for the string prefix, as well as returning an empty string value for the second branch

Count Undefined with MongoDB and Nodejs

Problem
Node.js MongoDB library consistently returns undefined for collection.count({}). This question has been posted and answered numerous times, and I've been sure to go through all previous solutions, but none seem to work, and I always get undefined.
As a background to the question, I am making a Job Automator, and before adding a new job, I want to make sure that 0 records already exist in the database that have the same name as the new job being added (i.e. names are unique). EDIT: There are a few cases where I do want to allow duplicates, so I don't want using indexing and dis-allow duplicates at the DB level.
Code
In this case, the console.log() inside count just prints undefined. In this case, I have put in an empty query string as part of debugging (not currently testing for name collisions).
add: function(io, newJob)
{
//mc is where require('mongodb').MongoClient is saved
//connectionString contains a valid connection string
//activeCollection contains the name of the collection
//(I am sure mc, connectionString and activeCollection are valid)
//I know this as I have used them to insert documents in previous parts
mc.connect(connectionString, function(err,db)
{
if(err)
throw err;
else
{
db.collection(activeCollection, function(err,collection)
{
if(err)
throw err;
//Start of problematic part
//See also "What I've tried" section
collection.count({},function(err,count)
{
console.log(count);
});
//End of problematic part
//Omitting logic where I insert records for brevity,
//as I have confirmed that works previously.
});
}
db.close();
});
}
What I've tried
I've read the previous questions, and replaced the content between //Start of problematic part and //End of problematic part in the previous code block with the following blocks:
Fully breaking out the callback (also prints undefined):
function countDocs(callback)
{
collection.count({},function(err, count)
{
if(err)
throw err;
callback(null, count);
}
}
countDocs(function(err,count)
{
if(err)
throw err;
console.log(count);
});
I've even tried things I know wouldn't work
var count = collection.count({});
NEW (1/28/16)
It was a little sloppy of me to not check the error in my count(), so I added a if(err)console.log(err); into the count() block and it turns out the error is:
{ [MongoError: server localhost:27017 sockets closed]
name: 'MongoError',
message: 'server localhost 27017 sockets closed' }
Which I don't really understand because in other sections of code, I am able to use the same connect() and collection() calls and make inserts into the DB just fine. Any insight based on this?
Any help would be much appreciated!
Let's deal with the intent of the question:
I am making a Job Automator, and before adding a new job, I want to
make sure that 0 records already exist in the database that have the
same name as the new job being added (i.e. names are unique).
Rather than labor through javascript, just set a unique index on the name key. In mongo:
db.collection.ensureIndex( { name: 1 }, { unique: true } )
Then when you insert a document use a try/catch block to catch any attempt to create a document with a duplicate name.
You can use collection.find().toArray(function(err,documents) { ...});, which returns an empty array if no documents match your query. Checking the length property of the array should be equivalent to what you are trying to achieve with count().
More info in the docs: https://mongodb.github.io/node-mongodb-native/api-generated/cursor.html#toArray

Bad value error in Oboe.js

Originally asked by Sashkan on the Oboe.js Github issues:
I'm getting a stremedResponse from a distant API. When I make an ajax call, I get the following response :
{"company_id":"3e1f975601f59090decc8f2d5ced72010162e481","airplane_type_id":"c10143316664f220a5cb87950b3dbac8794e2b15","legs":
[{"lfi_from":"FR49348","lfi_to":"FR24863","nb_pax":"1","datetime_from":"2015-12-10 15:45:00","datetime_to":"2015-12-10 16:44:00","duration":"00:59","availability":true}]},{"company_id":"3e1f975601f59090decc8f2d5ced72010162e481","airplane_type_id":"opfr8976xwqs54321zdickv678654xckvjfdf025","legs":
[{"lfi_from":"FR49348","lfi_to":"FR24863","nb_pax":"1","datetime_from":"2015-12-10 15:45:00","datetime_to":"2015-12-10 16:45:00","duration":"01:00","availability":true}]},{"company_id":"3e1f975601f59090decc8f2d5ced72010162e48e","airplane_type_id":"2368c24e9980e4eb9ccd986f32df884e5bd58707","legs":
[{"lfi_from":"FR49348","lfi_to":"FR24863","nb_pax":"1","datetime_from":"2015-12-10 15:45:00","datetime_to":"2015-12-10 16:50:00","duration":"01:05","availability":true}]}
But when I use oboe, only the first one is displayed, and immediately after, I get the following oboe error:
thrown: Error: Bad value Ln: 1 Col: 65 Chr: , at Error (native) at emitError (http://openjetfrontclean/app_dev.php/bundles/main_oboe-browser_9.js:636:20) at handleData (http://openjetfrontclean/app_dev.php/bundles/main_oboe-browser_9.js:816:20) at applyEach (http://openjetfrontclean/app_dev.php/bundles/main_oboe-browser_9.js:497:20) at emit (http://openjetfrontclean/app_dev.php/bundles/main_oboe-browser_9.js:2042:10) at XMLHttpRequest.handleProgress (http://openjetfrontclean/app_dev.php/bundles/main_oboe-browser_9.js:1253:10)
message: "Bad value↵Ln: 1↵Col: 65↵Chr: ,"
stack: (...)
get stack: ()
set stack: ()
__proto__: DefineError.bh
Any idea why ?
Answer provided by JuanCaicedo
I think that response is invalid json, which you can verify by plugging it in to http://jsonlint.com/. It looks like it's three comma-separated objects. I think it's meant to be an array? If so, just add a [ at the start of the first object and a ] at the end of the last object.
Oboe is able to pick items out of a top-level array. Call .node('[*]', function(){...}).

Categories