Implement more flexible error handling

- Add exception handling around new interface CommandExceptionResolver
  which allows to define a chain of resolvers to process errors before
  exception is bubbled up to result handlers.
- Will be foundation to add more sophisticated error handling features
  compared to what spring itself have for rest layer.
- Resolver returns CommandHandlingResult holder which further can be
  used to make a choice what to print into console and if spesific exit
  code should be used in non-interactive mode.
- Exception handling can be defined globally and per command giving
  a change for user to customise i.e. error thrown by parser.
- CommandParserExceptionResolver replaces CommandParserExceptionsExceptionResultHandler
  and provides more meaninful message for missing options.
- Fixes #503
This commit is contained in:
Janne Valkealahti
2022-10-14 10:46:27 +01:00
parent 3fe26025cd
commit 4c48017a97
23 changed files with 999 additions and 102 deletions

View File

@@ -23,7 +23,7 @@ describe('e2e commands exit-code', () => {
cli.run();
await waitForExpect(async () => {
const screen = cli.screen();
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Missing option')]));
expect(screen).toEqual(expect.arrayContaining([expect.stringContaining('Missing mandatory option')]));
});
await expect(cli.exitCode()).resolves.toBe(2);
};