Coverage for src/governed_harness/application/hints.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-12 16:06 +0000

1"""Remedies printed next to an error: what to run to fix it. 

2 

3The error text and the exit code stay as they are (scripts and tests rely on them); the hint is 

4an extra ``hint`` field in the JSON error and a ``Hint:`` line on a terminal.""" 

5 

6from __future__ import annotations 

7 

8from governed_harness.domain.errors import ConfigurationError, NotFoundError 

9 

10_HINTS: tuple[tuple[type[BaseException], str, str], ...] = ( 

11 ( 

12 ConfigurationError, 

13 "no .harness/project.yaml found", 

14 "Run `harness init` in the project directory, or pass --path to a project that has one.", 

15 ), 

16 ( 

17 ConfigurationError, 

18 "configuration already exists", 

19 "The project is already initialized; pass --force to replace its project.yaml.", 

20 ), 

21 ( 

22 NotFoundError, 

23 "execution not found", 

24 "List the runs with `harness run list`; `--run latest` selects the newest run and a " 

25 "unique prefix such as `run_1a2b` is accepted.", 

26 ), 

27 ( 

28 NotFoundError, 

29 "task not found", 

30 "List the tasks with `harness task list`, or create one with " 

31 "`harness task create --file task.yaml`.", 

32 ), 

33 ( 

34 NotFoundError, 

35 "artifact not found", 

36 "Use the full `artifact://sha256/...` reference or a longer digest prefix shown by " 

37 "`harness evidence list`.", 

38 ), 

39) 

40 

41 

42def default_hint(error: BaseException) -> str | None: 

43 message = str(error) 

44 for kind, fragment, hint in _HINTS: 

45 if isinstance(error, kind) and fragment in message: 

46 return hint 

47 return None