def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except (IndexError, OSError, RuntimeError, HTTPException, urllib3.exceptions.HTTPError, DeviceFacade.JsonRpcError, adbutils.errors.AdbError) as ex: print(COLOR_FAIL + describe_exception( ex, with_stacktrace=__version__.__debug_mode__ or not is_insomniac()) + COLOR_ENDC) # Check that adb works fine check_adb_connection(device_wrapper.device_id, wait_for_device=True) # Try to save the crash save_crash(device_wrapper.get(), ex) print("No idea what it was. Let's try again.") # Hack for the case when IGTV was accidentally opened close_instagram_and_system_dialogs(device_wrapper.get()) open_instagram(device_wrapper.device_id, device_wrapper.app_id) except LanguageChangedException: print_timeless("") print( "Language was changed. We'll have to start from the beginning." ) except RestartJobRequiredException: print_timeless("") print("Restarting job...")
def save_crash(device, ex=None): global print_log try: device.wake_up() directory_name = "Crash-" + datetime.now().strftime( "%Y-%m-%d-%H-%M-%S") try: os.makedirs(os.path.join("crashes", directory_name), exist_ok=False) except OSError: print(COLOR_FAIL + "Directory " + directory_name + " already exists." + COLOR_ENDC) return screenshot_format = ".png" if device.is_old() else ".jpg" try: device.screenshot( os.path.join("crashes", directory_name, "screenshot" + screenshot_format)) except RuntimeError: print(COLOR_FAIL + "Cannot save screenshot." + COLOR_ENDC) view_hierarchy_format = ".xml" try: device.dump_hierarchy( os.path.join("crashes", directory_name, "view_hierarchy" + view_hierarchy_format)) except RuntimeError: print(COLOR_FAIL + "Cannot save view hierarchy." + COLOR_ENDC) with open(os.path.join("crashes", directory_name, "logs.txt"), 'w', encoding="utf-8") as outfile: outfile.write(print_log) if ex: outfile.write("\n") outfile.write(describe_exception(ex)) shutil.make_archive(os.path.join("crashes", directory_name), 'zip', os.path.join("crashes", directory_name)) shutil.rmtree(os.path.join("crashes", directory_name)) if insomniac_globals.is_insomniac(): print(COLOR_OKGREEN + "Crash saved as \"crashes/" + directory_name + ".zip\"." + COLOR_ENDC) print(COLOR_OKGREEN + "Please attach this file if you gonna report the crash at" + COLOR_ENDC) print(COLOR_OKGREEN + "https://github.com/alexal1/Insomniac/issues\n" + COLOR_ENDC) except Exception as e: print( COLOR_FAIL + f"Could not save crash after an error. Crash-save-error: {str(e)}" + COLOR_ENDC) print(COLOR_FAIL + describe_exception(e) + COLOR_ENDC)
def print_copyright(): if insomniac_globals.is_insomniac(): print_timeless("\nIf you like this bot, please " + COLOR_BOLD + "give us a star" + COLOR_ENDC + ":") print_timeless(COLOR_BOLD + "https://github.com/alexal1/Insomniac\n" + COLOR_ENDC)