How to display the error path of where the custom function is used? - css

If I use a built-in Sass function that returns an error, it will display the path of where it is used.
Using a built-in Sass function:
Code from _test.scss.
.foo {
color: darken(blue, s);
}
Will result in:
error _test.scss (Line 2: $amount: "s" is not a number for `darken')
Now, if I use a custom function that returns an error, it will display the path of where it is defined instead of where it is used.
Using a custom function:
Code from _test.scss.
.foo {
color: example(string);
}
Code from _functions.scss.
#function example($string) {
#error 'error message';
}
Will result in:
error core/utils/_functions.scss (Line 2: error message)
Is there any solution for solving this "issue"?

Your examples are similar only visually, underlying logic is completely different:
For built-in function Sass throws error by itself because code is not valid from Sass point of view.
Into second example you're throwing error because code is not valid from your point of view. Code itself if valid from Sass point of view in this case.
In both cases Sass displays same information about error location - a point into your codebase where error occurs. But in a case of your own, intentional error throwing actual point where error occurs actually matches a place where you're generating this error - exactly at a place where you have your #error directive. So there is no mistake into Sass behavior because it knows nothing about reasons why did you decide to throw an error.
You can always analyze stack trace that is displayed (at least by node-sass) along with error message to decide where did you get to point of error from. You can also use #debug to display context that may be useful for error analysis.

Related

Multiple classes in a single file leads to overload warnings

I've recently started playing around with the closure compiler and ES6, and I've noticed something that I think is a bit strange. When I compile the following code:
export class Test
{
constructor(arg)
{
this.arg = arg;
}
}
class Test2
{
constructor(diffArg)
{
this.diffArg = diffArg;
}
}
I get this output when I compile with ADVANCED:
java -jar closure-compiler-v20170910.jar --compilation_level ADVANCED --language_in ECMASCRIPT6_TYPED --language_out ECMASCRIPT5 --js_output_file ui.js --js javascript/*.js --externs javascript/externs/externs.js --jscomp_off missingProperties
Test.js:11: WARNING - Function and method overloads are not supported and type information might be lost
constructor(diffArg)
^^^^^^^^^^^^^^^^^^^^^^
Test.js:5: ERROR - variable arg is undeclared
this.arg = arg;
^^^
It looks like the compiler is complaining because there are two functions with the same name in the file - even though they are in different classes - and the error comes in because the second function replaces the first. If I compile with SIMPLE, I get the warning but not the error, and the emitted code seems to contain the second constructor definition. To get the code to compile properly, I need to put each class into its own file.
My question is whether this is expected behavior or not - I don't believe that there is anything in the ES6 spec about only having one class per file, and since each function is in a different class, I would have expected that I can use the same name for each of them (especially for the constructor). Is there a way to get around this, or is having each class in its own file the right way to go?

Qt error is printed on the console; how to see where it originates from?

I'm getting this on the console in a QML app:
QFont::setPointSizeF: Point size <= 0 (0.000000), must be greater than 0
The app is not crashing so I can't use the debugger to get a backtrace for the exception. How do I see where the error originates from?
If you know the function the warning occurs in (in this case, QFont::setPointSizeF()), you can put a breakpoint there. Following the stack trace will lead you to the code that calls that function.
If the warning doesn't include the name of the function and you have the source code available, use git grep with part of the warning to get an idea of where it comes from. This approach can be a bit of trial and error, as the code may span more than one line, etc, and so you might have to try different parts of the string.
If the warning doesn't include the name of the function, you don't have the source code available and/or you don't like the previous approach, use the QT_MESSAGE_PATTERN environment variable:
QT_MESSAGE_PATTERN="%{function}: %{message}"
For the full list of variables at your disposal, see the qSetMessagePattern() docs:
%{appname} - QCoreApplication::applicationName()
%{category} - Logging category
%{file} - Path to source file
%{function} - Function
%{line} - Line in source file
%{message} - The actual message
%{pid} - QCoreApplication::applicationPid()
%{threadid} - The system-wide ID of current thread (if it can be obtained)
%{qthreadptr} - A pointer to the current QThread (result of QThread::currentThread())
%{type} - "debug", "warning", "critical" or "fatal"
%{time process} - time of the message, in seconds since the process started (the token "process" is literal)
%{time boot} - the time of the message, in seconds since the system boot if that can be determined (the token "boot" is literal). If the time since boot could not be obtained, the output is indeterminate (see QElapsedTimer::msecsSinceReference()).
%{time [format]} - system time when the message occurred, formatted by passing the format to QDateTime::toString(). If the format is not specified, the format of Qt::ISODate is used.
%{backtrace [depth=N] [separator="..."]} - A backtrace with the number of frames specified by the optional depth parameter (defaults to 5), and separated by the optional separator parameter (defaults to "|"). This expansion is available only on some platforms (currently only platfoms using glibc). Names are only known for exported functions. If you want to see the name of every function in your application, use QMAKE_LFLAGS += -rdynamic. When reading backtraces, take into account that frames might be missing due to inlining or tail call optimization.
On an unrelated note, the %{time [format]} placeholder is quite useful to quickly "profile" code by qDebug()ing before and after it.
I think you can use qInstallMessageHandler (Qt5) or qInstallMsgHandler (Qt4) to specify a callback which will intercept all qDebug() / qInfo() / etc. messages (example code is in the link). Then you can just add a breakpoint in this callback function and get a nice callstack.
Aside from the obvious, searching your code for calls to setPointSize[F], you can try the following depending on your environment (which you didn't disclose):
If you have the debugging symbols of the Qt libs installed and are using a decent debugger, you can set a conditional breakpoint on the first line in QFont::setPointSizeF() with the condition set to pointSize <= 0. Even if conditional breakpoints don't work you should still be able to set one and step through every call until you've found the culprit.
On Linux there's the tool ltrace which displays all calls of a binary into shared libs, and I suppose there's something similar in the M$ VS toolbox. You can grep the output for calls to setPointSize directly, but of course this won't work for calls within the lib itself (which I guess could be the case when it handles the QML internally).

Unexpected token ILLEGAL in concatenated CSS file

I'm getting the following error in the Chrome console:
Uncaught SyntaxError: Unexpected token ILLEGAL
At the start of my concatenated CSS file:
#import url("http://fonts.googleapis.com/css?family=Raleway:300,400,600")
This line ends up on its own, and it's specifically this line that throws the error:
I've had a look around and it seems this error should relate to invisible characters making their way into the code. Unfortunately in my case that doesn't seem to be true. I've even deleted this portion of code and re-written it by hand to make sure - no difference.
I use Stylus (with gulp) and the resulting compile is naturally what throws the error - is this maybe an issue with gulp-stylus? I've looked at the compiled code and can't track down any invisible characters there either…
Does anything else throw this error?
The error implies you are trying to load the style sheet with <script> instead of <link rel=stylesheet>.
CSS is not JavaScript and can't be treated as such.

Warning whitelist doesn't work in Google closure compiler

The manual says I can use:
--warnings_whitelist_file VAL : A file containing warnings to
suppress. Each line should be of the
form
<file-name>:<line-number>? <warning-d
escription>
This is what my whitelist looks like:
ef-utils.js:1 Redeclared variable: ef
ef-utils.js:1 Variable ef first declared in externs-ko.js
ef-validation.js:1 Redeclared variable: ef
ef-validation.js:1 Variable ef first declared in externs-ko.js
And I am still getting warnings while compiling:
ef-utils.js:1: WARNING - Redeclared variable: ef
?var ef = (function (ns, ko) {
^
ef-utils.js:1: WARNING - Variable ef first declared in externs-ko.js
?var ef = (function (ns, ko) {
^
ef-validation.js:1: WARNING - Redeclared variable: ef
?var ef = (function (ns, ko) {
^
ef-validation.js:1: WARNING - Variable ef first declared in externs-ko.js
?var ef = (function (ns, ko) {
^
I just toyed around with the current WhitelistWarningsGuard. I found out that
Line numbers are completely ignored: they are stripped both from the input file and the encountered warnings.
File names are formatted as they are for output, i.e. as they occur on the command line.
There is a colon after the file name, followed by two spaces, followed by the message text without indicator of the severity (WARNING, ERROR).
The main effect of the whitelist appears to be turning errors into warnings. So when applied to warnings, there will be no effect at all.
The WhitelistBuilder mentioned by Tibos is there in the code, but I see no way to use it from the command line.
As it is, that feature appears to be mostly useless for my use cases…
You should use the WhitelistBuilder to build the whitelist file. From the looks of it, you need absolute paths to the files, not relative.
As MvG correctly stated as this flag is implemented it's useless. Though, with pretty light changes to the compiler's code it can be turned to what we all expect from it: suppressing errors and warnings we don't want to see.
See details here: Suppressing or resolving compiler errors in goog.base

google Closure Compiler reports: JSC_TRAILING_COMMA

Im using google Closure Compiler to compress my js, anyhow I get the following error message:
JSC_TRAILING_COMMA: Parse error. Internet Explorer has a non-standard intepretation of trailing commas. Arrays will have the wrong length and objects will not parse at all. at line 8698 character 5 in post-login.js
];
The error is in the first line of this code, but I could not figure out whats wrong with it...
var plot = $.jqplot('usst_points_last_10_days', [data], {
title: '<h3 class="startGrafHeadline">' + global_language['discriptive']['usst']['visits_in_detail'] + '</h3>',
seriesColors: ["#00FF00"],
series: [{renderer:$.jqplot.BarRenderer}],
axesDefaults: {
tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
tickOptions: {
angle: -30,
fontSize: '10pt'
}
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer
}
}
});
Try looking at the line just before the line that the compiler is complaining about. This will be the last line is some other file, perhaps.
If you examine your command line or build script, that will lead you to the answer. It seems likely that you are compiling multiple files or are pre-concatenating many files before compilation. What closure compiler is telling you is to look at line 8698.
If you have some logical explanation about why you think the error is contained in this code, please let us know your reasoning.
If you post more information, I may be able to improve this answer.
There is a handy tool for using closure-compiler through a web UI that may help you convince yourself that you have not found the offending line:
http://closure-compiler.appspot.com

Resources