Fix error handling for per-file imports that use import mode ALL

Code owner config files can import other code owner config files. Which
rules are being imported depends on the import mode:

* ALL: all rules are imported
* GLOBAL_CODE_OWNER_SETS_ONLY: only rules for global code owners are
  imported (aka folder code owners)

For per-file code owner sets only imports with mode
GLOBAL_CODE_OWNER_SETS_ONLY are allowed.

If the find-owners backend is used, the import keyword controls which
import mode is being used:

* include = ALL
* file: = GLOBAL_CODE_OWNER_SETS_ONLY

OWNERS files with a per-file rule that use the include keyword, although
the include keyword is not allowed for per-file rules, are rejected as
non-parseable. However instead of throwing a
CodeOwnerConfigParseException, FindOwnersConfigParser throwed an
IllegalStateException. This was bad because IllegalStateExceptions are
causing internal server errors, whereas CodeOwnerConfigParseExceptions
are handled as configuration errors. Configuration errors make requests
fail with 409 Conflict and a proper error message, or if they occur
during the submit rule evaluation they cause the status to be set to
RULE_ERROR. This way the user can find out what's wrong and fix the bad
OWNERS file.

While we are at this, improve the error message. Talking about import
mode ALL doesn't make sense from a user's perspective. Rather tell them
directly that the include keyword is not supported for per-file rules.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I382aae540dcc69fcda30a565c75aa696a866664c
3 files changed
tree: e96ca39f48a51b5fe1684f76b6ee2b02e342edb4
  1. java/
  2. javatests/
  3. proto/
  4. resources/
  5. test/
  6. ui/
  7. .eslintrc.json
  8. .gitignore
  9. .gitreview
  10. bower.json
  11. BUILD
  12. LICENSE
  13. package-lock.json
  14. package.json
  15. README.md
README.md

Gerrit Code Review code-owners plugin

This plugin provides support for defining code owners for files in a repository.

If the code-owners plugin is enabled, changes can only be submitted if all touched files are covered by approvals from code owners.

Also see resources/Documentation/about.md.

IMPORTANT: Before installing/enabling the plugin follow the instructions from the setup guide, see resources/Documentation/setup-guide.md.