Re: [pacman-dev] [PATCH 1/2] makepkg: implement error codes

2017-09-14 Thread Allan McRae
On 15/09/17 08:58, ivy.fos...@gmail.com wrote:
> index 20e9dd7e..8ef3c48d 100644
> --- a/scripts/makepkg.sh.in
> +++ b/scripts/makepkg.sh.in
> @@ -87,6 +87,26 @@ SPLITPKG=0
>  SOURCEONLY=0
>  VERIFYSOURCE=0
>  
> +# Errors
> +E_OK=0
> +E_FAIL=1 # Generic error
> +# exit code 2 reserved by bash for misuse of shell builtins
> +E_CONFIG_ERROR=3
> +E_INVALID_OPTION=4
> +E_BUILD_FAILED=5
> +E_PACKAGE_FAILED=6
> +E_MISSING_FILE=7
> +E_MISSING_PKGDIR=8
> +E_INSTALL_DEPS_FAILED=9
> +E_REMOVE_DEPS_FAILED=10
> +E_ROOT=11
> +E_FS_PERMISSIONS=12
> +E_PKGBUILD_ERROR=13
> +E_ALREADY_BUILT=14
> +E_INSTALL_FAILED=15
> +E_MISSING_MAKEPKG_DEPS=16
> +E_PRETTY_BAD_PRIVACY=17

The last one is my favourite error code ever!


My only requested change is to define the error codes in
scripts/libmakepkg/util/error.sh.  I'd like to keep from adding chunks
to makepkg that would easily be placed in libmakepkg.

Thanks,
Allan


[pacman-dev] RFC: makepkg errors

2017-09-14 Thread Ivy Foster
I've implemented a patch that allows makepkg to return discrete error
values for different errors. This is based on the comments scattered
throughout indicating that at some point, somebody intended to
implement this.

As a side benefit, it also closes [FS#54204][], since being able to
return a recognizable error from a failed install_package means that
we can still do clean-up even if this function fails.

Cons: That's a lot of different types of error.

As always, I welcome your critiques!

iff

Links:

[FS#54204]: https://bugs.archlinux.org/task/54204


[pacman-dev] [PATCH 2/2] makepkg: clarify error when user passes -F

2017-09-14 Thread ivy . foster
From: Ivy Foster 

---
 scripts/makepkg.sh.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 8ef3c48d..a0d6f8e7 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1462,7 +1462,7 @@ catastrophic damage to your system.")" "makepkg"
fi
 else
if [[ -z $FAKEROOTKEY ]]; then
-   error "$(gettext "Do not use the %s option. This option is only 
for use by %s.")" "'-F'" "makepkg"
+   error "$(gettext "Do not use the %s option. This option is only 
for internal use by %s.")" "'-F'" "makepkg"
exit $E_INVALID_OPTION
fi
 fi
-- 
2.14.1


[pacman-dev] [PATCH 1/2] makepkg: implement error codes

2017-09-14 Thread ivy . foster
From: Ivy Foster 

For your convenience, makepkg now has 16 distinct ways to fail.
---
 doc/makepkg.8.txt |  60 ++
 scripts/makepkg.sh.in | 140 --
 2 files changed, 139 insertions(+), 61 deletions(-)

diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt
index 2dff1b19..224292a2 100644
--- a/doc/makepkg.8.txt
+++ b/doc/makepkg.8.txt
@@ -272,6 +272,66 @@ See linkman:makepkg.conf[5] for more details on 
configuring makepkg using the
 'makepkg.conf' file.
 
 
+Errors
+--
+On exit, makepkg will return one of the following error codes.
+
+**E_OK**=0::
+   Normal exit condition.
+
+**E_FAIL**=1::
+   Unknown cause of failure.
+
+// Exit code 2 is reserved by bash for misuse of shell builtins
+
+**E_CONFIG_ERROR**=3::
+   Error in configuration file.
+
+**E_INVALID_OPTION**=4::
+   User specified an invalid option
+
+**E_BUILD_FAILED**=5::
+   Error in PKGBUILD build function.
+
+**E_PACKAGE_FAILED**=6::
+   Failed to create a viable package.
+
+**E_MISSING_FILE**=7::
+   A source or auxiliary file specified in the PKGBUILD is
+   missing.
+
+**E_MISSING_PKGDIR**=8::
+   The PKGDIR is missing.
+
+**E_INSTALL_DEPS_FAILED**=9::
+   Failed to install dependencies.
+
+**E_REMOVE_DEPS_FAILED**=10::
+   Failed to remove dependencies.
+
+**E_ROOT**=11::
+   User attempted to run makepkg as root.
+
+**E_FS_PERMISSIONS**=12::
+   User lacks permissions to build or install to a given
+   location.
+
+**E_PKGBUILD_ERROR**=13::
+   Error parsing PKGBUILD.
+
+**E_ALREADY_BUILT**=14::
+   A package has already been built.
+
+**E_INSTALL_FAILED**=15::
+   The package failed to install.
+
+**E_MISSING_MAKEPKG_DEPS**=16::
+   Programs necessary to run makepkg are missing.
+
+**E_PRETTY_BAD_PRIVACY**=17::
+   Error signing package.
+
+
 See Also
 
 linkman:makepkg.conf[5], linkman:PKGBUILD[5], linkman:pacman[8]
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 20e9dd7e..8ef3c48d 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -87,6 +87,26 @@ SPLITPKG=0
 SOURCEONLY=0
 VERIFYSOURCE=0
 
+# Errors
+E_OK=0
+E_FAIL=1 # Generic error
+# exit code 2 reserved by bash for misuse of shell builtins
+E_CONFIG_ERROR=3
+E_INVALID_OPTION=4
+E_BUILD_FAILED=5
+E_PACKAGE_FAILED=6
+E_MISSING_FILE=7
+E_MISSING_PKGDIR=8
+E_INSTALL_DEPS_FAILED=9
+E_REMOVE_DEPS_FAILED=10
+E_ROOT=11
+E_FS_PERMISSIONS=12
+E_PKGBUILD_ERROR=13
+E_ALREADY_BUILT=14
+E_INSTALL_FAILED=15
+E_MISSING_MAKEPKG_DEPS=16
+E_PRETTY_BAD_PRIVACY=17
+
 export SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:-$(date +%s)}
 
 PACMAN_OPTS=()
@@ -130,7 +150,7 @@ clean_up() {
return
fi
 
-   if (( ! EXIT_CODE && CLEANUP )); then
+   if (( (EXIT_CODE == E_OK || EXIT_CODE == 15) && CLEANUP )); then
local pkg file
 
# If it's a clean exit and -c/--clean has been passed...
@@ -184,7 +204,7 @@ update_pkgver() {
newpkgver=$(run_function_safe pkgver)
if ! check_pkgver "$newpkgver"; then
error "$(gettext "pkgver() generated an invalid version: %s")" 
"$newpkgver"
-   exit 1
+   exit $E_PKGBUILD_ERROR
fi
 
if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then
@@ -192,7 +212,7 @@ update_pkgver() {
if ! @SEDINPLACE@ "s:^pkgver=[^ ]*:pkgver=$newpkgver:" 
"$BUILDFILE"; then
error "$(gettext "Failed to update %s from %s 
to %s")" \
"pkgver" "$pkgver" "$newpkgver"
-   exit 1
+   exit $E_PKGBUILD_ERROR
fi
@SEDINPLACE@ "s:^pkgrel=[^ ]*:pkgrel=1:" "$BUILDFILE"
source_safe "$BUILDFILE"
@@ -209,7 +229,7 @@ update_pkgver() {
 missing_source_file() {
error "$(gettext "Unable to find source file %s.")" "$(get_filename 
"$1")"
plain "$(gettext "Aborting...")"
-   exit 1 # $E_MISSING_FILE
+   exit $E_MISSING_FILE
 }
 
 run_pacman() {
@@ -263,7 +283,7 @@ handle_deps() {
 
if ! run_pacman -S --asdeps "${deplist[@]}"; then
error "$(gettext "'%s' failed to install missing 
dependencies.")" "$PACMAN"
-   exit 1 # TODO: error code
+   exit $E_INSTALL_DEPS_FAILED
fi
fi
 
@@ -284,12 +304,12 @@ resolve_deps() {
# deplist cannot be declared like this: local deplist=$(foo)
# Otherwise, the return value will depend on the assignment.
local deplist
-   deplist=($(check_deps "$@")) || exit 1
+   deplist=($(check_deps "$@")) || exit $E_INSTALL_DEPS_FAILED
[[ -z $deplist ]] && return $R_DEPS_SATISFIED
 
if handle_deps "${deplist[@]}"; then
# check deps again to make sure they were resolved
-   de