Repository: xonsh/xonsh

Issue:
xonsh: error: Source failed:
I get similar errors as in #1134 

In 0.6.0 I used to define my bash as foreign shell and import .bashrc this way.
Using source-foreign (doesnt matter if bash or zsh both dont work):

```
$DOTFILES = $HOME+"/repo/github/dotfiles"
for file in !(ls $DOTFILES/source/*):
    source-zsh --overwrite-alias @(file)
```

I get: ` xonsh: error: Source failed: /Users/mq/repo/github/dotfiles/source/30_aliases.sh`

Contents of `30_aliases.sh`

```
alias lah='ls -lah'     # list all files in human readable form
alias duh='du -hd 1'    # show space consumed by

alias untar='tar -xzf'

alias cd..='cd ..'

alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
```

```
+------------------+----------------------+
| xonsh            | 0.6.2                |
| Git SHA          | bcee4fe8             |
| Commit Date      | Apr 23 20:07:32 2018 |
| Python           | 3.6.3                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 1.0.15               |
| shell type       | prompt_toolkit       |
| pygments         | 2.2.0                |
| on posix         | True                 |
| on linux         | False                |
| on darwin        | True                 |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
+------------------+----------------------+
```


Discussion:
Thanks for reporting @Ohjeah.  

I can reproduce the problem using `source-zsh` but `source-bash` works on my end.
`source-bash ` works for me only outside the `xonshrc` file.

I basically have the same source-block in my `bashrc` file:

```
for file in $DOTFILES/source/*; do
  source "$file"
done
```

Does this interfere with `source-bash` in any way?


Hey @Ohjeah -- if I understand correctly, you are sourcing a `bashrc` file that itself sources other dotfiles?  That may cause problems -- can you try to source them directly from xonsh?
No, I source the files directly from xonsh. But if I understood correctly, source-foreign will create and execute a temporary script? Hence my question. 
I think the error is actually in your loop.  `for line in !(cmd)` will return lines, **including line endings (ie `"\n"`).**  So you are trying to source "/Users/mq/repo/github/dotfiles/source/30_aliases.sh\n", which isn't a real file.  

Now, you could do `@(file.strip())`, but I would recommend actually using ```g`$DOTFILES/source/*` ```  to loop over a glob of file names.  There is no need to use a subprocess here.  Namely, I'd use:

```
$DOTFILES = $HOME+"/repo/github/dotfiles"
for file in g`$DOTFILES/source/*`:
    source-zsh --overwrite-alias @(file)
```

See http://xon.sh/tutorial.html#advanced-path-search-with-backticks for more information on file name matching
The error message for source-foreign should be improved. Thanks for bringing this up @Ohjeah!

Resolving patch:
diff --git a/xonsh/aliases.py b/xonsh/aliases.py
--- a/xonsh/aliases.py
+++ b/xonsh/aliases.py
@@ -239,7 +239,8 @@ def source_foreign(args, stdin=None, stdout=None, stderr=None):
         if ns.dryrun:
             return
         else:
-            msg = 'xonsh: error: Source failed: {}\n'.format(ns.prevcmd)
+            msg = 'xonsh: error: Source failed: {0!r}\n'.format(ns.prevcmd)
+            msg += 'xonsh: error: Possible reasons: File not found or syntax error\n'
             return (None, msg, 1)
     # apply results
     env = builtins.__xonsh_env__


Test patch: