Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 551190 - /ebuild-writing/eapi/ example uses nonfatal incorrectly
Summary: /ebuild-writing/eapi/ example uses nonfatal incorrectly
Status: RESOLVED FIXED
Alias: None
Product: Documentation
Classification: Unclassified
Component: Devmanual (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Devmanual Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: bad-nonfatal
  Show dependency tree
 
Reported: 2015-06-04 09:43 UTC by Michał Górny
Modified: 2017-09-25 04:27 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch to replace the example (0001-Replace-nonfatal-example-with-something-correct.patch,1.62 KB, patch)
2015-06-07 12:45 UTC, Michał Górny
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2015-06-04 09:43:10 UTC
https://devmanual.gentoo.org/ebuild-writing/eapi/index.html#eapi=4

src_install() {
	emake DESTDIR="${D}" install
	nonfatal dodoc ChangeLog README
}

This is incorrect since the exit status is ignored. A better example would be to provide src_test() with custom error handling (see dev-vcs/git), e.g.:

src_test() {
	if ! nonfatal emake check; then
		# do some log processing or something
		die "Tests failed"
	fi
}
Comment 1 Ulrich Müller gentoo-dev 2015-06-04 10:04:19 UTC
Patch?
Comment 2 Markos Chandras (RETIRED) gentoo-dev 2015-06-04 20:20:14 UTC
reading the PMS itself, I am confused on when we actually need to use the nonfatal helper. Why is it bad to use it with dodoc etc? Is it only suitable for helpers that actually do some building themselves (ie emake)?
Comment 3 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2015-06-04 21:42:19 UTC
(In reply to Markos Chandras from comment #2)
> reading the PMS itself, I am confused on when we actually need to use the
> nonfatal helper. Why is it bad to use it with dodoc etc? Is it only suitable
> for helpers that actually do some building themselves (ie emake)?

It's not about what the helper does but how the result is used. Basically nonfatal replaces automatic termination with exit status return. You are expected to use the exit status -- not to ignore it.

Examples of nonfatal uses:

a. replacing 'die' message with a better one,

b. doing some post-failure test log processing/printing before 'die',

c. killing daemons spawned during test phase before 'die',

d. doing some compile tests in which failure triggers another code path.

As you can see, in all of those cases the ebuild checks for failure and handles it.


Now, the dodoc example is bad because there's no valid use for the failure status. In particular:

1. dodoc can fail if the files don't exist. But if they don't exist, they shouldn't be passed to dodoc in the first place. Then, nonfatal is used to allow incorrect code to work rather than fixing it (though it will throw warnings at user).

2. dodoc can fail if copying failed for any other reason. But if it fails for any other reason, there's something seriously wrong going on and we definitely don't want to proceed like nothing happened (and hope something else will fail and terminate the build for us).

3. Unless I'm mistaken, PMS doesn't specify how dodoc behaves after first failure. In particular, if ChangeLog does not exist, the remaining files may not be processed at all.
Comment 4 Markos Chandras (RETIRED) gentoo-dev 2015-06-05 20:07:16 UTC
Hmm I see then. Although I don't find it particularly disturbing to use nonfatal with dodoc and friends but I agree it can mask real bugs. Sounds like you need to write a patch for us since you can explain the situation much better than I would do.
Comment 5 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2015-06-07 12:45:39 UTC
Created attachment 404740 [details, diff]
Patch to replace the example

How about this one? It uses the code from paludis.
Comment 6 Larry the Git Cow gentoo-dev 2017-09-25 04:27:13 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=b5f6752aab9664d4672c476065467039b73b2f7b

commit b5f6752aab9664d4672c476065467039b73b2f7b
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2015-06-07 12:44:00 +0000
Commit:     Göktürk Yüksek <gokturk@gentoo.org>
CommitDate: 2017-09-25 04:25:12 +0000

    ebuild-writing/eapi: Replace nonfatal example with something correct
    
    Replace the nonfatal example from a poor programming practice (nonfatal
    dodoc) to a code collecting logs for test failures. Based on an old
    version of sys-apps/paludis.
    
    Closes: https://bugs.gentoo.org/551190

 ebuild-writing/eapi/text.xml | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)