pymobiledevice3 icon indicating copy to clipboard operation
pymobiledevice3 copied to clipboard

'OSError: [Errno 22] Invalid argument' while launching an app with the --stream flag

Open SergeyBibikov opened this issue 1 year ago • 2 comments
trafficstars

Test environment

  • Host OS version - Windows
  • IOs devices: Iphone SE3, version 15.6.1 Iphone 11, version 16.2

Describe the bug If I try launching an app with the --stream flag, using the following command pymobiledevice3 developer dvt launch com.my.package --stream, I get an OSError with the stack in the logs section after the app is launched

To Reproduce Steps to reproduce the behavior:

  1. Install an app on the device
  2. Launch it with the command pymobiledevice3 developer dvt launch {app bundle_id} --stream
  3. See the error in the terminal

Expected behavior An app is launched and it's output is streamed to the commandline

Logs


Process launched with pid 79286
Traceback (most recent call last):
  File "C:\Users\...\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\...\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\...\venv\Scripts\pymobiledevice3.exe\__main__.py", line 7, in <module>
    sys.exit(main())
  File "D:\...\venv\lib\site-packages\pymobiledevice3\__main__.py", line 101, in main
    cli()
  File "D:\...\venv\lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "D:\...\venv\lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "D:\...\venv\lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "D:\...\venv\lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "D:\...\venv\lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "D:\...\venv\lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "D:\...\venv\lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "D:\...\venv\lib\site-packages\pymobiledevice3\cli\cli_common.py", line 136, in wrap_callback_calling   
    callback(service_provider=service_provider, **kwargs)
  File "D:\...\venv\lib\site-packages\pymobiledevice3\cli\developer.py", line 203, in launch
    for output_received in process_control:
  File "D:\...\venv\lib\site-packages\pymobiledevice3\services\dvt\instruments\process_control.py", line 77, in __iter__
    yield OutputReceivedEvent.create(value)
  File "D:\...\venv\lib\site-packages\pymobiledevice3\services\dvt\instruments\process_control.py", line 18, in create
    date = datetime.datetime.fromtimestamp(message[2].value)
OSError: [Errno 22] Invalid argument

Additional context Maybe, it's worth handling not just ValueError but OSError as well in the 'create' method?

@dataclasses.dataclass
class OutputReceivedEvent:
    pid: int
    date: int
    message: str

    @classmethod
    def create(cls, message) -> 'OutputReceivedEvent':
        try:
            date = datetime.datetime.fromtimestamp(message[2].value)
        except ValueError: 
            date = None

        return cls(pid=message[1].value, date=date, message=message[0].value)

Printing the 'message' that causes the error gives the following output:

ListContainer: 
Container: 
    type = 2
    value = u'AK Info: Number of detected and '... (truncated, total 62)
Container:
    type = 3
    value = 79293
Container:
    type = 6
    value = 106543509355060

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

SergeyBibikov avatar Jan 25 '24 13:01 SergeyBibikov

Thanks for the very detailed issue report! I tried testing it with com.apple.mobilesafari on my mac but wasn't able to reproduce it - making me suspect this is a windows-specific issue.

Could you test adding the OSError handling resolves the issue and submit a PR?

doronz88 avatar Jan 26 '24 12:01 doronz88

Yeah, sure, thanks

SergeyBibikov avatar Jan 26 '24 15:01 SergeyBibikov