KBNLresearch / ipmlab

Image Portable Media Like A Boss
Apache License 2.0
3 stars 1 forks source link

Aaru fails with exit code 1 if Ipmlab is run from PyPi package #23

Open bitsgalore opened 2 years ago

bitsgalore commented 2 years ago

This happens under Linux Mint 19.3. No useful info from Aaru log/error log.

However, everything works fine when running Ipmlab from local script (launcher in Git repo). I suspect this has something to do with Aaru trying to write to stdout/stderr (which is shown in terminal for local script), and fact that stdout and stderr are not captured. But capturing stdout/stderr leads to the problems described here:

https://github.com/KBNLresearch/ipmlab/issues/16

bitsgalore commented 2 years ago

Update - if the packaged version of Ipmlab is launched from the terminal Aaru works as expected. So issue is definitely caused by Aaru's stdout/stderr handliing.

Does this help:

https://stackoverflow.com/questions/2804543/read-subprocess-stdout-line-by-line

bitsgalore commented 2 years ago

Update, changed call to Aaru to this (this sends all stout/stderr to a file):

        with open('/home/johan/test/ipmlab.stdout', "w") as outfile:
            sub.run(args, stderr=sub.STDOUT, stdout=outfile)

Result (from /ipmlab.stdout):

aaru 5.3.1
Copyright © 2011-2022 Natalia Portillo

Output image format: Raw Disk Image.
Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.ArgumentOutOfRangeException: Count cannot be less than zero. (Parameter 'count')
   at System.String.Ctor(Char c, Int32 count)
   at Aaru.Progress.ClearCurrentConsoleLine()
   at Aaru.Progress.UpdateStatus(String text)
   at Aaru.Core.Devices.Dumping.Dump.Start() in /home/claunia/Development/Aaru/Aaru/Aaru.Core/Devices/Dumping/Dump.cs:line 214
   at Aaru.Commands.Media.DumpMediaCommand.Invoke(Boolean debug, Boolean verbose, String cicmXml, String devicePath, Boolean resume, String encoding, Boolean firstPregap, Boolean fixOffset, Boolean force, Boolean metadata, Boolean trim, String outputPath, String options, Boolean persistent, UInt16 retryPasses, UInt32 skip, Byte speed, Boolean stopOnError, String format, String subchannel, Boolean private, Boolean fixSubchannelPosition, Boolean retrySubchannel, Boolean fixSubchannel, Boolean fixSubchannelCrc, Boolean generateSubchannels, Boolean skipCdiReadyHole, Boolean eject, UInt32 maxBlocks, Boolean useBufferedReads, Boolean storeEncrypted, Boolean titleKeys)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__19_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass21_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__20_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__18_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__10_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__9_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseExceptionHandler>b__0>d.MoveNext()
bitsgalore commented 2 years ago

Possibly (un?)related :

https://github.com/robotframework/robotframework/issues/4173

bitsgalore commented 2 years ago

Todo: make minimal demo script that demonstrates the issue.

bitsgalore commented 2 years ago

Update, in Windows, Ipmlab launches Aaru in a separate console Window (which closes automatically upon completion:

VirtualBox_Windows 10_15_09_2022_18_44_43

A bit ugly, but at least it works.

bitsgalore commented 2 years ago

Another twist to this - in Windows, setting "shell=True" gets rid of the terminal, and Aaru completes normally (in Linux this won't even run!):

 # Run Aaru as subprocess
 p = sub.run(args, shell=True)

In another interesting twist, if I change the above code and use the more low-level Popen method:

p = sub.Popen(args, shell=True)

In this case Ipmlab doesn't wait for aaru to complete. Remedied by adding:

output, errors = p.communicate()

Provisional solution: added OS-specific shell flag that makes sure everything at least works under Windows: https://github.com/KBNLresearch/ipmlab/commit/92f5a4eedb3f23d0d722efd7b504e66cbc49290b.

In Linux, Aaru execution only works if ipmlab is launched from a terminal (launching from menu shortcut will result in failure).

bitsgalore commented 2 years ago

Opened Aaru issue for this:

https://github.com/aaru-dps/Aaru/issues/749

All works without problems on Linux Mint with the binaries of the Aaru 6.0 development version!

bitsgalore commented 6 months ago

Fixed now in Aaru:

https://github.com/aaru-dps/Aaru/issues/749