Bug 148275 - Set error status to non 0 if headless conversion failed or aborted
Summary: Set error status to non 0 if headless conversion failed or aborted
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: framework (show other bugs)
Version:
(earliest affected)
7.4.0.0 alpha0+
Hardware: All All
: medium normal
Assignee: Not Assigned
URL: https://wiki.documentfoundation.org/Q...
Whiteboard:
Keywords:
Depends on:
Blocks: Commandline
  Show dependency treegraph
 
Reported: 2022-03-30 15:23 UTC by Timur
Modified: 2023-03-12 09:30 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Timur 2022-03-30 15:23:27 UTC
If headless conversion failed or aborted, as seen with examples from bug 97392 or bug 148253, it still returns error status 0. It should return some specific error.

To reproduce, run a script with:
/instdir/program/soffice  --headless --convert-to xlsx  password-to-open.ods
echo "status is $?"
Comment 1 Mike Kaganski 2022-04-01 08:58:27 UTC
I agree that we need to introduce a "*some* commands failed" return code. Note that a command line is not necessarily a simple "soffice file", but it may have multiple files, and multiple commands (allowing one to print several files, and convert several files at the same command line). So it is possible that only *some* of them failed. Additionally, failures are different: some may be absent; some may be corrupt, or couldn't be exported using unavailable export filters ... so it is not a simple task. The "some error processing some file" is very different from other kinds of failures (that set the error codes) - like crashes, restart requests, etc.

Interesting, what is a convention commonly used in such a case?
Comment 2 Timur 2022-04-01 11:10:48 UTC
Automated bibisect cannot be done now for those cases. 
I think that there should be multiple status errors for different cases. 
Why not start for a simple and most common case of single conversion that fails or is aborted or source file not found. 
These are reserved Bash exit codes https://tldp.org/LDP/abs/html/exitcodes.html.
Comment 3 Mike Kaganski 2022-04-01 11:35:19 UTC Comment hidden (obsolete)
Comment 4 Stephan Bergmann 2022-04-01 12:03:23 UTC
(In reply to Mike Kaganski from comment #3)
> Stephan, do you know if that's feasible? IIRC, we can return rather
> arbitrary stuff coming from some external APIs, so can we declare some
> private error codes range, and make it public API?

I don't understand the above.

Why not keep things simple and if any --convert-to operation fails call std::exit with EXIT_FAILURE rather than EXIT_SUCCESS.
Comment 5 Mike Kaganski 2022-04-01 12:47:52 UTC
(In reply to Stephan Bergmann from comment #4)
> Why not keep things simple and if any --convert-to operation fails call
> std::exit with EXIT_FAILURE rather than EXIT_SUCCESS.

If that's an option - then great!
Do you mean "std::exit after the first failure"?
How a user would know if some previous ones succeeded?

I suppose that EXIT_FAILURE is more about inability to run. But having another dedicated value for the case would likely make it simple enough, and still distinguishable?
Comment 6 Mike Kaganski 2022-04-01 12:50:06 UTC
(In reply to Mike Kaganski from comment #5)
> I suppose that EXIT_FAILURE is more about inability to run.

... as *we* use it, not implying it's what stdlib means :-)
Comment 7 Stephan Bergmann 2022-04-01 13:08:56 UTC
(In reply to Mike Kaganski from comment #5)
> Do you mean "std::exit after the first failure"?

What I had thought about was to change the code so that where apparently it currently unconditionally does the equivalent of std::exit(EXIT_SUCCESS), make it do the equivalent of std::exit(EXIT_FAILURE) if any of those --convert-to operations had failed (after processing all of them).  But stopping after the first failing one might be fine as well.

> How a user would know if some previous ones succeeded?

Why would we care?  If the user wants to have more precise information about which operations succeeded or failed, they could either call soffice for each of them individually, or they could presumably use the UNO API to do the same operations with more fine grained error reporting.

> I suppose that EXIT_FAILURE is more about inability to run. But having
> another dedicated value for the case would likely make it simple enough, and
> still distinguishable?

EXIT_FAILURE is all that the C/C++ standards portably offer.  It traditionally translates to an exit status of 1 on Posix (and Windows), which traditionally represents a catch-all "failure" status in those environments.  I still fail to see a need for a more specific exit status for "some --convert-to operation failed" in those environments.
Comment 8 Timur 2022-04-01 13:33:02 UTC
I think it's safe to put New. 
Anything is better than current 0 so a single error would be good and this bug could be closed.

As for why more would be better, I listed some cases: conversion fails or is aborted or source file not found or source password protected.
Comment 9 Timur 2022-07-05 13:46:20 UTC
I noticed another aspect of this. 
soffice-convert && app-to-open doesn't work, at least in Windows, because soffice immediately gives 0 for %errorlevel% so app-to-open opens immediately after soffice-convert is run, when no converted file exists.
Comment 10 Mike Kaganski 2022-07-05 14:20:24 UTC
(In reply to Timur from comment #9)
What is "soffice-convert"? Is the proper console mode `soffice.com` used, that is intended to work properly in command line and batch mode [1], and allows use of the program name without extension from command line?

[1] https://mikekaganski.wordpress.com/2018/11/21/proper-console-mode-for-libreoffice-on-windows/
Comment 11 Timur 2022-07-07 13:18:40 UTC
(In reply to Mike Kaganski from comment #10)
> (In reply to Timur from comment #9)
> What is "soffice-convert"
That was meant to be: soffice.exe --headless --convert-to ext

> Is the proper console mode `soffice.com` used,
> that is intended to work properly in command line and batch mode [1], and
> allows use of the program name without extension from command line?
No, I just learned about it. And really it's working properly, it waits for a command to finish to continue with the next one. Thanks.