Coverage for functions \ flipdare \ util \ yaml_error_formatter.py: 96%

28 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

2# 

3# This file is part of Flipdare's proprietary software and contains 

4# confidential and copyrighted material. Unauthorised copying, 

5# modification, distribution, or use of this file is strictly 

6# prohibited without prior written permission from Flipdare Pty Ltd. 

7# 

8# This software includes third-party components licensed under MIT, 

9# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

10# 

11 

12from ruamel.yaml.error import MarkedYAMLError 

13 

14 

15class YamlErrorFormatter: 

16 def __init__(self, file_name: str, ex: Exception) -> None: 

17 self.file_name = file_name 

18 self.ex = ex 

19 

20 @property 

21 def formatted(self) -> str: 

22 ex = self.ex 

23 if isinstance(ex, MarkedYAMLError): 

24 mark = ex.problem_mark 

25 context_mark = ex.context_mark 

26 problem = ex.problem 

27 

28 msg = f"❌ YAML error found in file: {self.file_name}\n" 

29 msg += "\tError: " + (problem or "Unknown error") + "\n" 

30 

31 if context_mark is not None: 

32 orig_line = ex.context_mark.line + 1 

33 orig_col = ex.context_mark.column + 1 

34 dup_line = ex.problem_mark.line + 1 

35 dup_col = ex.problem_mark.column + 1 

36 

37 msg += "Context Error:\n" 

38 msg += f"\tOriginal Line: {orig_line}, column: {orig_col}\n" 

39 msg += f"\tProblem Line: {dup_line}, column: {dup_col}\n" 

40 

41 if mark is not None: 

42 line = mark.line 

43 column = mark.column 

44 msg += f"Error Location: line {line + 1}, column {column + 1}\n" 

45 

46 return msg 

47 

48 # For other exceptions, return a generic message 

49 return f"❌ Error found in file: {self.file_name}\nError: {ex!s}\n"