Syntax error handling in dojo 18n resource file - dojo

require(["dojo/i18n!myapp/nls/extTools_i18nStrings"],function(extTools_i18nStrings){
// Do something with the loaded file
});
If the resource file (extTools_i18nStrings) has syntax error, it will be shown in dojo.js. How can I handle it in my code?
Try catch block did not work.
Thanks in advance.
Error: Script error .............dojo.js:15

The quick answer is you don't want to. The right thing to do is fix the bundle. This is the same as having errors in your application code, and you would not expect the code to 'handle' that.
But since i18n is an AMD plugin running as part of the loader (which is why you can't try/catch it), the error might be reported through the AMD micro event API, and you could use that to show a better error. I'm not sure how you 'handle' this syntax error other than showing an error.
If you can't control the quality of the bundles via some part of your development or build process you'd have to invent your own alternative to dojo/i18n and you probably don't want to go down that route for all of your bundles.

Related

How to find my own functions in a ClojureScript error message?

I am a new ClojureScript user and I'm writing an application using Re-frame. When I get an error message (from ClojureScript), in most cases, I get a call stack ending in JavaScript code from a library. That is expected, but I don't get a function from my own code in the stack! Sometimes, I don't get any ClojureScript function calls at all, just JavaScript's. Is there a way to see the top of the stack in these error messages? Or to see the last function from my code/namespace in the stack?
That could be a huge help to me. Even small mistakes (such as, swapping operator's positions in a map call) are very hard to track. I should be doing something wrong.
It is said that ClojureScript error messages are an acquired taste. Because of the way the compiler works error messages can be cryptic.
What can help make ClojureScript error messages more readable is installing cljs-devtools or the fork Dirac. This has among other things:
The :hints feature.
The :hints feature is an attempt to augment uncaught exceptions and error object to include a bit of additional knowledge related to such errors. It tries to fetch the original source file, extract relevant part to show you more context and mark the javascript error there. This is expected to work only with :optimizations none compiler mode and it is disabled by default because it relies on monkey patching.
Better display of ClojureScript function names.
Example of nicer stack trace (from Dirac, but cljs-webtools already improves it a lot)
Installation
Enable custom formatters
Open DevTools with CMD-ALT-J
Go to Settings with F1 or by pressing the three dots
Check "Enable custom formatters" under Console
cljs-webtools
(See Installation):
Add configuration to the compiler in project.clj
{:builds
[{:id "dev"
:source-paths ["src/cljs"]
:figwheel {:on-jsload "blabla.core/reload"}
:compiler {(...)
:preloads [devtools.preload]
:external-config {:devtools/config {:features-to-install :all}}}}
Dirac
Install the Dirac Chrome extension.
Run Chrome with remote debugging enabled.
/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary \
--remote-debugging-port=9222 \
--no-first-run \
--user-data-dir=$A_PATH_TO_YOUR_USER_PROFILE_DIRECTORY
Add binaryage/dirac to dependencies in your project.clj
:dependencies [[binaryage/dirac "RELEASE"]]
(or use another one of the installation instructions).
If you use the re-frame Leiningen template the cljs-devtools are included by default

How to get Yii2 formatted error message in production systems?

When Yii2 is used in debug mode and an error occurs, it shows a error message along with call trace, session, cookie and server info.
Sample image shown below.
In production ready systems, this will not be shown. However, Is there a way to pull this formatted html into a variable in production systems, so that it can be emailed to the developer to ease in debugging errors. If any one has any idea, please let me know.
I tried using \Yii::$app->mailer->render() passing #vendor/yiisoft/yii2/views/errorHandler/exception.php as view, ['exception => $ex] as data, layout file as parameters. I'm getting undefined variable handler error.
Config Log Targets for your purpose:
http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html

Dojo console error objects empty

All of a sudden the errors that Dojo (1.8.3 from Google CDN) is spitting out empty errors, which makes debugging impossibly hard. For example, if I forget to require a dependent before using it, I get the usual
> dojo/parser::parse() error ReferenceError {}
... in the error console, but I remember getting more information in the ReferenceError (spindown arrow was present), giving me the arguments of the error as well as the message making it easy to figure out what I had done wrong.
I have isDebug : true in my dojoConfig, but it just doesn't want to tell me anything anymore.
What gives?
I've been having the same problem using Dojo 1.8.3 as well. When I close my developer tool's console and then re-open it the Error had the spindown and more details as expected. Seems stupid, but give it a try and see if that at "fixes" it for you. I planned on digging a little further into this later, so if I find any additional details I will make sure to update my answer with them.

Proper way to check system requirements for a WordPress plugin

I am curious about the proper way to stop a user from activating my plugin if their system does not meet certain requirements. Doing the checks is easy and I don't need any help with that, I am more curious how to tell WordPress to exit and display an error message.
Currently I have tried both exit($error_message) and die($error_message) in the activation hook method. While my message is displayed and the plugin is not activated, a message saying Fatal Error is also displayed (see image below).
Does anyone know of a better way, that would display my message in a proper error box without displaying Fatal error, it just looks really bad for new users to see that.
Thanks for any help in advance.
This is a little undocumented, as you might have noticed. Instead of die(), do it like this:
$plugin = dirname(__FILE__) . '/functions.php';
deactivate_plugins($plugin);
wp_die('<p>The <strong>X</strong> plugin requires version WordPress 2.8 or greater.</p>','Plugin Activation Error',array('response'=>200,'back_link'=>TRUE));
The lines above wp_die() are to deactivate this plugin. Note that we use functions.php in this case because that's where I have my Plugin Name meta data comment declaration -- and if you use a different file, then change the code above. Note that the path is very specific for a match. So, if you want to see what your path would normally be, use print_r(get_option('active_plugins'));die(); to dump that out so that you know what path you need. Since I had a plugin_code.php where the rest of my plugin code was, and since it was in the same directory as functions.php, I merely had to do dirname(__FILE__) for the proper path.
Note that the end of the wp_die() statement is important because it provides a backlink and prevents an error 500 (which is the default Apache code for wp_die()).
It is only a idea though. Try checking the wordpress version and compare then use php to through custom exception/error. PHP 5.0 try catch can be a good way to do it. Here is some resources.
http://www.w3schools.com/php/php_exception.asp
http://php.net/manual/en/internals2.opcodes.throw.php
You can try the first link. It is pretty basic. Thanks! hope the information will be helpful.

Is there a browser-agnostic way to detect client-side script errors with Watin?

We're using WatiN to test our web portals. During the course of an E2E test, we'll occasionally see client-side script errors on the IE status bar. I'd like to chain a handler onto the script error event and record the error for later analysis and bug filing.
Problem is, I don't know that there's a global script error event or how to chain into it. And if there's not a browser-agnostic way to accomplish this, I can create MyIE and MyFF subclasses but then this becomes two browser-specific questions.
In essence, I'm thinking of something like this entirely made-up call:
browser.ScriptEngine.SetCustomErrorHandler(LogScriptingError);
... where LogScriptErrors is my code that does the obvious.
Many of our client-side scripting errors don't necessarily prevent the test from continuing (a pretty UI element didn't animate, for example, but the underlying form is still submittable), so I'd like to log the error and forge ahead in most cases.
You probably looking for this:
window.onerror=function(message, url, line){logError();};
You can add this code to your pages to handle errors in logError(). but this may not work in all browser(works in IE), check this for browser compatibility:
http://www.quirksmode.org/dom/events/error.html
Or you may try this commercial product:
exceptionhub.com/
You could maybe co-opt the ability to inject eval code (described under "Added Eval functionality") to add a script that caught all errors, not just errors from the eval'ed script. I'm not sure if this would work, but it's an area to explore. Another resource might be this blog post, which discusses how to evaluate Javascript in WatiN.