Is it possible to throw warnings as errors in Ember application. I found
Ember.ENV.RAISE_ON_DEPRECATION = true
but as I understand it works only for depreciation warning.
I want to throw warnings like
"WARNING: Binding style attributes may introduce cross-site scripting vulnerabilities; please ensure that values being bound are properly escaped. For more information, including how to disable this warning, see http://emberjs.com/deprecations/v1.x/#toc_warning-when-binding-style-attributes30."
You can use Ember.Logger.warn or Ember.warn. The differences between the two is that the second in a production build, is defined as an empty function.
Ember.Logger.warnseems undocumented but you can give a look at the source code https://github.com/emberjs/ember.js/blob/master/packages/ember-console/lib/index.js#L81.
Docs for Ember.warn: http://emberjs.com/api/#method_warn
Related
I'm getting NG0100 error (Expression changed) in my console. Is there any way I can catch this error in my code and print it in the console via my code?
I tried try catch block but it doesn't seem to be working.
try{
//error generating code
}
catch(e){
console.log(e.message)
}
Thanks!
Actually, catch a NG0100 won't help that much. It's not a blocking error, it's just a big warning to tell yout that your code is unsafe and some expressions change at a point of the component genereation where it shouldn't.
It is supported by Angular DoubleCheck wich is a system that check your template binded attributes to make sure your code is stable and predictable. NG0100 means your expression has changed between these two checks.
It is just a warning because this DoubleCheck only exists in devmode (aka ng serve or ng build --configuration developement).
Best you can do is find why and where this happens in your code, to avoid it.
The informations given can't let us know, but you can watch this video from Angular official documentation that explains most common reasons of NG0100
Is it possible to track errors in polymer.js in a strategic way? Somehow I don't get any error-messages or Exceptions. In case of Errors, Polymer just does nothing if I'm doing something wrong.
For example, if I add the property disableSwipe to paper-drawer-panel, it is ignored, but there is no error-message or logging that could give me a hint what is going wrong. (I still don't know why, but this is offtopic)
Is there any way to activate some Kind of strict-mode that would cause Polymer to throw Exceptions in case of an error, or at least activate some logging that would show error-messages?
Debugging without errorMessages feels too much coincidence-based to me.
Someone else beat you to this complaint and filed an issue with Polymer.js.
https://github.com/Polymer/polymer/issues/3367
I searched through the Polymer project and there is no mention of error handling or exception handling or increased verbosity levels, and until they code something in to implement those features, you'll be left with the default javascript runtime, coding blind and with poor mans debugger.
As an alternative, the polymer.js people recommend using polylint, which won't give you information about runtime errors or exceptions, but instead a static code analysis analyzer, and it might not find your exception because your error might be some off-by-one error that static code analysis can't find.
https://github.com/PolymerLabs/polylint
That's a bad code smell and strike against Polymer.js If you can't bother to put in proper exception reporting and error handling, I can't be bothered to use your product.
The best you're going to get other than polylint is whatever the google javascript developer tools embedded in google chrome browser gives you:
https://developers.google.com/web/tools/chrome-devtools/inspect-styles/shortcuts
That will give you warnings and errors, but that's only if the polymer.js devs wrote an actual bug. If it doesn't halt on an error or warning, you're left to inspect and watch the javascript code line by line, and try to guess what went wrong by reading the Polymer.js source.
After compiling my JavaScript source with KJSCompiler (https://github.com/knyga/kjscompiler) I get this weird function wrapped around my code. If I try to include it in my live source code I get this error in the console "Uncaught ReferenceError: JSCOMPILER_PRESERVE is not defined ".
I thought that this problem occurred because I didn't add the "wrapper" in the JSON file of kjscompiler. After trying that it still occurs.
Does anyone have an idea how to fix this?
I came across this when using Closure Compiler directly via the Java API.
It seems to be caused by running the compiler in checks-only mode but with protect hidden side effects enabled. The late pass to remove protection of hidden side effects is skipped in checks-only mode.
I'm not sure about KJSCompiler specifically, but it might help to look at changing the compilation level to SIMPLE or ADVANCED, and/or how you might be able to control what checks and optimisations run to KJSCompiler, e.g. turning off CompilerOptions.protectHiddenSideEffects.
See https://github.com/google/closure-compiler/issues/1875
In addition to Steve S's answer:
set protectHiddenSideEffects after setting optimization level, as options.setProtectHiddenSideEffects(false); didn't work for me for GCC version v20180204 if I set it before setting CompilationLevel.
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(compilerOptions);
//To remove JSCOMPILER_PRESERVE error: https://github.com/google/closure-compiler/issues/1875
compilerOptions.setProtectHiddenSideEffects(false);
tl;dr When there is an error with a test written in intern I don't seem to get error messages that describe on which line the error occurred. I've found a workaround but its not really the ideal solution as it involves messing with code in dependent projects. Does any one have a better way / am I just doing it wrong? Thanks!
Details :
I've seen several times that when there is an issue with parsing a test written in intern (for example failing to close brackets, quotes etc.) that the actual line where the error occurred is not reported, and there is only an error like this (I've subbed in for the actual path as its a work project, but you get the gist):
SyntaxError: Unexpected identifier
at Function.vm.runInThisContext (<myproject>/node_modules/intern/node_modules/istanbul/lib/hook.js:163:16)
at <myproject>/node_modules/intern/node_modules/dojo/dojo.js:745:8
at fs.js:266:14
at Object.oncomplete (fs.js:107:15)
I poked around a little and discovered that there's an undocumented(? - its not in here) parameter for vm.runInThisContext, which if enabled actually provides details of the original error (here and here) - there's some discussion about how this will play out but if I switch dojo.js and hook.js in istanbul (if its running) to use this parameter, I get error messages like this :
<myproject>/test/publisherConfigSpec.js:16
errorCb cat = dfd.rejectOnError(function(error) {
^^^
SyntaxError: Unexpected identifier
at Function.vm.runInThisContext (<myproject>/node_modules/intern/node_modules/istanbul/lib/hook.js:163:16)
at <myproject>/node_modules/intern/node_modules/dojo/dojo.js:745:8
at fs.js:266:14
at Object.oncomplete (fs.js:107:15)
which is the output I want (or at least massively improves my chances of finding and fixing the error) but its not ideal to be messing about with the node dependencies, and it seems to me that it may be too much in flux for a pull request (see most recent update to the API) Is there an alternative way of getting useful output when there's an error parsing the test code input?
Thanks for any advice :)
The output that Node.js provides for SyntaxError is obviously not great, but we probably won’t use undocumented features (they’re undocumented for a reason!) in any official release of Intern to make it work differently. Non-syntax errors (runtime errors) will be caught and reported competently by Intern to whatever reporters you are using.
In this case, I’d advise you to use an editor that includes support for syntax checking: Komodo Edit/IDE, WebStorm, SublimeText, Eclipse, vim… if you get to the point where you are trying to run syntactically invalid code, your code editor is failing you by not telling you soon enough that you’ve made a mistake.
I am in the process of ironing out my codebase so it can compile with ADVANCED_OPTIMIZATIONS on google's closure compiler.
After properly setting up the debugging environment required for this task (source map file, chrome, wrapping the compiled js file) i stumbled upon try catch issues. It appears that extensive use of try/catch statements in my codebase has backfired on me.
On almost all methods and functions i use a typical try { } catch(e) {ss.error(e);} statement, where ss.error() is a generic error handler that depending on environment either prints out debug stuff or reports back the exceptions...
In the process of ironing my codebase, when i get an error that i need to fix, what happens is that instead of having Chrome report the offending file and line, it points to the error handler ss.error(). Thus leaving me with no way of backtracing the problem. The ss.error() func however, does print where the problem originated from:
Error! type:TypeError at Db (/jsc/compiled.js:547:246) msg:Cannot call
method 'ka' of undefined source:
After i get these type of errors i have to do two steps:
1. Fiddle with the compiled code at line 547 char 246 and try to figure out which part in my uncompiled code this refers to...
2. After i locate it, remove the try/catch blocks so i can directly and more clearly see what caused the error...
I must say i am not happy with this workflow and need to find an alternative that will both allow me to properly catch exceptions and debug my compiled and uncompiled code while retaining mind sanity =)
I was thinking of somehow using the Line:CharPosition info to query the source map and have the ss.error() function do the mapping to my uncompiled source code...
ideas?
There is a java interface to the SourceMaps as part of the closure compiler. There are also JS implementations in various states of repair. I try to keep links to them up to date here:
http://code.google.com/p/closure-compiler/wiki/SourceMaps
For the Java implementation you simply load the source map using the SourceMapConsumerFactory, the interface is pretty simple.