Crash Kibana in dev/CI if a process warning is detected. This does not influence how Kibana behaves in production when run via `./bin/kibana` as there the `--no-warnings` flag is used. We will detect this flag and as a result, disable this behavior. Previously we used the flags `--trace-warnings --throw-deprecation` when you started Kibana via `yarn start` and we used `--throw-deprecation` in CI. This meant that we would only crash on deprecation warnings and log a stack trace for all other types of warnings. There were a couple of drawbacks to this approach: 1. If the deprecated API was called in a place enclosed in a try-catch (or inside of a Promise or an async/await context), the throw would be caught and the program would not crash. 2. If you ran `./scripts/kibana` directly instead of running `yarn start`, you would not get these flags automatically. 3. If you ran any of our tests locally you would not get the standard CI flags. This meant something that might seem to pass locally would not pass in CI. This commit changes this behavior by ensuring: - That we always crash - no matter if the offending code is surrounded by a try-catch (etc). - That you always get the same behavior whether you run `yarn start` or `./scripts/kibana`. - That you always get the same behavior in CI or if you run individual tests locally. Furthermore, we now crash for all types of warnings - not only deprecation warnings (except `MaxListenersExceededWarning`). Closes #59646
This commit is contained in:
parent
fe2fb159ec
commit
9fb405f481
|
@ -52,7 +52,7 @@
|
|||
"typespec": "typings-tester --config x-pack/legacy/plugins/canvas/public/lib/aeroelastic/tsconfig.json x-pack/legacy/plugins/canvas/public/lib/aeroelastic/__fixtures__/typescript/typespec_tests.ts",
|
||||
"checkLicenses": "node scripts/check_licenses --dev",
|
||||
"build": "node scripts/build --all-platforms",
|
||||
"start": "node --trace-warnings --throw-deprecation scripts/kibana --dev",
|
||||
"start": "node scripts/kibana --dev",
|
||||
"debug": "node --nolazy --inspect scripts/kibana --dev",
|
||||
"debug-break": "node --nolazy --inspect-brk scripts/kibana --dev",
|
||||
"lint": "yarn run lint:es && yarn run lint:sass",
|
||||
|
|
|
@ -14,7 +14,7 @@ cacheDir="$HOME/.kibana"
|
|||
RED='\033[0;31m'
|
||||
C_RESET='\033[0m' # Reset color
|
||||
|
||||
export NODE_OPTIONS="$NODE_OPTIONS --throw-deprecation --max-old-space-size=4096"
|
||||
export NODE_OPTIONS="$NODE_OPTIONS --max-old-space-size=4096"
|
||||
|
||||
###
|
||||
### Since the Jenkins logging output collector doesn't look like a TTY
|
||||
|
@ -168,4 +168,4 @@ if [[ -d "$ES_DIR" && -f "$ES_JAVA_PROP_PATH" ]]; then
|
|||
export JAVA_HOME=$HOME/.java/$ES_BUILD_JAVA
|
||||
fi
|
||||
|
||||
export CI_ENV_SETUP=true
|
||||
export CI_ENV_SETUP=true
|
||||
|
|
38
src/setup_node_env/exit_on_warning.js
Normal file
38
src/setup_node_env/exit_on_warning.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
if (process.noProcessWarnings !== true) {
|
||||
var ignore = ['MaxListenersExceededWarning'];
|
||||
|
||||
process.on('warning', function(warn) {
|
||||
if (ignore.includes(warn.name)) return;
|
||||
|
||||
if (process.traceProcessWarnings === true) {
|
||||
console.error('Node.js process-warning detected - Terminating process...');
|
||||
} else {
|
||||
console.error('Node.js process-warning detected:');
|
||||
console.error();
|
||||
console.error(warn.stack);
|
||||
console.error();
|
||||
console.error('Terminating process...');
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
|
@ -17,7 +17,11 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
require('./harden'); // this require MUST be executed before any others
|
||||
// The following require statements MUST be executed before any others - BEGIN
|
||||
require('./exit_on_warning');
|
||||
require('./harden');
|
||||
// The following require statements MUST be executed before any others - END
|
||||
|
||||
require('symbol-observable');
|
||||
require('./root');
|
||||
require('./node_version_validator');
|
||||
|
|
Loading…
Reference in a new issue