I have running in my Mac a Node.JS server, and, I access to it from other computer, the server doesn't crash, but, I don't know why, the application crashes when I access from my iPad. If I access from Safari, the server works, but, with Chrome for iPad, the app crash!
This is the error: TypeError: Cannot read property 'following' of null. Why this happens?
EDITED:
app.get('/home', middleware.yeses, function (req, res){
console.log(req.session.user + "\n\n");
UserModel.find({ user: req.session.user }, function (err, user){
console.log(user);
res.render('home.ejs', {
username: req.session.user,
avatar: user[0].avatar,
following: user[0].following.length,
followers: user[0].followers.length
});
});
});
EDITED:
I changed the console.log(user); to this console.log(user[0].following). And there's no problem. I don't know why, there's a problem with it in the locals.
This occurs because the JavaScript is throwing an exception. Somewhere in the code, the there is a variable that is assigned to null and the property following is being accessed on that variable. This operation raises an exception.
var obj = null;
obj.following; // exception thrown!
It's impossible to help you more. With the info and code you've provided (very little of either). But look for where you are accessing a following property and debug from there.
Update:
It appears user[0] is null. Why? No idea. That depends on other code you haven't posted. WHere is user declared and populated? Is it an array? Because that would be strange for a variable named user.
Related
I need to create some reports using the websdk pertaining to orders and price quotes.
I tried following the documentation but even the example given in the developer portal is lacking a lot of crucial information.
Specifically, I need to work with these two procedures:
ESH_WWWSHOWORDER3
ESH_WWWSHOWCPROF2
I tried writing some logic arround the sample found on https://prioritysoftware.github.io/api/procedure/#Introduction
const procedure = priority.procStart(PROC_NAME,"R", () => {},customerName, function(procSuccess){
logger.info('Proc start OK, received documentOptions');
logger.info(JSON.stringify(procSuccess));
logger.info('Specifying format...');
resolve(new Promise((resolve, reject) => {
procSuccess.proc.documentOptions(1,1,2,procSuccess => {
logger.info('Received inputFields');
logger.info(JSON.stringify(procSuccess));
procSuccess.proc.inputFields(1,{ORDNUM: ordernum}, procSuccess => {
logger.info('Received url');
logger.info(JSON.stringify(procSuccess));
});
}, procError => {
reject(procError)
})
}));
}, function(procError){
logger.error('Proc start error');
logger.error(procError);
reject(procError);
});
}).catch(err => {
logger.error(err);
})
Where PROC_NAME is WWWSHOWORDER
I am trying to understand what the process is asking of me, but it's not really clear. I tried supplying some values in the order specified by the documentation but I get errors that are not very descriptive to someone who doesn't know the ins and outs of Priority.
The logs look somehting like this
Starting Procedure WWWSHOWORDER
2019-11-26T11:55:31.718Z info: Proc start OK, received documentOptions
2019-11-26T11:55:31.719Z info: {"proc":{"name":"WWWSHOWORDER"},"type":"message","message":"No such Tabula entity"}
2019-11-26T11:55:31.721Z info: Specifying format...
2019-11-26T11:55:32.124Z info: Received inputFields
2019-11-26T11:55:32.125Z info: {"proc":{"name":"WWWSHOWORDER"},"type":"message","message":"Failure to p...
Unfortunately my logs are truncated for some strange reason...
EDIT:
I switched trying to work with ESH_WWWSHOWORDER3, I am getting an inputFields parameter, and I hope what I need to do, is take the iinputFields.input.EditFields object, and populate the value field with the name of the order, I think, unfortunately this results in a 500 error from the server...
{"proc":{"title":"(אישור הזמנה עם מפרט ללקוח (פריו","name":"ESH_WWWSHOWORDER3"},"type":"inputFields","input":{"EditFields":[{"field":1,"helpstring":"","ispassword":0,"mandatory":0,"operator":0,"readonly":0,"title":"Order","type":"text","code":"Str","value":"*","value1":"","maxlength":56,"zoom":"Zoom","format":""}],"Operators":[{"name":"= ","op":0,"title":"equals"},{"name":"< ","op":1,"title":"less than"},{"name":"<=","op":2,"title":"less than or equal to"},{"name":"> ","op":3,"title":"greater than"},{"name":">=","op":4,"title":"greater than or equal to"},{"name":"<>","op":5,"title":"not equal to"},{"name":"- ","op":6,"title":"between"},{"name":"! ","op":7,"title":"ולא"},{"name":"| ","op":8,"title":"או"}],"text":"","title":"Parameter Input"}}
2019-12-02T09:07:10.129Z info: Specifying input...
2019-12-02T09:07:10.550Z error: ###Can't connect to server. HTTP Response: 500, Internal Server Error
details: <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><s:Header><o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><u:Timestamp u:Id="_0"><u:Created>2019-12-02T09:07:07.700Z</u:Created><u:Expires>2019-12-02T09:12:07.700Z</u:Expires></u:Timestamp></o:Security></s:Header><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode><faultstring xml:lang="he-IL">Object reference not set to an instance
of an object.</faultstring><detail><ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><HelpLink i:nil="true"/><InnerException i:nil="true"/><Message>Object reference not set to an instance of an object.</Message><StackTrace> at WCFService.ProcEditFieldsOKMob(String session, Boolean save, Byte[] xml)
at SyncInvokeProcEditFieldsOKMob(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace><Type>System.NullReferenceException</Type></ExceptionDetail></detail></s:Fault></s:Body></s:Envelope>
Again, documentation does not seem to be very detailed on this topic, the EditFields object itself is not very well described...
I am also not an experienced priority user, so I am not sure where I need to navigate to check out these procedures and what else.
It seems that you are passing "R" as the second parameter, which means that you are calling for a report. Try passing "P" instead.
Also, what is customerName? according to the Web SDK I believe this should be dname: "Internal name of the company in which the procedure is run."
You can tell that WWWSHOWORDER is a Procedure and not a Report by going to System Management -> Generators -> Procedures -> Procedure Generator and querying for it. If you find it in the procedure generator - its a procedure (in this case it is a procedure which generates a report), and you should call it with a "P" parameter.
If you find the entity in Management -> Generators -> Reports-> ReportGenerator than its a plain Report and you should call it with the "R" Parameter.
I am developing web app by using Angular. When I upgrade my app to Angular7, Date function is not working. It gave me error such as
DateTime.getFullYear is not a function
It was ok before I upgraded to Angular7. In package.json:
"typescript": "^3.1.1", "#angular/cli": "~7.0.2",
"#angular/complier-cli": "~7.0.0".
What is going on?
Remember next time you post a question to paste the code relating to your error so that someone can have a look at it, since the same error can result from different code.
After upgrading my ng6 app to ng7 my DateTime.getFullYear worked fine, until I changed something about it, and it suddenly gave the same error. Everything seemed fine.
Checking my date object like below returned an object just the way it should
dateFunction(longdate) {
console.log(typeof(longDate)) // This returned 'object' which is correct
longDate.getFullYear() // Would get the same error here
}
So I tried passing in a fresh date object into the function, and not one being send via parameter like this:
dateFunction() {
longDate = new Date();
console.log(typeof(longDate)); // This returned 'object' which is correct
longDate.getFullYear(); // This worked fine now
}
And this would work fine, so I realized it is not my getFullYear() function that is wrong, but my parameter that is corrupt.
But here is the strange part, so I went to the parent component and did the same thing there - I deleted the old code and made a fresh longDate = new Date() and send it through to my function, and suddenly it was working. The exact same code, but I just re-wrote it.
Try creating a fresh date just before your function, pass it in and see if it works. If it works then it is not your function but the old date variable that is corrupt.
PS: I just feel that I have to say that you must use the new keyword (see examples above) when creating your initial date variable, or it will also throw the error...
I had a working app that uses Dexie. After upgrading to iOS 10.3, lookups by key are not working. (This is actually an indexeddb problem, not Dexie per se, I'm sure.) I'm still in shock but I have been able to confirm that the data is there by doing db.table.each(function(p) {}, and the fields used in keys are there and correct. But if I do
db.table.get(primarykey, function(p) {}
or
db.table.where("somekey").equals(nonprimarykey).first(function(p) {}
p is undefined.
I tried doing .db.table.each and then putting each retrieved object back to see if that would rebuild the keys, and it worked in Firefox, but doesn't work in Safari or Chrome (still can't retrieve by key).
I also tried specifying a new version with the same key structure and an empty upgrade, and that didn't do anything (but I only tried it in Chrome).
Everything is fine if the database is created AFTER installing 10.3 but I'm hoping that my customers won't have to delete their databases.
Is there any way to repair this without losing data?
This seems to be an upgrade bug in Safari and should really be filed on bugs.webkit.org. Assume this is something that will be fixed there as the Safari team is very responsive when it comes to critical bugs. Please file it!
As for a workaround, I would suggest to recreate the database. Copy the database to a new database, delete it, then copy back and delete the intermediate copy. I've not verified the code below, so you have to test it.
function check_and_fix_IOS_10_3_upgrade_issue () {
return (somehowCheckIfWeNeedToDoThis) ?
recreateDatabase() : Promise.resolve();
}
function recreateDatabase () {
copyDatabase("dbName", "dbName_tmp").then(()=>{
return Dexie.delete("dbName");
}).then(()=>{
return copyDatabase("dbName_tmp", "dbName");
}).then(()=>{
return Dexie.delete("dbName_tmp");
});
}
function copyDatabase(fromDbName, toDbName) {
return new Dexie(fromDbName).open().then(db => {
let schema = db.tables.reduce((schema, table) => {
schema[table.name] = [table.schema.primKey.src]
.concat(table.schema.indexes.map(idx => idx.src))
.join(',');
}, {});
let dbCopy = new Dexie(toDbName);
dbCopy.version(db.verno).stores(schema);
return dbCopy.open().then(()=>{
// dbCopy is now successfully created with same version and schema as source db.
// Now also copy the data
return Promise.all(
db.tables.map(table =>
table.toArray().then(rows => dbCopy.table(table.name).bulkAdd(rows))));
}).finally(()=>{
db.close();
dbCopy.close();
});
})
}
Regarding "somehowCheckIfWeNeedToDoThis", I can't answer exactly how to do it. Maybe user-agent sniff + cookie (set persistent cookie when fixed, so that it wont be recreated over and over). Maybe you'll find a better solution.
Then before you open your database (maybe before your app is launched) you'd need to do something like:
check_and_fix_IOS_10_3_upgrade_issue()
.then(()=>app.start())
.catch(err => {
// Display error, to user
});
I ran into the same issue, using the db.js library. All of my app data is wiped on upgrade.
Based on my tests, it looks like the 10.2 -> 10.3 upgrade is wiping any data in tables that have autoIncrement set to false. Data saved in autoIncrement=true tables is still accessible after the upgrade.
If this is the case, it's a pretty serious bug. The autoIncrement function of Safari had a host of troubles and caused a lot of us to switch to managing our own IDs instead.
I haven't tested this theory with vanilla JS yet. if someone wants to do that please add your results to the bugs.webkit.org ticket
I try to get the service metadata of a sapui5 v2 odata model.
Code:
var oModel = new sap.ui.model.odata.v2.ODataModel(someServiceURL);
var oMetadata = oModel.getServiceMetadata();
This should work according to this page:
https://openui5beta.hana.ondemand.com/docs/guide/6c47b2b39db9404582994070ec3d57a2.html
Anyhow I got "undefined" for oMetadata.
If I change code to:
var oModel = new sap.ui.model.odata.v2.ODataModel({
loadMetadataAsync : false,
serviceUrl : someServiceURL
});
Still oMetadata === undefined
According to SDK documentation metadata should be loaded in sync:
Return the metadata object. Please note that when using the model with
bLoadMetadataAsync = true then this function might return undefined
because the metadata has not been loaded yet. In this case attach to
the metadataLoaded event to get notified when the metadata is
available and then call this function.
What is wrong with my code?
I am using (1.28.11):
<script src="https://sapui5.netweaver.ondemand.com/resources/sap-ui-core.js" ...
I started debugging the UI5 code and detected following line:
this.bLoadMetadataAsync = true;
I started debugging of SAPUI5 code and detected following line (seems to be called each time):
this.bLoadMetadataAsync = true;
Is it a bug? Or is something wrong with my code?
Solution:
The following worked for me in an actual application environment. I guess it not being fired in my fiddle was due to no actual data request being made:
var oModel = new sap.ui.model.odata.v2.ODataModel(<ServiceURL>);
oModel.attachMetadataLoaded(null, function(){
var oMetadata = oModel.getServiceMetadata();
console.log(oMetadata);
},null);
Lead up to the solution:
Ok so I started playing around with this a bit and found the following:
.getServiceMetadata() worked fine with sap.ui.model.odata.ODataModel.
with the sap.ui.model.odata.v2.ODataModel the request for the metadata was sent through the network but somehow .getServiceMetadata() returned undefined.
I tried to sap.ui.model.odata.v2.ODataModel.attachMetadataLoaded() but the event was never fired. (This only applied in the jsbin I used)
I will edit this with any further findings I make. If you have anything that should be included in my findings/testing just tell me.
Edit:
The bLoadMetadataAsync is a parameter you can set on the sap.ui.model.odata.ODataModel. The parameter is not in the API for sap.ui.model.odata.v2.ODataModel anymore. I assume that the async loading has been choosen as default.
Edit:
#user3783327 Reported a bug here: https://github.com/SAP/openui5/issues/564
As sirion already mentioned, the ODataModel has now an API named metadataLoaded which returns a promise accordingly. In the resolve function, we can definitely get the service metadata via getServiceMetadata().
myODataModel.metadataLoaded()
.then(() =>/* Do something with */myODataModel.getServiceMetadata());
Alternatively, we can also make use of ODataMetaModel which can be set on any ManagedObject (including View) and provides several useful accessors related to the service metadata. In order to get the meta model, we need to use the appropriate API from the ODataModel instead of instantiating the model directly:
myODataModel.getMetaModel().loaded()
.then(() =>/* Do something with */myODataModel.getMetaModel()/*...*/);
Documentation: Meta Model for OData V2
I have read through the breeze validator information, but am not sure how to view the actual error that is occurring.
Error: client side validation errors encountered - see the entity Errors collection on this object for more detail.
I believe it's somewhere in entity.entityAspect.getValidationErrors() but am having trouble figuring out how to get the actual error out of it.
I am trying to insert a record into an entity and save changes when this error message occurs.
See :
http://www.breezejs.com/sites/all/apidocs/classes/ValidationError.html
http://www.breezejs.com/sites/all/apidocs/classes/EntityAspect.html#method_getValidationErrors
Simple example:
var errors = entity.entityAspect.getValidationErrors();
errors.forEach(function(ve) {
var errorMessage = ve.errorMessage;
var property = ve.property;
});
To get all of the errors in an EntityManager you can use
manager.getEntities().forEach(function(entity) {
var errors = entity.entityAspect.getValidationErrors();
//.. do something with the errors ..
});
You can 'catch' the errors when you try and save, like so:
manager.saveChanges()
.catch(function(error){
console.log("error catch", error, error.entityErrors);
});
Just keep in mind that any code after that will need to be in a
setTimeout(function() {}, 0);
as the catch is async.
This was you don't need to loop through all the entities in the app to find the ones with errors.