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: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: framework (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium enhancement
Assignee: Justin L
URL: https://wiki.documentfoundation.org/Q...
Whiteboard: target:26.2.0
Keywords:
Depends on:
Blocks: Commandline
  Show dependency treegraph
 
Reported: 2022-03-30 15:23 UTC by Timur
Modified: 2025-07-02 12:17 UTC (History)
6 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 Comment hidden (off-topic)
Comment 10 Mike Kaganski 2022-07-05 14:20:24 UTC Comment hidden (off-topic)
Comment 11 Timur 2022-07-07 13:18:40 UTC Comment hidden (off-topic)
Comment 12 QA Administrators 2025-03-12 03:12:27 UTC Comment hidden (obsolete, spam)
Comment 13 Justin L 2025-03-13 16:31:13 UTC
(In reply to Stephan Bergmann from comment #7)
> > How a user would know if some previous ones succeeded?
> Why would we care? 
+1

> EXIT_FAILURE is all that the C/C++ standards portably offer.
So IMHO that makes it a simple decision - the choice is already made for us.
Comment 14 Mike Kaganski 2025-06-09 07:00:04 UTC
So a code pointer:

RequestHandler::ExecuteCmdLineRequests processes aRequest.aConversionParams. It happens in the main instance of the program. We need to keep track of each of the processed conversion results. When it's initiated by its own main() (through Desktop::OpenClients), it needs to make sure, that when main() ends, it returns the appropriate code. When it's called from IpcThread::process, the end result must be transferred back to the calling instances.
Comment 15 Justin L 2025-06-26 23:12:15 UTC
proposed patch at https://gerrit.libreoffice.org/c/core/+/187075
Comment 16 Mike Kaganski 2025-06-27 09:47:44 UTC
A code pointer for transferring status to the external caller:

desktop/unx/source/start.c : send_args (Linux?) / desktop/source/app/officeipcthread.cxx : PipeIpcThread::enable (general / windows) sends args and receives the status; it checks if it got "InternalIPC::ProcessingDone". We could return other strings instead (just need to fit into the length?).

Returning the status happens in desktop/source/app/officeipcthread.cxx : PipeIpcThread::execute; and there we can check the new "GetAllSucceeded".
Comment 17 Commit Notification 2025-07-01 14:00:43 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/633ce6b17007ea401aa5c013ec14308b14596d31

tdf#148275: EXIT_FAILURE if any cmdline operation fails

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 18 Justin L 2025-07-02 12:06:28 UTC
(In reply to Mike Kaganski from comment #16)
> A code pointer for transferring status to the external caller:
I'm not sure under what steps-to-reproduce this would be processed, so I haven't done anything more than a code-read. Assuming this can be made into a separate bug report if desired.

> Returning the status happens in desktop/source/app/officeipcthread.cxx :
> PipeIpcThread::execute; and there we can check the new ...
m_handler->mFlags & DispatchRequestFlags::WithError);
I hope that my "design" allows this to be nicely extended in case more granularity or other kinds of "result flags" are desired in the future.


Marking this bug as fixed.
Comment 19 Timur 2025-07-02 12:17:07 UTC
This is IMO worth ReelaseNotes.