It's not always obvious from stack trace where error occurred.
So, maybe it's not meaningless to log where error has been thrown.
throw new Error(ErrorsMessagesBuilder.buildErrorMessage({
errorType: ErrorsMessagesBuilder.ErrorsTypes.invalidParameterValue,
functionInvocationExpression: function.name,
description: `Tasks set: '${targetTagsSetID}' is not defined in config file.`
}));
Unfortunately, function.name will be lost because of Webpack code minification. Does Webpack suggest some solutions for it?
Related
I recently started using the eslint module to help clean-up some JavaScript files. The following error is being reported when I lint one of my files:
127:17 error Unexpected alias 'me' for 'this' consistent-this
After checking the documentation, I understand the error is being reported because my code is assigning the value of this to a variable named me instead of that.
What is the proper way to configure my project's .eslintrc.json to make it so the following line of code is not reported as an error: var me = this;?
The rule should be like this in your .eslintrc
{
"rules" : {
"consistent-this": ["error", "me"]
}
}
I am trying to integrate the stackdriver-error-js library into my Vue project as a module.
The code and the setup:
in package.json
"stackdriver-errors-js": "^0.2.0"
in bootstrap.js
import errorHandler from './error/error-reporting';
in error-reporting.js
import { StackdriverErrorReporter } from 'stackdriver-errors-js';
let errorHandler;
errorHandler = new StackdriverErrorReporter();
errorHandler.start({
key: "{{.Config.StackDriverApiKey}}",
projectId: "{{.Config.StackDriverProject}}",
service: "{{.Config.GoogleCloudProjectID}}",
version: "{{.Copacknfig.GaeEnv}}",
disabled: false
});
export default errorHandler;
The actual error
The error I got now is (console output and test)
[vue-devtools] Ready. Detected Vue v2.4.2
(function testErrorReporting() {window.onerror(null, null, null, null, new Error('Test: Something broke!'));})();
stackdriver-errors.js:109 Uncaught ReferenceError: StackTrace is not defined
at StackdriverErrorReporter.webpackJsonp.556.StackdriverErrorReporter.report (stackdriver-errors.js:109)
at window.onerror (stackdriver-errors.js:67)
at testErrorReporting (<anonymous>:1:40)
at <anonymous>:1:111
and line (stackdriver-errors.js:109)
...
StackTrace.fromError(err).then(function(stack){
...
If you do not load the stackdriver-errors-concat.min.js file, you also manually need to also the stacktrace-js module.
stackdriver-errors expects a StackTrace object to be present.
Since the library you want to use is experimental, and therefore cannot be used in a production environment, it would be better to use a different library which has been tested and validated for production use.
I suggest using this other library instead, which includes features related to Stackdriver error reporting for Node.js and JavaScript.
First of all, install the dependency by running this command:
npm install --save #google-cloud/error-reporting
This will add the dependency automatically to package.json.
In error-reporting.js, you can add the dependencyby adding this to your code (All the parameters are optional):
var errors = require('#google-cloud/error-reporting')({
projectId: 'my-project-id',
keyFilename: '/path/to/keyfile.json',
credentials: require('./path/to/keyfile.json'),
// if true library will attempt to report errors to the service regardless
// of the value of NODE_ENV
// defaults to false
ignoreEnvironmentCheck: false,
// determines the logging level internal to the library; levels range 0-5
// where 0 indicates no logs should be reported and 5 indicates all logs
// should be reported
// defaults to 2 (warnings)
logLevel: 2,
// determines whether or not unhandled rejections are reported to the
// error-reporting console
reportUnhandledRejections: true,
serviceContext: {
service: 'my-service',
version: 'my-service-version'
}
});
After that, use this code to test if the error is properly reported by Stackdriver:
errors.report(new Error('Something broke!'));
Please be aware that this library is currently on a beta stage, so there might be some changes to it in the future.
I have a webpack-dev-server running that compiles and serves some Babel/React code. I have gotten as far as to have it serve the compiled client.js over localhost:3001.
But when I try to include the script in my HTML, I get the following error in Chrome's developer console:
routerWarning.js:19 Uncaught SyntaxError: Unexpected token :
That line belongs to react-router and contains the following code:
process.env.NODE_ENV !== 'production' ? _warning2['default'].apply(undefined, [falseToWarn, message].concat(args)) : undefined;
First, I don't see how that line of code would cause a syntax error. And second, I don't understand how it got in, because this looks like a piece of compiled (babelified) code to me. And finally, I don't know how to fix it! :(
Any help would be greatly appreciated.
I was using webpack's DefinePlugin to set process.env.BABEL_ENV like this:
new DefinePlugin({
'process.env': {
BABEL_ENV: JSON.stringify('client')
}
});
This resulted in webpack replacing all instances of process.env in the code with {"BABEL_ENV":"client"}. The SyntaxError was caused in this part, not in the ternary expression.
I fixed it by setting process.env.BABEL_ENV like this:
new DefinePlugin({
'process.env.BABEL_ENV': JSON.stringify('client')
});
I looked through the protractor API and reference conf.js but I couldn't find any documentation on how to fail protractor on warnings or how to turn warnings into errors.
Is either of those possible?
There is nothing built-in in Protractor to treat warnings as errors.
You can redefine the Protractor's log.warn() and throw an error instead of logging a warning:
onPrepare: function () {
var logger = require('protractor/lib/logger.js');
logger.warn = function (message) {
throw message;
};
},
Works for me.
Also, note that:
WARNING - more than one element found for locator ... - the first result will be used
This warning can easily be fixed by replacing the:
element(...)
with:
element.all(...).first()
node.js 10.26 will rightfully throw an error when you try to require a file that is not valid javascript (or JSON).
My problem is that it also outputs to stderr:
borken.js - know to be broken javascript file
,,>Z>badfile!=-csa&asd;'asdl ds]=}{ADS}DAS:LMFSV'
test.js
try {
var borken = require('./borken');
} catch (e) {} finally {
console.log('finally!');
}
Expected
$ node test.js
finally!
Actual
$ node test.js
/path/to/borken.js:1
(function (exports, require, module, __filename, __dirname) { asd;'asdl
^^^^^
finally!
The first three lines are output to stderr (running as node test.js 2> /dev/null suppresses them).
Is there any way to get rid of them?
What I've done so far:
I debugged while following the source and narrowed down the culprit to:
lib/module.js:439
var compiledWrapper = runInThisContext(wrapper, filename, true);
runInThisContext is defined in lib/vm.js, which unfortunately is a C++ wrapper, so I couldn't really follow what is going on through there.
I guess I'm looking for a magic "don't spam stderr" flag or any knowledge of this being fixed in any latest versions.
Apparently this has been fixed in the dev branch (0.11.x) but not in the latest stable (0.10.29)
Github issue: Syntax errors are printed to stderr, even when wrapped with try/catch #6920