I would like to get an alert when errors occur when loading my jqGrid table. For instance, when the jsonReader is not well configured, like when repeatitems is true instead of false, U can see in Firebug the error:
ccur is undefined
[Break On This Error] idr = ccur[idn] || idr;
How can I place such an error in an alert? I have already tried using loadError, but it doesn't work, because it is not even triggered.
It seems for me that you should just use try - catch block over jqGrid code:
try {
// create the grid
$("#list").jqGrid({
// all jqGrid options
});
} catch (err) {
// display the error message which you want
alert(err);
}
UPDATED: You are right, the try {...} catch (err) {...} which I described before work in IE only with reading local data. In case of getting data from the server the exception take place inside of success callback of $.ajax. To be exactly it take place inside of addJSONData or addXmlData depend of the type of data which you use. To catch the exception you should modify code of jqGrid in the place. The modified code can be about the following
success:function(data,st, xhr) {
if ($.isFunction(ts.p.beforeProcessing)) {
ts.p.beforeProcessing.call(ts, data, st, xhr);
}
try {
if(dt === "xml") { addXmlData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
else { addJSONData(data,ts.grid.bDiv,rcnt,npage>1,adjust); }
if(lc) { lc.call(ts,data); }
if (pvis) { ts.grid.populateVisible(); }
} catch (err) {
alert(err);
}
if( ts.p.loadonce || ts.p.treeGrid) {ts.p.datatype = "local";}
data=null;
if (npage === 1) { endReq(); }
}
I tested in the demo the corresponding modified version of jquery.jqGrid.src.js which display error message. I don't reproduced exactly the error which you described so the error message is a little other as in your case.
If you need minimized version of the modified jquery.jqGrid.src.js file you can produce it yourself with any JavaScript minimizer. For example Microsoft Ajax Minifier can be free downloaded and installed. The usage as
ajaxmin.exe jquery.jqGrid.src.js -out jquery.jqGrid.min.js
will produce the new minimized version of jquery.jqGrid.src.js which will be even a little smaller as the original jquery.jqGrid.min.js.
Another good minimizer is available online here. You should use "Simple" Optimization only.
Related
Development Environment OS: Windows 7 Enterprise LTS
Browser compatibility minimum requirements: Should support all Edge, Firefox, Chrome browsers, as of 2018.
Current ongoing issue: Unable to run VM on dev workstation; Cannot run Windows 10 VMs to debug Microsoft Edge extensions.
To explain:
An "all-in-one browser extension" refers to a browser extension code that uses the same code with minor differences to work on various WebExtensions / Chrome Extensions supported browsers. At bare minimum, the same codebase should work and run on Edge, Firefox, and Chrome with very minor changes.
Callbacks on the content scripts for Edge/Firefox/Chrome extensions are handled differently.
For unknown reasons, I cannot run VM on my workstation machine. When VM is running, VM client is black. This is a localized issue on my end that I cannot resolve, so I'm forced to find a different solution/alternative.
How are they handled differently on the content scripts:
Edge: browser.runtime.sendMessage uses callbacks, and returns undefined.
Firefox: browser.runtime.sendMessage uses Promises, and returns a Promise.
Chrome: chrome.runtime.sendMessage uses callbacks, and returns undefined.
According to various references:
Firefox / Chrome / MS Edge extensions using chrome.* or browser.*
https://www.smashingmagazine.com/2017/04/browser-extension-edge-chrome-firefox-opera-brave-vivaldi/
On the content scripts, you can declare the following JavaScript snippet at the top in order to create a global variable that can be referenced everywhere else:
//Global "browser" namespace definition.
window.browser = (function() {
return window.msBrowser || window.browser || window.chrome;
})();
Unfortunately, because of the issue I'm experiencing (VM not running), I cannot tell if window.msBrowser is still being used. And this solution is not helpful for me when handling message callbacks when using namespace.runtime.sendMessage.
With all that said, my main question is: How to write a message passing function that can handle callbacks properly?
Currently, I'm using the following code:
function sendGlobalMessage(messageRequest, callback) {
if (chrome && window.openDatabase) {
//This is Chrome browser
chrome.runtime.sendMessage(messageRequest, callback);
}
else if (browser) {
try {
//Edge will error out because of a quirk in Edge IndexedDB implementation.
//See https://gist.github.com/nolanlawson/a841ee23436410f37168
let db = window.indexedDB.open("edge", (Math.pow(2, 30) + 1));
db.onerror = function(e) {
throw new Error("edge is found");
};
db.onsuccess = function(e) {
//This is Firefox browser.
browser.runtime.sendMessage(messageRequest).then(callback);
};
}
catch (e) {
//This is Edge browser
browser.runtime.sendMessage(messageRequest, callback);
}
}
}
I truly felt this is a hacky solution, because the code is based off of browser platform exclusive quirks in order to separate chrome.runtime.sendMessage and browser.runtime.sendMessage API calls, so as to handle callbacks in their respective platforms. I really wanted to change this.
So I'm asking what better ways are there, out there, that is useful to detect the different platforms, and handle message passing callbacks properly at the same time?
Thanks in advance.
I believed I solved it.
EDIT: The FINAL final version (updated and more stable, less message passing):
//Global "browser" namespace definition, defined as "namespace". Can be renamed to anything else.
window.namespace = (function() {
return window.browser || window.chrome;
})();
function sendGlobalResponse(message, callback){
if (window.namespace === window.chrome) {
//Chrome
window.namespace.runtime.sendMessage(message, callback);
}
else if (window.namespace === window.browser) {
//Using instanceof to check for object type, and use the returned evaluation as a truthy value.
let supportPromises = false;
try {
supportPromises = window.namespace.runtime.getPlatformInfo() instanceof Promise;
}
catch(e) { }
if (supportPromises){
//Firefox
window.namespace.runtime.sendMessage(message).then(callback);
}
else {
//Edge
window.namespace.runtime.sendMessage(message, callback);
}
}
}
(Original Post):
The final version (Now obsoleted):
//Global "browser" namespace definition.
window.namespace = (function() {
return window.browser || window.chrome;
})();
function sendGlobalResponse(message, callback){
if (window.namespace === window.chrome) {
//Chrome
window.namespace.runtime.sendMessage(message, callback);
}
else if (window.namespace === window.browser) {
let returnValue = window.namespace.runtime.sendMessage({});
if (typeof returnValue === "undefined"){
//Edge
window.namespace.runtime.sendMessage(message, callback);
}
else {
//Firefox
window.namespace.runtime.sendMessage(message).then(callback);
}
}
}
In the second if statement, by checking to see if the return value of a window.browser.runtime.sendMessage is a Promise or undefined, we can detect if the platform is Firefox or Edge.
I think this is the only solution to handle message passing callbacks/message responses on the content scripts.
I really couldn't think of a better solution than this. So I'll be using this from now on.
But if anyone else knows a better way, a way where you don't need to send out 1 extra dummy message for Firefox and Edge per function call, that would be great!
It sucks that anything inside the content script is not persistent, and even if you store information about what platform the code is being run on, you still have to fetch the information from the background script before filtering out which runtime.sendMessage function to call on, so it doesn't really save much time.
I been trying to clear display of all errors onload but those errors should display on further action after load .
I got solution for this but i felt it can been done in a better way
Working solution: This will clear onload messages
ko.utils.arrayForEach(self.MAIN(), function (s) {
ko.utils.arrayForEach(s.STData(), function (s1) {
ko.utils.arrayForEach(s1.SData(), function (s2) {
if (s2.Validation.errors().length > 0) {
s2.Validation.errors.showAllMessages(false);
}
});
});
});
Tried usign group but stuck with error i.e
object doesn't support property or method 'ismodified' in knokcout validation .
Not working :
var result= ko.validation.group(self.MAIN(), { deep: true });
if (!self.MAIN().isValid()) { // rightly i am getting isvalid false and also showing my error text under it .
result.showAllMessages(false); // error at this line as metioned above.
return true;
}
Additional code :
function data(){
var inner = this;
self.name=ko.observable(""); // i have many observables
self.validation = ko.validatedObservable([
self.name.extend({required true, //custom validations also written})
]);
}
But i have this function in observable array which is deeper in self.MAIN
My levels : function data object is pushed into self.SData observable array later this one is pushed into self.STData and finally i pushed this one into 'self.MAIN' .
So you can clearly see i am trying to clear messages onLoad but i get that error . Actually in the mean time i went into validation script file i found i am getting error at this line
ko.utils.arrayForEach(validatables(), function (observable) {
observable.isModified(show); // here isModified is undefined
});
Any suggestions are appreciated .
I have such a Js injected in webView:decidePolicyForNavigationResponse:decisionHandler:
function postMyMessage()
{
try {
window.webkit.messageHandlers.SimpleBrowser.postMessage('JS for qq.com called');
} catch(err) {
alert('The native context does not exist yet ' + err);
}
}
postMyMessage()
implementing the delegate like this
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
{
NSLog(#"Message: %#", message.body);
}
The problem is this log only show once, never come out after, even through load another WKWebView.
I got this err msg when NOT receiving the message log.
alert The native context does not exist yet TypeError: null is not an object (evaluating 'window.webkit.messageHandlers')
Is is a bug? any solution now?
Using CasperJS how do I catch and handle CasperError?
The default appears to continue execution of the program (which does nothing but propagates the error).
These errors are logged to the console/stdout but I don't seem to see a way (from the docs) to catch and handle these errors.
Example:
this.fillSelectors(selector, data);
May produce:
CasperError: Errors encountered while filling form: form not found
I know I can check to make sure everything exists before calling, but is there a way to catch after the fact? (this applies to many other operations like casper.click as well)
I use something currently like this:
casper.on('error', function(msg,backtrace) {
this.capture('./out/error.png');
throw new ErrorFunc("fatal","error","filename",backtrace,msg);
});
and then I have a custom function ErrorFunc to process array of any warnings or a fatal error.
If you have an unsuccessful click it should throw the casper.on('error'). So you can put custom code there for how you would like to handle the error.
Here's the documentation for Casper events.
var casper = require('casper').create({
onError: function(msg, backtrace) {
this.capture('error.png');
throw new ErrorFunc("fatal","error","filename",backtrace,msg);
}
});
This works pretty well.
(See http://docs.casperjs.org/en/latest/modules/casper.html#index-1)
This is the complete solution for who need it ^^
casper.on('error', function(msg, backtrace) {
this.capture('/tmp/error.png');
console.log('backtrace: ' + JSON.stringify(backtrace, null, 4));
console.log('message: ' + JSON.stringify(msg, null, 4));
console.log('check capture in /tmp/error.png');
casper.exit(1);
})
I have a simple ExtJs (3.4) Grid with a Writer. When the user makes some changes the store is saved to the server as follows:
store.on('save', afterSave(resp));
All is fine. However, I want to get a response as to wheather the record has been saved successfully, failed or an update conflict happed. How to best do this?
Are you using Ext.data.proxy.Ajax to load your stores? If so, you can use the reader property to evaluate and handle the server responses.
Another option would be to make AJAX called directly and handle the responses from there as well
I used exception listener to parse the data as suggested here. But, is this the right way to do this.
Ext.data.DataProxy.addListener('exception', function(proxy, type, action,
options, res) {
if (type == 'response') {
var success = Ext.util.JSON.decode(res.responseText).success;
if (success) {
console.log('UPDATE OK');
} else {
console.log('UPDATE FAILED');
}
}
});