|
17 | 17 | ) |
18 | 18 | from canonicalwebteam.exceptions import StoreApiError |
19 | 19 | from canonicalwebteam.store_api.devicegw import DeviceGW |
20 | | -from pybadges import badge |
21 | | - |
22 | 20 | device_gateway = DeviceGW("snap", helpers.api_session) |
23 | | - |
| 21 | +from pybadges import badge |
| 22 | +import sys |
| 23 | + |
| 24 | + |
| 25 | +# --- Patch device_gateway.session.get to log full request/response --- |
| 26 | +original_get = device_gateway.session.get |
| 27 | + |
| 28 | +def debug_get(url, *args, **kwargs): |
| 29 | + if "nushell" in url: |
| 30 | + print(f"\nDEBUG: GET request to URL: {url}") |
| 31 | + print(f"DEBUG: kwargs: {kwargs}") |
| 32 | + response = original_get(url, *args, **kwargs) |
| 33 | + if "nushell" in url: |
| 34 | + print(f"DEBUG: Response status: {response.status_code}") |
| 35 | + print(f"DEBUG: Response headers: {response.headers}") |
| 36 | + print(f"DEBUG: Response text (first 500 chars): {response.text[:500]}") |
| 37 | + sys.stdout.flush() |
| 38 | + return response |
| 39 | + |
| 40 | +device_gateway.session.get = debug_get |
| 41 | + |
| 42 | +# --- Patch get_snap_details to log input, output, and exceptions --- |
| 43 | +original_get_snap_details = device_gateway.get_snap_details |
| 44 | + |
| 45 | +def debug_get_snap_details(snap_name, fields=None): |
| 46 | + if snap_name == "nushell": |
| 47 | + print(f"\nDEBUG: Calling get_snap_details with snap_name={snap_name}, fields={fields}") |
| 48 | + sys.stdout.flush() |
| 49 | + try: |
| 50 | + result = original_get_snap_details(snap_name, fields=fields) |
| 51 | + print(f"DEBUG: get_snap_details result:\n{result}") |
| 52 | + sys.stdout.flush() |
| 53 | + return result |
| 54 | + except Exception as e: |
| 55 | + print(f"DEBUG: Exception in get_snap_details: {e}") |
| 56 | + sys.stdout.flush() |
| 57 | + import traceback |
| 58 | + traceback.print_exc() |
| 59 | + raise |
| 60 | + |
| 61 | +device_gateway.get_snap_details = debug_get_snap_details |
| 62 | + |
| 63 | +import traceback |
24 | 64 | FIELDS = [ |
25 | 65 | "title", |
26 | 66 | "summary", |
@@ -213,19 +253,20 @@ def snap_details(snap_name): |
213 | 253 | status_code = 200 |
214 | 254 |
|
215 | 255 | context = _get_context_snap_details(snap_name) |
216 | | - print(f"DEBUGGING: {snap_name}") |
| 256 | + print("----------------------------------------------------------------") |
| 257 | + print(f"DEBUGGING: {snap_name}",flush=True) |
217 | 258 | try: |
218 | 259 | extra_details = device_gateway.get_snap_details( |
219 | 260 | snap_name, fields=FIELDS_EXTRA_DETAILS |
220 | 261 | ) |
221 | 262 | except Exception as e: |
| 263 | + print("IT FAILED",flush=True) |
222 | 264 | print(e) |
223 | | - response = requests.get( |
224 | | - f"https://api.snapcraft.io/api/v1/snaps/details/{snap_name}?fields=aliases", |
225 | | - headers={"X-Ubuntu-Series": "16"}) |
226 | | - print(response.status_code) |
227 | | - print(response.text) |
228 | | - print("END_DEBUGGING") |
| 265 | + traceback.print_exc() |
| 266 | + extra_details = None |
| 267 | + print("END_DEBUGGING",flush=True) |
| 268 | + |
| 269 | + print("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE") |
229 | 270 |
|
230 | 271 | if extra_details and extra_details["aliases"]: |
231 | 272 | context["aliases"] = [ |
|
0 commit comments