Skip to content

Commit

Permalink
Display error if bundle load fails (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
desyncr committed Dec 3, 2016
1 parent b5f7a03 commit 3936f16
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 58 deletions.
92 changes: 58 additions & 34 deletions bin/antigen.zsh
Expand Up @@ -294,7 +294,7 @@ antigen () {
if [[ $success -eq 0 ]]; then
printf "Done. Took %ds.\n" $took
else
echo -n "Error! See $_ANTIGEN_LOG_PATH.";
printf "Error! See \"$_ANTIGEN_LOG_PATH\".\n";
fi
fi

Expand Down Expand Up @@ -350,44 +350,64 @@ antigen () {
unfunction -- -set-default

}
# Load a given bundle by sourcing it.
#
# The function also modifies fpath to add the bundle path.
#
# Usage
# -antigen-load "bundle-url" ["location"] ["make_local_clone"] ["btype"]
#
# Returns
# Integer. 0 if success 1 if an error ocurred.
-antigen-load () {
local url="$1"
local loc="$2"
local make_local_clone="$3"
local btype="$4"
local src
local success=1

for src in $(-antigen-load-list "$url" "$loc" "$make_local_clone"); do
if [[ -d "$src" ]]; then
if (( ! ${fpath[(I)$location]} )); then
fpath=($location $fpath)
fi
if [[ -d "$src" ]]; then
if (( ! ${fpath[(I)$location]} )); then
fpath=($location $fpath)
fi
else
# Hack away local variables. See https://github.com/zsh-users/antigen/issues/122
# This is needed to seek-and-destroy local variable definitions *outside*
# function-contexts. This is done in this particular way *only* for
# interactive bundle/theme loading, for static loading -99.9% of the time-
# eval and subshells are not needed.
if [[ "$btype" == "theme" ]]; then
eval "$(cat $src | sed -Ee '/\{$/,/^\}/!{
s/^local //
}')"
else
# Hack away local variables. See https://github.com/zsh-users/antigen/issues/122
# This is needed to seek-and-destroy local variable definitions *outside*
# function-contexts. This is done in this particular way *only* for
# interactive bundle/theme loading, for static loading -99.9% of the time-
# eval and subshells are not needed.
if [[ "$btype" == "theme" ]]; then
eval "$(cat $src | sed -Ee '/\{$/,/^\}/!{
s/^local //
}')"
else
source "$src"
fi
source "$src"
fi
fi

success=0
done

# Return if there is an error loading bundle in order to avoid
# cluttering fpath with broken bundles
if [[ $success == 1 ]]; then
return $success
fi

local location
if $make_local_clone; then
location="$(-antigen-get-clone-dir "$url")/$loc"
location="$(-antigen-get-clone-dir "$url")/$loc"
else
location="$url/"
location="$url/"
fi
# Add to $fpath, for completion(s), if not in there already
if (( ! ${fpath[(I)$location]} )); then
fpath=($location $fpath)
fpath=($location $fpath)
fi

return $success
}
-antigen-parse-args () {
local key
Expand Down Expand Up @@ -483,6 +503,17 @@ antigen-apply () {
fi
unset _zdotdir_set
}
antigen-bundles () {
# Bulk add many bundles at one go. Empty lines and lines starting with a `#`
# are ignored. Everything else is given to `antigen-bundle` as is, no
# quoting rules applied.
local line
grep '^[[:space:]]*[^[:space:]#]' | while read line; do
# Using `eval` so that we can use the shell-style quoting in each line
# piped to `antigen-bundles`.
eval "antigen-bundle $line"
done
}
# Syntaxes
# antigen-bundle <url> [<loc>=/]
# Keyword only arguments:
Expand All @@ -496,22 +527,26 @@ antigen-bundle () {
local btype=plugin

if [[ -z "$1" ]]; then
echo "Must provide a bundle url or name."
echo "Antigen: Must provide a bundle url or name."
return 1
fi

eval "$(-antigen-parse-bundle "$@")"

# Ensure a clone exists for this repo, if needed.
# Ensure a clone exists for this repo, if needed.
if $make_local_clone; then
if ! -antigen-ensure-repo "$url"; then
# Return immediately if there is an error cloning
# Error message is displayed from -antigen-ensure-repo
return 1
fi
fi

# Load the plugin.
-antigen-load "$url" "$loc" "$make_local_clone" "$btype"
if ! -antigen-load "$url" "$loc" "$make_local_clone" "$btype"; then
echo "Antigen: Failed to load $btype."
return 1
fi

# Add it to the record.
local bundle_record="$url $loc $btype $make_local_clone"
Expand All @@ -520,17 +555,6 @@ antigen-bundle () {
_ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$bundle_record"
fi
}
antigen-bundles () {
# Bulk add many bundles at one go. Empty lines and lines starting with a `#`
# are ignored. Everything else is given to `antigen-bundle` as is, no
# quoting rules applied.
local line
grep '^[[:space:]]*[^[:space:]#]' | while read line; do
# Using `eval` so that we can use the shell-style quoting in each line
# piped to `antigen-bundles`.
eval "antigen-bundle $line"
done
}
antigen-cleanup () {

# Cleanup unused repositories.
Expand Down
10 changes: 7 additions & 3 deletions src/commands/bundle.zsh
Expand Up @@ -11,22 +11,26 @@ antigen-bundle () {
local btype=plugin

if [[ -z "$1" ]]; then
echo "Must provide a bundle url or name."
echo "Antigen: Must provide a bundle url or name."
return 1
fi

eval "$(-antigen-parse-bundle "$@")"

# Ensure a clone exists for this repo, if needed.
# Ensure a clone exists for this repo, if needed.
if $make_local_clone; then
if ! -antigen-ensure-repo "$url"; then
# Return immediately if there is an error cloning
# Error message is displayed from -antigen-ensure-repo
return 1
fi
fi

# Load the plugin.
-antigen-load "$url" "$loc" "$make_local_clone" "$btype"
if ! -antigen-load "$url" "$loc" "$make_local_clone" "$btype"; then
echo "Antigen: Failed to load $btype."
return 1
fi

# Add it to the record.
local bundle_record="$url $loc $btype $make_local_clone"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ensure-repo.zsh
Expand Up @@ -61,7 +61,7 @@
if [[ $success -eq 0 ]]; then
printf "Done. Took %ds.\n" $took
else
echo -n "Error! See $_ANTIGEN_LOG_PATH.";
printf "Error! See \"$_ANTIGEN_LOG_PATH\".\n";
fi
fi

Expand Down
58 changes: 39 additions & 19 deletions src/lib/load.zsh
@@ -1,39 +1,59 @@
# Load a given bundle by sourcing it.
#
# The function also modifies fpath to add the bundle path.
#
# Usage
# -antigen-load "bundle-url" ["location"] ["make_local_clone"] ["btype"]
#
# Returns
# Integer. 0 if success 1 if an error ocurred.
-antigen-load () {
local url="$1"
local loc="$2"
local make_local_clone="$3"
local btype="$4"
local src
local success=1

for src in $(-antigen-load-list "$url" "$loc" "$make_local_clone"); do
if [[ -d "$src" ]]; then
if (( ! ${fpath[(I)$location]} )); then
fpath=($location $fpath)
fi
if [[ -d "$src" ]]; then
if (( ! ${fpath[(I)$location]} )); then
fpath=($location $fpath)
fi
else
# Hack away local variables. See https://github.com/zsh-users/antigen/issues/122
# This is needed to seek-and-destroy local variable definitions *outside*
# function-contexts. This is done in this particular way *only* for
# interactive bundle/theme loading, for static loading -99.9% of the time-
# eval and subshells are not needed.
if [[ "$btype" == "theme" ]]; then
eval "$(cat $src | sed -Ee '/\{$/,/^\}/!{
s/^local //
}')"
else
# Hack away local variables. See https://github.com/zsh-users/antigen/issues/122
# This is needed to seek-and-destroy local variable definitions *outside*
# function-contexts. This is done in this particular way *only* for
# interactive bundle/theme loading, for static loading -99.9% of the time-
# eval and subshells are not needed.
if [[ "$btype" == "theme" ]]; then
eval "$(cat $src | sed -Ee '/\{$/,/^\}/!{
s/^local //
}')"
else
source "$src"
fi
source "$src"
fi
fi

success=0
done

# Return if there is an error loading bundle in order to avoid
# cluttering fpath with broken bundles
if [[ $success == 1 ]]; then
return $success
fi

local location
if $make_local_clone; then
location="$(-antigen-get-clone-dir "$url")/$loc"
location="$(-antigen-get-clone-dir "$url")/$loc"
else
location="$url/"
location="$url/"
fi
# Add to $fpath, for completion(s), if not in there already
if (( ! ${fpath[(I)$location]} )); then
fpath=($location $fpath)
fpath=($location $fpath)
fi

return $success
}
16 changes: 15 additions & 1 deletion tests/bundle.t
@@ -1,7 +1,7 @@
Should get a complain if no bundle is given as argument.

$ antigen-bundle
Must provide a bundle url or name.
Antigen: Must provide a bundle url or name.
[1]

Load plugin from master.
Expand All @@ -16,6 +16,20 @@ Load the plugin again. Just to see nothing happens.
$ hehe
hehe

Try to load an unexisting plugin from a cloned bundle.

$ antigen-bundle $PLUGIN_DIR wrong
Antigen: Failed to load plugin.
[1]

Try to install an unexisting bundle.

$ antigen-bundle https://127.0.0.1/bundle/unexisting
Installing bundle/unexisting... Error! See * (glob)
[1]
$ echo $fpath | grep -Pco test-plugin
1

Confirm there is still only one repository.

$ ls $ADOTDIR/repos | wc -l
Expand Down
4 changes: 4 additions & 0 deletions tests/theme.t
Expand Up @@ -3,3 +3,7 @@ Load the theme explicitly.
$ antigen-theme $PLUGIN_DIR silly &> /dev/null
$ echo "$PS1"
prompt>

$ antigen-theme $PLUGIN_DIR wrong
Antigen: Failed to load theme.
[1]

0 comments on commit 3936f16

Please sign in to comment.