Gentoo Archives: gentoo-dev

From: Chris Houser <chouser@×××××××××××××××××.net>
To: gentoo-dev@××××××××××.org
Subject: [gentoo-dev] how to use die() and assert_true_or_die()
Date: Sun, 12 Aug 2001 02:42:46
Message-Id: 20010812044153.A187580@plato.zk3.dec.com
In Reply to: Re: [gentoo-dev] \" fixes by Mikael Hallendal
1 Okay, here's some quick documentation on Aron Griffis' new "exception
2 handling" functions. I am confidant Aron will correct any mistakes I
3 make here.
4
5
6 Although try() still exists, there are two new functions available that
7 are much better. For a details on why try() should be deprecated, and
8 for more examples of how to use these functions in less common
9 situations, see Aron's earlier messages. Note that these new functions
10 give more detailed error messages than try() did.
11
12 --- Simple die() --
13 In most cases where you used to use try(), you should now use die().
14 For example, the Development HOWTO has the following:
15
16 try ./configure ${myvar} --prefix=/usr --host=${CHOST}
17
18 To use die() instead, use this syntax:
19
20 ./configure ${myvar} --prefix=/usr --host=${CHOST} || die
21
22 You may optionally include a message to describe what failed:
23
24 ./configure ${myvar} --prefix=/usr --host=${CHOST} || die "Bad configure"
25
26
27 --- Pipelined die() --
28 If you want to check the results of a pipelined command, you may
29 only need to attach die to the last command. This is often sufficient
30 because if commands earlier in the pipeline fail, later commands often
31 fail as well:
32
33 bzip2 -dc ${DISTDIR}/patch-${KV}.bz2 | patch -p0 || die
34
35 However, it is possible for earlier commands to fail and for later ones
36 to succeed anyway. This example, for instance, will appear to succeed
37 if the patch file does not exists. So, to make sure your .ebuild
38 catches this type of situation, you can attach die to each command of
39 the pipeline:
40
41 ( bzip2 -dc ${DISTDIR}/patch-${KV}.bz2 || die ) | ( patch -p0 || die )
42
43
44 --- assert_true_or_die() --
45 This function is meant to be used when you don't want to make long
46 commands even longer by adding the "|| die" syntax. To use it, simply
47 add the function call after the command you want to check:
48
49 ./configure ${myvar} --prefix=/usr --host=${CHOST}
50 assert_true_or_die "Bad configure"
51
52 Note that using the function this way doesn't allow you to check
53 multiple commands in a pipeline the way die() does.
54
55 --Chouser

Replies

Subject Author
Re: [gentoo-dev] how to use die() and assert_true_or_die() Daniel Robbins <drobbins@g.o>