kibana/packages
Matt Bargar 539bc6f3a2
Improve KQL error messages (#34900)
Attempts to make KQL syntax errors more sensical to the average user.

I initially tried to use a similar solution to the one we used for detecting usage of old lucene syntax. In other words, I tried to create rules in the grammar that would match strings containing common mistakes the user might make and throw custom error messages for each situation. This proved to be more difficult for detecting errors in the regular language. While the Lucene rules could be completely separated from the main grammar, the KQL error rules had to be mixed into the main grammar which made it much more complex and had a lot of unintended side effects.

So instead I decided to lean more heavily on PEG's built in error reporting. Giving certain rules human readable names allows the parser to use those names in the error reporting instead of auto generating a long list of possible characters that might be expected based on the matching rules. Since the PEG errors contain location information I was also able to add ascii art that points the user to exactly where the error occurred in their query string. While this approach is not quite as nice as bespoke error messages that tell the user exactly what is wrong in plain English, it's much more maintainable and I think it still results in much better error messages compared to what we have today.

I've also removed the old original kuery grammar (for queries like is(response, 200)). We were only using it to display an error if I user was still using the old syntax. This version of kuery hasn't existed since 6.3 and we've had error messages telling users this since then. I think it's safe to remove the legacy parser at this point, which greatly reduces the complexity of our error reporting.
2019-04-24 16:40:38 -04:00
..
elastic-datemath Migrate from tslint (#33826) 2019-04-05 17:45:23 +01:00
eslint-config-kibana [New platform] Restrict import from core&plugin internals for ts files (#34688) 2019-04-10 14:56:09 +02:00
kbn-babel-code-parser Migration to Babel7 and @babel/preset-typescript (#33093) 2019-03-26 20:44:03 +00:00
kbn-babel-preset [APM] Optimize idx calls to native optional chaining (#34841) 2019-04-22 13:37:07 -07:00
kbn-config-schema [ts][ftr] improve types for ftr and expect.js, cleanup changes to tsconfig files (#31948) 2019-02-28 12:06:00 -08:00
kbn-dev-utils [ftr] convert remaining JS to TS (#35110) 2019-04-18 12:06:24 -07:00
kbn-elastic-idx [APM] Optimize idx calls to native optional chaining (#34841) 2019-04-22 13:37:07 -07:00
kbn-es [kbn-es] Add network archive downloading to installArchive (#31535) 2019-04-23 21:48:14 -07:00
kbn-es-query Improve KQL error messages (#34900) 2019-04-24 16:40:38 -04:00
kbn-eslint-import-resolver-kibana Prefer third-party plugin development in ./plugins instead of ../kibana-extra (#31748) 2019-03-07 17:04:29 -06:00
kbn-eslint-plugin-eslint [New platform] Restrict import from core&plugin internals for ts files (#34688) 2019-04-10 14:56:09 +02:00
kbn-expect Migrate from tslint (#33826) 2019-04-05 17:45:23 +01:00
kbn-i18n [npm] upgrade getopts (#34603) 2019-04-15 14:39:34 -07:00
kbn-interpreter [npm] upgrade getopts (#34603) 2019-04-15 14:39:34 -07:00
kbn-plugin-generator [npm] upgrade getopts (#34603) 2019-04-15 14:39:34 -07:00
kbn-plugin-helpers Migration to Babel7 and @babel/preset-typescript (#33093) 2019-03-26 20:44:03 +00:00
kbn-pm [npm] upgrade getopts (#34603) 2019-04-15 14:39:34 -07:00
kbn-spec-to-console adding spec to console utility as Kibana script (#35232) 2019-04-17 20:40:32 -04:00
kbn-test [ftr] convert remaining JS to TS (#35110) 2019-04-18 12:06:24 -07:00
kbn-test-subj-selector Migrate from tslint (#33826) 2019-04-05 17:45:23 +01:00
kbn-ui-framework Merge remote-tracking branch 'origin/master' into feature/merge-code 2019-04-17 21:47:00 -07:00
README.md

Kibana-related packages

This folder contains packages that are intended for use in Kibana and Kibana plugins.

tl;dr:

  • Don't publish to npm registry
  • Always use the @kbn namespace
  • Always set "private": true in package.json

Using these packages

We no longer publish these packages to the npm registry. Now, instead of specifying a version when including these packages, we rely on yarn workspaces, which sets up a symlink to the package.

For example if you want to use the @kbn/i18n package in Kibana itself, you can specify the dependency like this:

"@kbn/i18n": "1.0.0"

However, if you want to use this from a Kibana plugin, you need to use a link: dependency and account for the relative location of the Kibana repo, so it would instead be:

"@kbn/i18n": "link:../../kibana/packages/kbn-i18n"

How all of this works is described in more detail in the @kbn/pm docs.

Creating a new package

Create a new sub-folder. The name of the folder should mirror the name in the package's package.json. E.g. if the name is @kbn/i18n the folder name should be kbn-i18n.

All new packages should use the @kbn namespace, and should be marked with "private": true.

Unit tests for a package

Currently there are two patterns used to test packages, one using Mocha and one using Jest. These patterns emerged out of convention and we'd like to make them more similar to each other in the near future.

1. Mocha

Today a package can follow the pattern of having a __tests__ directory in each source code directory of a package which contains the tests for that module. These are usually run by Mocha.

If a package's tests should be run with Mocha, you'll have to opt-in to run them by appending the package's test file pattern(s) to Kibana's tasks/config/simplemocha.js file. These will then be run by the unit test runner.

  • yarn test or yarn grunt test runs all unit tests.
  • node scripts/mocha runs all Mocha tests.

2. Jest

A package can also follow the pattern of having .test.js files as siblings of the source code files, and these run by Jest.

A package using the .test.js naming convention will have those tests automatically picked up by Jest and run by the unit test runner, currently mapped to the Kibana test script in the root package.json.

  • yarn test or yarn grunt test runs all unit tests.
  • node scripts/jest runs all Jest tests in Kibana.

Each package can also specify its own test script in the package's package.json, for cases where you'd prefer to run the tests from the local package directory.