Uncaught TypeError: undefined is not a function - prototypejs

this error Uncaught TypeError: undefined is not a function keeps getting thrown it is part if the prototype.js I didn't write the website but it seems to be causing lots of errors on other items. What is the cause of this? Thanks
var Enumerable = (function() {
function each(iterator, context) {
var index = 0;
try {
this._each(function(value) {
iterator.call(context, value, index++);
});
} catch (e) {
if (e != $break) throw e;
}
return this;
}

The object being enumerated is probably not enumerable. Look into the code anywhere you have .each() and make sure a valid object/array is being passed onto it.

Related

apollo-client Network error if field is null

This particular code has been now running without issues for months, this morning, without any relevant change I can pinpoint in our setup or our code I started receiving
ERROR Error: Uncaught (in promise): Error: Network error: Cannot convert undefined or null to object Error: Network error: Cannot convert undefined or null to object
at new ApolloError (ApolloError.js:43)
at eval (QueryManager.js:324)
at eval (QueryManager.js:755)
at Array.forEach (<anonymous>)
at eval (QueryManager.js:754)
at Map.forEach (<anonymous>)
at QueryManager.broadcastQueries (QueryManager.js:749)
at eval (QueryManager.js:251)
at ZoneDelegate.invoke (zone.js:388)
at Object.onInvoke (core.js:4733)
at new ApolloError (ApolloError.js:43)
at eval (QueryManager.js:324)
at eval (QueryManager.js:755)
at Array.forEach (<anonymous>)
...
inline.bundle.js:26 (anonymous) # main.bundle.js:1
This happens because of an error at Object.keys(src).forEach:
var hasOwn = Object.prototype.hasOwnProperty;
export function merge(dest, src) {
Object.keys(src).forEach(function (key) {
var srcVal = src[key];
if (!hasOwn.call(dest, key)) {
dest[key] = srcVal;
}
else if (srcVal && typeof srcVal === 'object') {
merge(dest[key], srcVal);
}
});
}
The error is:
"Cannot convert undefined or null to object"
merge is called from here:
function executeSelectionSet(selectionSet, rootValue, execContext) {
var fragmentMap = execContext.fragmentMap, contextValue = execContext.contextValue, variables = execContext.variableValues;
var result = {};
selectionSet.selections.forEach(function (selection) {
if (!shouldInclude(selection, variables)) {
// Skip this entirely
return;
}
if (isField(selection)) {
var fieldResult = executeField(selection, rootValue, execContext);
var resultFieldKey = resultKeyNameFromField(selection);
if (fieldResult !== undefined) {
if (result[resultFieldKey] === undefined) {
result[resultFieldKey] = fieldResult;
}
else {
merge(result[resultFieldKey], fieldResult);
}
}
}
else {
var fragment = void 0;
if (isInlineFragment(selection)) {
fragment = selection;
}
else {
// This is a named fragment
fragment = fragmentMap[selection.name.value];
if (!fragment) {
throw new Error("No fragment named " + selection.name.value);
}
}
var typeCondition = fragment.typeCondition.name.value;
if (execContext.fragmentMatcher(rootValue, typeCondition, contextValue)) {
var fragmentResult = executeSelectionSet(fragment.selectionSet, rootValue, execContext);
merge(result, fragmentResult);
}
}
});
if (execContext.resultMapper) {
return execContext.resultMapper(result, rootValue);
}
return result;
}
After I identified the field that was being parsed and the fact the it was null valued in the backend I tried to change the value and then the error moved to the next null valued field for the same node. I tried also with other queries and we have the same result.
We are using django and graphene at the backend and apollo-client at the frontend.
I would be grateful for any insight here, I am still trying to understand what has changed between 23:00 yesterday (latest time I tested the code that is now bombing and it all worked) and 1am tonight (time of the automated deployment on our dev server).
I got a similar error last night and for me, I was able to track it down to a change in the graphql-anywhere package from version 4.1.8 to 4.1.9 (updated 2 days ago).
Here is the changelog: https://github.com/apollographql/apollo-client/blob/master/packages/graphql-anywhere/CHANGELOG.md
Adding "graphql-anywhere": "4.1.8", to my package.json file has solved the issue for my app.

Async binding in Aurelia

I'm trying to bind an async value to one of my Aurelia templates, and obviously all I get is [object Promise] in return.
I found this article http://www.sobell.net/aurelia-async-bindings/ which excellently explains how to solve this problem using a binding behavior which looks like this:
// http://www.sobell.net/aurelia-async-bindings/
export class asyncBindingBehavior {
bind (binding, source) {
binding.originalUpdateTarget = binding.updateTarget;
binding.updateTarget = a => {
if (typeof a.then === 'function') {
binding.originalUpdateTarget('...');
a.then(d => {
binding.originalUpdateTarget(d);
});
}
else {
binding.originalUpdateTarget(a);
}
};
}
unbind (binding) {
binding.updateTarget = binding.originalUpdateTarget;
binding.originalUpdateTarget = null;
}
}
This works perfectly when the promise resolves with a string or other non-object-like variable.
But what if my promise resolves with an object? How would I go about accessing the property I need inside that object?
Because if I do: ${object.property & async} inside my template then it will fail as object.property isn't a promise - only object is.
I added a bit of a hack that allows me to specify a property as an argument to async, like this: ${object & async:'property'} and updated my binding behavior as such:
// http://www.sobell.net/aurelia-async-bindings/
export class asyncBindingBehavior {
bind (binding, source, property) {
binding.originalUpdateTarget = binding.updateTarget;
binding.updateTarget = a => {
if (typeof a.then === 'function') {
binding.originalUpdateTarget('...');
a.then(d => {
if (property) {
binding.originalUpdateTarget(d[property]);
}
else {
binding.originalUpdateTarget(d);
}
});
}
else {
binding.originalUpdateTarget(a);
}
};
}
unbind (binding) {
binding.updateTarget = binding.originalUpdateTarget;
binding.originalUpdateTarget = null;
}
}
But this feels very much like a hack to me, and it also won't allow me to access any deeper properties like object.parent.child.
I also found this (rather old) issue on GitHub: https://github.com/aurelia/templating/issues/81 where they use a getValue method. I've never heard of this method and trying to use it fails so I'm not sure how that works at all...
Any ideas?
You could sidestep your conundrum by specifying a function as the third parameter, giving the flexibility to do much more than simple property extraction.
You could write something like this :
export class asyncBindingBehavior {
bind (binding, source, transformer="default") {
binding.originalUpdateTarget = binding.updateTarget;
binding.updateTarget = a => {
if (typeof a.then === 'function') {
binding.originalUpdateTarget('...');
a.then(d => binding.originalUpdateTarget(transformFunctions[transformer](d)));
} else {
binding.originalUpdateTarget(a);
}
};
}
unbind (binding) {
binding.updateTarget = binding.originalUpdateTarget;
binding.originalUpdateTarget = null;
}
}
The transformFunctions lookup would be necessary(?) due to the way Aurelia bindings are specified as HTML-ebbedded or template directives (ie all params must be String). Unless Aurelia offers a better way better way to "pass a function" (Value Converters?), you would write something like this :
export var transformFunctions = {
default: (d) => d,
transform1: (d) => d.someProperty,
transform2: (d) => d.someProperty.someOtherProperty,
transform3: someFunction,
transform4: someOtherFunction.bind(null, someData);
}
Of course, you would give the functions better names.

Node module imported via require has no methods

I'm having a problem with node modules that I cannot resolve. I have the following three files. I've included the basic methods of interest but have excluded the rest of the methods and the actual guts of the methods.
The problem that I'm struggling with is that when the publish_event method is called on the event_queue object from events.js node crashes with the following error:
FATAL TypeError: Object # has no method 'publish_event', stack:
TypeError: Object # has no method 'publish_event'
at Events.publish_event (/Users/mburbidg/stormcloud/ccapi/cloud_pipes/node_modules/f5/server/services/event/events.js:137:15)
I cannot figure this out, you can see that I can use methods of the EventQueue object from index.js, another module, in our system just fine. I've checked names other obvious things several times.
Any suggestions as to how to proceed?
File 1 - f5/server/notifications/sqs_event_queue.js
function EventQueue() {
this.queue_name = 'notification_queue';
this.queue_url = null;
this.sqs = null;
}
EventQueue.prototype.publish_event = function(event_data, registration_id, log, callback) {
...
}
EventQueue.prototype.start = function(callback) {
...
}
module.exports = new EventQueue();
File 2 - f5/server/index.js
var event_queue = require('f5/server/notifications/sqs_event_queue');
var start_notifications = function()
{
event_queue.start(on_start);
function on_start(error)
{
}
}
File 3 - f5/server/services/event/events.js
var event_queue = require('f5/server/notifications/sqs_event_queue');
function Events () {
}
Events.prototype.publish_event = function(event_data, registration_id, log, callback) {
event_queue.publish_event(event_data, registration_id, log, callback);
};
module.exports = new Events();

Get error for using Type object in function

I have a function to return Type Object in the class. It is work on webpage, but not windows phone application. The error is "Expected class, delegate, enum, interface or struct". Would anyone tell me how to solve it. Thanks.
There is my code:
public static object GetData(Uri relativeUri)
{
return GetData<object>(relativeUri);
}
public static T GetData<T>(Uri relativeUri)
{
var request = CreateRequest(relativeUri);
HttpWebResponse r;
//return Deserializer<T>(request.GetResponse().GetResponseStream());
try
{
r = (HttpWebResponse)request.GetResponse();
return Deserializer<T>(r.GetResponseStream());
}
catch (WebException webex)
{
HttpWebResponse webResp = (HttpWebResponse)webex.Response;
setSessionError(webResp.GetResponseStream());
}
return Deserializer<T>(request.GetResponse().GetResponseStream());
}
I found it what is wrong on my code. I have extra close bracket that put the function out of the class.

IE & Ajax / XPath

I've read countless threads and tried implementing many different suggestions, but haven't had any luck.
first:
function ajaxRequest() {
try {
var request = new XMLHttpRequest();
}
catch(e1) {
try {
var request = new ActiveXObject("Msxml2.HTMLHTTP");
}
catch(e2) {
try {
var request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e3) {
var request = false;
}
}
}
return request;
}
It looks like IE is successfully using XMLHttpRequest. As far as I can tell, it's loading the XML fine, but Xpath is another story:
function XMLPath(doc, path) {
try {
return doc.evaluate(path, doc, null, XPathResult.STRING_TYPE, null).stringValue;
} catch (e) {
try {
doc.setProperty("SelectionLanguage", "XPath");
return doc.selectNodes(path);
}
catch(e2) {
alert(e2);
}
}
}
Basically, what must I change in my catch statement to make it work with IE? What's also interesting is that it never alerts an e2 error, meaning it's not actually throwing an error. Totally confused.
Thanks.
Try return doc.selectSingleNode(path).text; for IE, that is the closest you can get for accessing the string value of the node found by your path.

Resources