Coverage for faststream / _internal / cli / utils / errors.py: 0%

10 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-08 01:48 +0000

1from faststream.exceptions import StartupValidationError 

2 

3 

4def draw_startup_errors(startup_exc: StartupValidationError) -> None: 

5 from click.exceptions import BadParameter, MissingParameter 

6 from typer.core import TyperOption 

7 

8 def draw_error(click_exc: BadParameter) -> None: 

9 try: 

10 from typer import rich_utils 

11 

12 rich_utils.rich_format_error(click_exc) 

13 except ImportError: 

14 click_exc.show() 

15 

16 for field in startup_exc.invalid_fields: 

17 draw_error( 

18 BadParameter( 

19 message=( 

20 "extra option in your application " 

21 "`lifespan/on_startup` hook has a wrong type." 

22 ), 

23 param=TyperOption(param_decls=[f"--{field}"]), 

24 ), 

25 ) 

26 

27 if startup_exc.missed_fields: 

28 draw_error( 

29 MissingParameter( 

30 message=( 

31 "You registered extra options in your application " 

32 "`lifespan/on_startup` hook, but does not set in CLI." 

33 ), 

34 param=TyperOption( 

35 param_decls=[f"--{x}" for x in startup_exc.missed_fields], 

36 ), 

37 ), 

38 )