From b5a333d5354d7cab82f5342a8e50d13f44f1e878 Mon Sep 17 00:00:00 2001 From: Dhinak G <17605561+dhinakg@users.noreply.github.com> Date: Fri, 7 May 2021 16:35:59 -0400 Subject: [PATCH] Fix exception traceback printing wrong thing Fix crash in `guess_ports()` when companion has errored Add some more specific port errored prints debug_dump now saves to file (& prompts for location) --- Scripts/usbdump.py | 8 ++++++-- Windows.py | 2 +- base.py | 4 ++-- debug_dump.py | 16 ++++++++++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Scripts/usbdump.py b/Scripts/usbdump.py index 1dc5924..7b4f676 100644 --- a/Scripts/usbdump.py +++ b/Scripts/usbdump.py @@ -110,7 +110,7 @@ def guess_ports(): if not port["status"].endswith("DeviceConnected"): # we don't have info. anything else is going to error port["guessed"] = None - elif port["type_c"] or port["companion_info"]["port"] and get_companion_port(port)["type_c"]: + elif port["type_c"] or port["companion_info"]["port"] and get_companion_port(port).get("type_c", None): port["guessed"] = shared.USBPhysicalPortTypes.USB3TypeC_WithSwitch elif not port["user_connectable"]: port["guessed"] = shared.USBPhysicalPortTypes.Internal @@ -157,9 +157,13 @@ def serialize_hub(hub): } port_info["name"] = f"Port {port_info['index']}" + friendly_error = { + "DeviceCausedOvercurrent": "Device connected to port pulled too much current." + } + if not port_info["status"].endswith("DeviceConnected"): # shared.debug(f"Device connected to port {port_info['index']} errored. Please unplug or connect a different device.") - port_info["devices"] = [{"error": True}] + port_info["devices"] = [{"error": friendly_error.get(port_info["status"], True)}] hub_info["ports"].append(port_info) continue diff --git a/Windows.py b/Windows.py index 0e1e5fd..5c8eac2 100644 --- a/Windows.py +++ b/Windows.py @@ -111,7 +111,7 @@ def get_controllers(self): self.update_usbdump() break except Exception as e: - if i == 10: + if i == 9: raise else: shared.debug(e) diff --git a/base.py b/base.py index 93ef618..76cfc42 100644 --- a/base.py +++ b/base.py @@ -14,7 +14,7 @@ from Scripts import shared, utils -CURRENT_VERSION = "0.0.7" +CURRENT_VERSION = "0.0.8" class Colors(Enum): @@ -207,7 +207,7 @@ def print_devices(self, device, indentation=" "): if isinstance(device, str): print(f"{indentation}- {device}") elif device.get("error", False): - print(f"{indentation}- Device connected to port errored. Please unplug or connect a different device.") + print(f"{indentation}- {device['error'] if isinstance(device['error'], str) else 'Device connected to port errored.'} Please unplug or connect a different device.") else: print(f"{indentation}- {device['name'].strip()} - operating at {shared.USBDeviceSpeeds(device['speed'])}") for i in device["devices"]: diff --git a/debug_dump.py b/debug_dump.py index bbd449f..a266697 100644 --- a/debug_dump.py +++ b/debug_dump.py @@ -4,7 +4,8 @@ import time from enum import Enum from pathlib import Path - +import tkinter as tk +import tkinter.filedialog as filedialog import win32com.client import wmi @@ -77,4 +78,15 @@ def recurse_bus(instance_id): usbdump = json.loads(subprocess.run(usbdump_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.decode()) -print(json.dumps({"wmitest": controllers, "usbdump": usbdump}, sort_keys=True)) +temp_tk_root = tk.Tk() +temp_tk_root.wm_withdraw() +save_path = filedialog.asksaveasfilename(title="Save debugging information", defaultextension=".json", filetypes=[("json", "*.json")]) +temp_tk_root.destroy() + +if not save_path: + sys.exit(1) +else: + save_path = Path(save_path) + +json.dump({"wmitest": controllers, "usbdump": usbdump}, save_path.open("w"), sort_keys=True) +input(f"Please upload {save_path}.\nPress [Enter] to exit")