FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cecli/cecli/report.py at main · cecli-dev/cecli · GitHub
cecli-dev
cecli
Repository navigation
Code
Issues
11
(11)
Pull requests
8
(8)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cecli
/
cecli
/
report.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
278 lines (217 loc) · 7.84 KB
Breadcrumbs
cecli
/
cecli
/
report.py
Copy path
File metadata and controls
278 lines (217 loc) · 7.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import
os
import
platform
import
subprocess
import
sys
import
traceback
import
urllib
.
parse
import
webbrowser
from
cecli
import
__version__
from
cecli
.
urls
import
github_issues
from
cecli
.
versioncheck
import
VERSION_CHECK_FNAME
# Global variable to store resolved args data for error reporting
resolved_args_data
=
None
error_prefix
=
[]
FENCE
=
"`"
*
3
def
get_python_info
():
implementation
=
platform
.
python_implementation
()
is_venv
=
sys
.
prefix
!=
sys
.
base_prefix
return
(
f"Python implementation:
{
implementation
}
\n
Virtual environment:"
f"
{
'Yes'
if
is_venv
else
'No'
}
"
)
def
get_os_info
():
return
f"OS:
{
platform
.
system
()
}
{
platform
.
release
()
}
(
{
platform
.
architecture
()[
0
]
}
)"
def
get_git_info
():
try
:
git_version
=
subprocess
.
check_output
([
"git"
,
"--version"
]).
decode
().
strip
()
return
f"Git version:
{
git_version
}
"
except
Exception
:
return
"Git information unavailable"
def
format_args_for_reporting
(
args
):
"""
Format args data for error reporting, removing sensitive keys and collapsing MCP servers.
"""
if
not
args
:
return
"No args data available"
# Create a copy of the args namespace as a dictionary
args_dict
=
vars
(
args
).
copy
()
# Remove any keys containing "key" (case insensitive)
keys_to_remove
=
[
key
for
key
in
args_dict
.
keys
()
if
"key"
in
key
.
lower
()]
for
key
in
keys_to_remove
:
args_dict
.
pop
(
key
,
None
)
# Handle mcp_servers - collapse into just a list of server names
if
"mcp_servers"
in
args_dict
:
mcp_servers
=
args_dict
[
"mcp_servers"
]
if
isinstance
(
mcp_servers
,
str
):
try
:
import
json
config
=
json
.
loads
(
mcp_servers
)
if
"mcpServers"
in
config
:
server_names
=
list
(
config
[
"mcpServers"
].
keys
())
args_dict
[
"mcp_servers"
]
=
server_names
except
(
json
.
JSONDecodeError
,
AttributeError
):
# If parsing fails, keep the original value
pass
# Format the output line by line
lines
=
[
"Configuration:
\n
```yaml"
]
for
key
,
value
in
sorted
(
args_dict
.
items
()):
lines
.
append
(
f"
{
key
}
:
{
value
}
"
)
lines
.
append
(
"```"
)
return
"
\n
"
.
join
(
lines
)
def
get_args_error_data
():
global
resolved_args_data
# noqa
return
resolved_args_data
def
set_args_error_data
(
args
):
global
resolved_args_data
# noqa
resolved_args_data
=
args
def
get_error_prefix
():
global
error_prefix
# noqa
return
error_prefix
def
update_error_prefix
(
prefix
):
global
error_prefix
# noqa
error_prefix
.
append
(
f"
{
prefix
}
\n
"
)
error_prefix
=
error_prefix
[
-
10
:]
def
report_github_issue
(
issue_text
,
title
=
None
,
confirm
=
True
):
"""
Compose a URL to open a new GitHub issue with the given text prefilled,
and attempt to launch it in the default web browser.
:param issue_text: The text of the issue to file
:param title: The title of the issue (optional)
:param confirm: Whether to ask for confirmation before opening the browser (default: True)
:return: None
"""
version_info
=
f"cecli version:
{
__version__
}
\n
"
python_version
=
f"Python version:
{
sys
.
version
.
split
()[
0
]
}
\n
"
platform_info
=
f"Platform:
{
platform
.
platform
()
}
\n
"
python_info
=
get_python_info
()
+
"
\n
"
os_info
=
get_os_info
()
+
"
\n
"
git_info
=
get_git_info
()
+
"
\n
"
args_info
=
format_args_for_reporting
(
get_args_error_data
())
+
"
\n
"
prefix_info
=
""
.
join
(
get_error_prefix
())
system_info
=
(
version_info
+
python_version
+
platform_info
+
python_info
+
os_info
+
git_info
+
"
\n
"
+
prefix_info
+
"
\n
"
+
args_info
+
"
\n
"
)
issue_text
=
system_info
+
issue_text
params
=
{
"body"
:
issue_text
}
if
title
is
None
:
title
=
"Bug report"
params
[
"title"
]
=
title
issue_url
=
f"
{
github_issues
}
?
{
urllib
.
parse
.
urlencode
(
params
)
}
"
if
confirm
:
# print(f"\n# {title}\n")
# print(issue_text.strip())
# print()
print
(
"Please consider reporting this bug to help improve cecli!"
)
prompt
=
(
"Open a GitHub Issue pre-filled with the above error messages in your browser? (Y/n) "
)
confirmation
=
input
(
prompt
).
strip
().
lower
()
yes
=
not
confirmation
or
confirmation
.
startswith
(
"y"
)
if
not
yes
:
return
print
(
"Attempting to open the issue URL in your default web browser..."
)
try
:
if
webbrowser
.
open
(
issue_url
):
print
(
"Browser window should be opened."
)
except
Exception
:
pass
if
confirm
:
print
()
print
()
print
(
"You can also use this URL to file the GitHub Issue:"
)
print
()
print
(
issue_url
)
print
()
print
()
def
exception_handler
(
exc_type
,
exc_value
,
exc_traceback
):
# If it's a KeyboardInterrupt, just call the default handler
if
issubclass
(
exc_type
,
KeyboardInterrupt
):
return
sys
.
__excepthook__
(
exc_type
,
exc_value
,
exc_traceback
)
# We don't want any more exceptions
sys
.
excepthook
=
None
# Check if VERSION_CHECK_FNAME exists and delete it if so
try
:
if
VERSION_CHECK_FNAME
.
exists
():
VERSION_CHECK_FNAME
.
unlink
()
except
Exception
:
pass
# Swallow any errors
# Format the traceback
tb_lines
=
traceback
.
format_exception
(
exc_type
,
exc_value
,
exc_traceback
)
# Replace full paths with basenames in the traceback
tb_lines_with_basenames
=
[]
for
line
in
tb_lines
:
try
:
if
"File "
in
line
:
parts
=
line
.
split
(
'"'
)
if
len
(
parts
)
>
1
:
full_path
=
parts
[
1
]
basename
=
os
.
path
.
basename
(
full_path
)
line
=
line
.
replace
(
full_path
,
basename
)
except
Exception
:
pass
tb_lines_with_basenames
.
append
(
line
)
tb_text
=
""
.
join
(
tb_lines_with_basenames
)
# Find the innermost frame
innermost_tb
=
exc_traceback
while
innermost_tb
.
tb_next
:
innermost_tb
=
innermost_tb
.
tb_next
# Get the filename and line number from the innermost frame
filename
=
innermost_tb
.
tb_frame
.
f_code
.
co_filename
line_number
=
innermost_tb
.
tb_lineno
try
:
basename
=
os
.
path
.
basename
(
filename
)
except
Exception
:
basename
=
filename
# Get the exception type name
exception_type
=
exc_type
.
__name__
# Prepare the issue text
issue_text
=
f"An uncaught exception occurred:
\n
\n
{
FENCE
}
\n
{
tb_text
}
\n
{
FENCE
}
"
# Prepare the title
title
=
f"Uncaught
{
exception_type
}
in
{
basename
}
line
{
line_number
}
"
# Report the issue
report_github_issue
(
issue_text
,
title
=
title
)
# Call the default exception handler
sys
.
__excepthook__
(
exc_type
,
exc_value
,
exc_traceback
)
def
report_uncaught_exceptions
():
"""
Set up the global exception handler to report uncaught exceptions.
"""
sys
.
excepthook
=
exception_handler
def
dummy_function1
():
def
dummy_function2
():
def
dummy_function3
():
raise
ValueError
(
"boo"
)
dummy_function3
()
dummy_function2
()
def
main
():
report_uncaught_exceptions
()
dummy_function1
()
title
=
None
if
len
(
sys
.
argv
)
>
2
:
# Use the first command-line argument as the title and the second as the issue text
title
=
sys
.
argv
[
1
]
issue_text
=
sys
.
argv
[
2
]
elif
len
(
sys
.
argv
)
>
1
:
# Use the first command-line argument as the issue text
issue_text
=
sys
.
argv
[
1
]
else
:
# Read from stdin if no argument is provided
print
(
"Enter the issue title (optional, press Enter to skip):"
)
title
=
input
().
strip
()
if
not
title
:
title
=
None
print
(
"Enter the issue text (Ctrl+D to finish):"
)
issue_text
=
sys
.
stdin
.
read
().
strip
()
report_github_issue
(
issue_text
,
title
)
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL