Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error exit code on success #82

Open
susuhahnml opened this issue Mar 25, 2022 · 3 comments
Open

Error exit code on success #82

susuhahnml opened this issue Mar 25, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@susuhahnml
Copy link

susuhahnml commented Mar 25, 2022

Hi! I am getting an exit status code of 1 for sucess. Is this intended? I am running your example:

% Probabilistic facts:
0.5::heads1.
0.6::heads2.

% Rules:
twoHeads :- heads1, heads2.

% Queries:
query(heads1).
query(heads2).
query(twoHeads).

And just running:

>>> problog coin.pl -v
[INFO] Output level: INFO
[INFO] Propagating evidence: 0.0000s
[INFO] Grounding: 0.0016s
[INFO] Cycle breaking: 0.0001s
[INFO] Clark's completion: 0.0000s
[INFO] DSharp compilation: 0.6023s
[INFO] Total time: 0.6084s
  heads1:	0.5
  heads2:	0.6
twoHeads:	0.3

>>> echo $?
1
@rmanhaeve rmanhaeve self-assigned this Mar 25, 2022
@rmanhaeve rmanhaeve added the bug Something isn't working label Mar 25, 2022
@Mezzenilium
Copy link

Mezzenilium commented Apr 17, 2022

You are right, Problog always seems to end with the code: 1, whether the source of the interpreted program is correct or flawed.
I noticed this on my local version of Problog installed on a Linux PC.

Program with error :

(False, ParseError('% Probabilistic facts:\n0.5::heads1.\n0.6::heads2.\n\n% Rules:\ntwoHeads :- heads1, heads2\n\n%    Queries:\nquery(heads1).\nquery(heads2).\nquery(twoHeads).\n', 'Expected binary operator', 98))
------------------
(program exited with code: 1)
Press return to continue

Program without error :

(True, {heads2: 0.6000000000000001, heads1: 0.5000000000000001, twoHeads: 0.30000000000000004})
 ------------------
(program exited with code: 1)
Press return to continue

The convention that a function should return 0 when its execution has been nominal has its origin in the C language. Indeed Problog seems to not respect this convention of behaviour.

In fact even when I intentionally introduced a syntax error into the code of the program written in Problog, the behaviour of the Problog interpreter was correct because it detected and reported the presence of this error.
Otherwise, I have not yet encountered a case where Problog does not do what it is supposed to do.

VincentDerk added a commit that referenced this issue Jun 29, 2022
The probability.main task returns an exit code (cf. change Robin to fix public issue #82) rather than a result. Some tests erroneously relied on it returning the result instead of exit code. This fix addresses that. A similar approach should be taken still for the other problog tasks!
VincentDerk added a commit that referenced this issue Jun 29, 2022
Mainly bugfixes, but we also changed the Term's hashing method. If this proofs to be worse, we may reconsider switching back later.

* Bugfix library/string.py::str2lst (public issue #84)
* Bugfix return exit code instead of result - only for probability task atm (public issue #82)
* Critical Bugfix in dSharp library (compiled CNF theory with too long clauses could yield wrong result)
* Bugfix in pypl related to lists (private issue #16)
* Minor improvements to LFI
* Changed Term's hashing method
@VincentDerk
Copy link
Collaborator

This should be fixed in version v2.2.3 for the probability task (relevant commit b719042).

For the other tasks (mpe, sample, ...), it is still on the internal to do list.

@sdemjanenko
Copy link

Instead of having the CLI script call sys.exist(main()), propagating anything main() returns as the exit code, it may be easier to maintain if sys.exit is called with a non-zero code in an except block. If one wants to control the non-zero code, then perhaps one can raise a specific class of exception with the desired code set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants