-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_error.py
More file actions
122 lines (85 loc) Β· 2.13 KB
/
Copy pathnew_error.py
File metadata and controls
122 lines (85 loc) Β· 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""Scaffold a new error document from the canonical template."""
from __future__ import annotations
import re
from datetime import date
from pathlib import Path
_TEMPLATE = """---
title: "{title}"
slug: {slug}
technologies: [{technology}]
severity: {severity}
tags: [{tags}]
related: []
last_reviewed: {today}
---
# {title}
## Error Message
```text
TODO: paste the exact error string here.
```
## Description
TODO: explain what this error means and when it appears.
## Technologies
- {technology}
## Severity
**{severity}** β TODO: describe the operational impact.
## Common Causes
1. TODO
## Root Cause Analysis
TODO: explain the failure mechanism.
## Diagnostic Commands
```bash
# TODO: a real, READ-ONLY diagnostic command.
```
## Expected Results
```text
TODO: what the diagnostic output reveals.
```
## Resolution
1. TODO
## Validation
TODO: how to confirm the fix worked.
## Prevention
- TODO
## Related Errors
- TODO
## References
- [Advanced troubleshooting guides](https://devopsaitoolkit.com/blog)
## Tags
`{tag_inline}`
"""
def slugify(text: str) -> str:
"""Turn a title into a kebab-case slug."""
slug = re.sub(r"[^a-z0-9]+", "-", text.lower()).strip("-")
return slug or "error"
def create_error(
title: str,
technology: str,
*,
severity: str = "medium",
tags: list[str] | None = None,
root: str | Path = "errors",
subdir: str | None = None,
) -> Path:
"""Write a new error document and return its path.
The file is placed under ``errors/<technology>/`` (or a nested ``subdir`` such
as an OpenStack service) and named after the slug.
"""
slug = slugify(title)
tag_list = tags or [technology]
base = Path(root) / technology
if subdir:
base = base / subdir
base.mkdir(parents=True, exist_ok=True)
target = base / f"{slug}.md"
content = _TEMPLATE.format(
title=title,
slug=slug,
technology=technology,
severity=severity,
tags=", ".join(tag_list),
tag_inline=" Β· ".join(tag_list),
today=date.today().isoformat(),
)
target.write_text(content, encoding="utf-8")
return target