PDA

View Full Version : [FIXED][3.??] Ext.Direct "exception" event raises "tid has no properties" error



j.bruni
22 Jun 2009, 7:31 AM
I am using a Ext.data.DirectStore to get data from server.

I am dealing with a "tid has no properties" error at ext-all-debug.js line 13944 (using ExtJS 3 RC 2)

This happens when the server response is not parsable (in my case, PHP code generated an error, and instead of the beauty JSON, the response is PHP's error messages)

I found that the Ext.data.JsonProvider is creating the Ext.Direct.ExceptionEvent (see code below from ext-all-debug.js line 14057)



/**
* @class Ext.direct.JsonProvider
* @extends Ext.direct.Provider
*/
Ext.direct.JsonProvider = Ext.extend(Ext.direct.Provider, {
parseResponse: function(xhr){
if(!Ext.isEmpty(xhr.responseText)){
if(typeof xhr.responseText == 'object'){
return xhr.responseText;
}
return Ext.decode(xhr.responseText);
}
return null;
},

getEvents: function(xhr){
var data = null;
try{
data = this.parseResponse(xhr);
}catch(e){
var event = new Ext.Direct.ExceptionEvent({
data: e,
xhr: xhr,
code: Ext.Direct.exceptions.PARSE,
message: 'Error parsing json response: \n\n ' + data
})
return [event];
}
var events = [];
if(Ext.isArray(data)){
for(var i = 0, len = data.length; i < len; i++){
events.push(Ext.Direct.createEvent(data[i]));
}
}else{
events.push(Ext.Direct.createEvent(data));
}
return events;
}
});
But at its subclass Ext.Direct.RemotingProvider onData method, we have a call to the event's "getTransaction" method (see code below from ext-all-debug.js line 14242)


onData: function(opt, success, xhr){
if(success){
var events = this.getEvents(xhr);
for(var i = 0, len = events.length; i < len; i++){
var e = events[i];
var t = e.getTransaction();
this.fireEvent('data', this, e);
if(t){
this.doCallback(t, e, true);
Ext.Direct.removeTransaction(t);
}
}

But the event has no "transaction" nor "tid" set, thus generating the error.

What shall I do?

Thanks!

j.bruni
22 Jun 2009, 9:28 AM
Ok, I just did a small adjustment and everything runs fine now.



onData: function(opt, success, xhr){
if(success){
var events = this.getEvents(xhr);
for(var i = 0, len = events.length; i < len; i++){
var e = events[i];
var t = e.getTransaction();
var t = this.getTransaction(e);
this.fireEvent('data', this, e);
if(t){
this.doCallback(t, e, true);
Ext.Direct.removeTransaction(t);
}
}


This is code from Ext.data.RemotingProvider onData method (ext-all-debug.js line 14242)

j.bruni
22 Jun 2009, 9:32 AM
Well... the only issue now is that I can't change other people's ExtJS source code...

How can this correction be commited to the SVN?
(Although I believe this was probably already done...)

Who may I contact or request? Is this the correct Forum to ask for this? Who is the boss here? :)

Thanks!

stever
22 Jun 2009, 2:48 PM
Thanks!

evant
22 Jun 2009, 7:14 PM
This hay have already been resolved, please post a test case that demonstrates the issue.

j.bruni
22 Jun 2009, 7:42 PM
As suggested, I am providing the following code as a test case:



Ext.app.REMOTING_API = {
'url': 'router.txt',
'type': 'remoting',
'actions': { 'remoteStore': [{"name":"load","len":2}] }
};

Ext.Direct.addProvider( Ext.app.REMOTING_API );

var grid = {
xtype: 'editorgrid',
title: 'Nice Editor Grid',
frame: true,
store: {
xtype: 'directstore',
storeId: 'niceStore',
// proxy
paramOrder: [ 'sort', 'dir' ],
paramsAsHash: false,
directFn: remoteStore.load,
// reader
totalProperty: 'total',
root: 'rows',
idProperty: 'id',
fields: [ 'user_id', 'user_name' ],
// store
remoteSort: true,
sortInfo: {
field: 'user_name',
direction: 'ASC'
}
},
columns: [
{ header: 'User ID', dataIndex: 'user_id' , sortable: false, menuDisabled: true },
{ header: 'User Name', dataIndex: 'user_name', sortable: false, menuDisabled: true }
],
tbar: [{
xtype: 'tbbutton',
text: 'Ext.StoreMgr.get(\'niceStore\').load();',
handler: function() {
Ext.StoreMgr.get('niceStore').load();
}
}]
};

// below, we are setting an event handler for ExceptionEvent
// to display an alert showing some exception's details
Ext.Direct.on( 'exception', function(e) {
Ext.Msg.alert( 'Failure' ,
'e.code: ' + e.code + '<br><br>' +
'e.message: ' + e.message + '<br><br>' +
'e.xhr.responseText: ' + e.xhr.responseText
);
});

function doLayout() {
new Ext.Viewport({
layout: 'fit',
items: grid
});
}

Ext.onReady( doLayout );
If you run the above code in ExtJS 3 RC 2, you will see a button in a top toolbar.
Click it to run the code in red. It calls the DirectStore "load" method:


Ext.StoreMgr.get('niceStore').load();
What happens?


It depends on our server response.
In this test case, we configured the remoting API with a a "fake" server-side router: router.txt
We have three possibilities:

1) There is no "router.txt" (404 error)
The alert window is displayed, with the exception's details. :)
No problem here.

2) "router.txt" containing proper JSON response - for example:


{"type":"rpc","tid":2,"action":"remoteStore","method":"load","result":{"id":"user_id","total":3,"success"
:true,"rows":[{"user_id":3,"user_name":"Asterix"},{"user_id":1,"user_name":"Felix, the Cat"},{"user_id"
:2,"user_name":"Garfield"}]}}The grid will be populated with the response's data. Success! :D
No problem here.

3) "router.txt" containing not-JSON response - for example:


not a JSON stringHere is the problem! In this case... sometimes nothing will happen at all. No exceptions. No errors. No data. No alert. This is not bad. A response with NO data... nothing loaded in the store... nothing to display in the grid. That's ok, but... /:)

...sometimes you will got a "tid has no properties" error at ext-all-debug.js line 13944 !!! :-?

So, that's why I have put a button in the toolbar to call the Store's load method.
Maybe you will got the error in the first click/call. Maybe in the second or third...


What was expected?


Instead of "tid has no properties" error, I'd like to see the alert containing the exception's details.

This is exactly what happens after changing the code as suggested in the previous post! =D>

Thanks for your attention! :)

j.bruni
22 Jun 2009, 7:56 PM
FYI...

OS: Linux Mandriva 2008.0
Browser: Firefox 2.0.0.18 with Firebug 1.3.1
Server: Apache 2.2.6 (localhost)

evant
22 Jun 2009, 8:14 PM
Thanks for the detailed test case. Your fix has been committed to SVN.

j.bruni
22 Jun 2009, 8:56 PM
Great! Thanks!

I look forward to the ExtJS 3 release! Congratulations for the hard and good work! =D>