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(){...}).
Related
I am a fairly new to web development and have not given much thought to error. But today I noticed something I have to use json.stringyfy() to see the entire error object. Also message key is not shown in statement 2 but when I print error.message I get a message instead of undefined.
"message" is not even a key(check statement 4) but still logging error.message logs a value(typeof(error.message) is string) .
try {
//Some error occours
} catch (error) {
console.log(JSON.stringify(error)) //statement 1
console.error(error) //statement 2
console.log(error.message) //statement 3
console.log(Object.keys(error)) //statement 4
}
statement 1 logs
MongoServerError: E11000 duplicate key error collection: trendyApp.Markets index: name_1 dup key: { name: "murat market" }
at D:\web projects\trendyApp\server\node_modules\mongodb\lib\operations\insert.js:51:33
at D:\web projects\trendyApp\server\node_modules\mongodb\lib\cmap\connection_pool.js:273:25
at handleOperationResult (D:\web projects\trendyApp\server\node_modules\mongodb\lib\sdam\server.js:363:9)
at MessageStream.messageHandler (D:\web projects\trendyApp\server\node_modules\mongodb\lib\cmap\connection.js:474:9)
at MessageStream.emit (events.js:375:28)
at processIncomingData (D:\web projects\trendyApp\server\node_modules\mongodb\lib\cmap\message_stream.js:108:16)
at MessageStream._write (D:\web projects\trendyApp\server\node_modules\mongodb\lib\cmap\message_stream.js:28:9)
at writeOrBuffer (internal/streams/writable.js:358:12)
at MessageStream.Writable.write (internal/streams/writable.js:303:10)
at TLSSocket.ondata (internal/streams/readable.js:726:22) {
index: 0,
code: 11000,
keyPattern: { name: 1 },
keyValue: { name: 'murat market' }
}
statement 2 logs
{"index":0,"code":11000,"keyPattern":{"name":1},"keyValue":{"name":"murat market"}}
statement 3 logs
E11000 duplicate key error collection: trendyApp.Markets index: name_1 dup key: { name: "murat market" }
I saw this behavior while I was making an express application and the error is generated by mongoose but I think this would be common throughout javascript
statement 4 logs
[ 'index', 'code', 'keyPattern', 'keyValue' ]
"message" is not even a key(check statement 4)
It is, but Object.keys is designed to list enumerable properties, and message is not enumerable.
In the ECMAScript specification, we see in the section on the Error constructor that the constructor creates its message (and other properties) with the procedure:
Perform CreateNonEnumerableDataPropertyOrThrow(O, "message", msg).
Other -- custom -- properties can of course be added to Error objects by JavaScript code, which explains why other properties are listed by Object.keys().
As to the output of console.log: the console API implementation has a lot of freedom on how to display objects -- lot's of differences can be found between implementations.
To also output those non-enumerable properties, use
console.log(Object.getOwnPropertyNames(error))
As #trincot said, it is not shown because of message is a non enumerable attribute for Error constructor, the MongoServerError is overriding the MongoError and actually this is overriding the JS Error object, so if you need to know what attributes you have into the error you can check the previous links to see what attributes you can check.
Also if you want to get all the attributes (included the non enumerable ones) you can use Object.getOwnProperties(error) to see all the attributes that the given object has.
Also you can use Object.getOwnPropertyDescriptors(error) to know what is the descriptor for each attribute you've defined into the given object.
Sadly error stack and message fields are not enumerable, below is a utility function that extracts all properties from an error object, even custom fields you assign to errors:
const err = new Error('Something bad happened.');
err.metadata = { custom: { field: '1' } };
console.log(errorToPOJO(err)); // {"stack":"Error: Something bad happened.\\n at <anonymous>:1:13","message":"Something bad happened.","metadata":{"custom":{"field":"1"}}
function errorToPOJO(error) {
const ret = {};
for (const properyName of Object.getOwnPropertyNames(error)) {
ret[properyName] = error[properyName];
}
return ret;
};
Try this if your using api
console.log(error.message.toString())
I'm trying to follow this tutorial.
Basically, I want to create my custom function that creates a folder if it not exists.
var makeDir = (path) => {
const file = Gio.file_new_for_path(path);
if (file.query_exists(path)) {
print(`Dir already exists ${path}`);
return;
}
print(`My Path: ${path}`);
// file.make_directory(path);
};
When I run this code I'm receiving an error:
Gjs-CRITICAL **: 17:35:17.161: JS ERROR: Error: Expected an object of type GCancellable for argument 'cancellable' but got type string
In the documentation I see that GCancellable is optional. So I have no idea why my code does not work. Haw can I make it work?
In the C documentation, "optional" means something else than it usually does in JS: it means it's optional to pass a real pointer as that argument, and you may also pass NULL.
The error message is complaining about a string because query_exists() does not take a path string argument. Check the JS documentation for the list of arguments accepted in JS: you should call file.query_exists(null).
I am trying to convert all characters in a search field to lower case in my react app using the toLowerCase() method but gives the error typeError: Cannot read property 'toLowerCase' of undefined.
onSearchChange = (event) => {
const filteredRobots = this.state.robots.filter(robot => {
return robots.name.toLowerCase().includes(this.state.searchfield.toLowerCase());
})
You aren't including enough information to solve the issue, but here's my best guess:
Your robots.name.toLowerCase() should be robot.name.toLowerCase() instead (note the missing s on robot).
You're attempting to read the name property off the array you're filtering on rather than the current element that's being operated on.
My recommendation for when you run across errors like this in the future is to check your error log for something like this:
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
at <myFunction>:1:27
This would read as TypeError in "myFunction" function at line 1, column (character) 27. You'd then be able to pinpoint exactly where your error is coming from. If you're still stuck, it's useful info to post along with your problem.
const filteredRobots = this.state.robots.filter(robot => {
return robot.name.toLowerCase().includes(this.state.searchfield.toLowerCase());
})
I think this is just typo.
Replace 'robots' with 'robot'
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
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.