Repository: xonsh/xonsh

Issue:
bug: no error message in cd when $THREAD_SUBPROCS is False
<!--- Provide a general summary of the issue in the Title above -->
<!--- If you have a question along the lines of "How do I do this Bash command in xonsh"
please first look over the Bash to Xonsh translation guide: https://xon.sh/bash_to_xsh.html
If you don't find an answer there, please do open an issue! -->

## xonfig

<details>

```
+------------------+----------------------+
| xonsh            | 0.13.0               |
| Python           | 3.10.5               |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 3.0.30               |
| shell type       | prompt_toolkit       |
| history backend  | json                 |
| pygments         | 2.12.0               |
| on posix         | True                 |
| on linux         | True                 |
| distro           | arch                 |
| on wsl           | False                |
| on darwin        | False                |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
| xontrib 1        | sh                   |
| xontrib 2        | cd                   |
| xontrib 3        | z                    |
| xontrib 4        | bashisms             |
| xontrib 5        | whole_word_jumping   |
| xontrib 6        | voxapi               |
| xontrib 7        | vox                  |
| RC file 1        | /home/user/.xonshrc |
+------------------+----------------------+
```
</details>

## Expected Behavior
<!--- Tell us what should happen -->
When I use `cd a_nonexistent_directory`, I expect the error message `cd: no such file or directory: a_nonexistent_directory`

## Current Behavior
<!--- Tell us what happens instead of the expected behavior -->
<!--- If part of your bug report is a traceback, please first enter debug mode before triggering the error
To enter debug mode, set the environment variable `XONSH_DEBUG=1` _before_ starting `xonsh`.
On Linux and OSX, an easy way to to do this is to run `env XONSH_DEBUG=1 xonsh` -->

I don't get any error message.  The return code is 1 but there is no message.
```
~ @ > cd a_non_existant_directory
~ [1] @ >
```
When I remove the load bashism in xonshrc and restart, I get back the expected behavior.
### Traceback (if applicable)


<details>

```
> cd a_nonexistent_directory
--- before precommand event
+++ after precommand event
@@ -1 +1 @@
-cd a_nonexistent_directory
+cd! a_nonexistent_directory
<stdin>:1:2:28 - cd! a_nonexistent_directory
<stdin>:1:2:28 + ![cd! a_nonexistent_directory]
```
</details>

## Steps to Reproduce
<!--- Please try to write out a minimal reproducible snippet to trigger the bug, it will help us fix it! -->

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**


Discussion:
codecov-commenter: # [Codecov](https://codecov.io/gh/xonsh/xonsh/pull/4919?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh) Report
> Merging [#4919](https://codecov.io/gh/xonsh/xonsh/pull/4919?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh) (09f3a4e) into [main](https://codecov.io/gh/xonsh/xonsh/commit/ffe7b3445cf64b25a741d214581d57871196fd34?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh) (ffe7b34) will **decrease** coverage by `2.50%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##             main    #4919      +/-   ##
==========================================
- Coverage   66.86%   64.36%   -2.51%     
==========================================
  Files         129      129              
  Lines       23728    23729       +1     
  Branches     4705     4706       +1     
==========================================
- Hits        15866    15273     -593     
- Misses       6640     7207     +567     
- Partials     1222     1249      +27     
```

| Flag | Coverage Δ | |
|---|---|---|
| macOS-latest | `?` | |
| ubuntu-latest | `64.36% <100.00%> (-0.06%)` | :arrow_down: |
| windows-latest | `?` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/xonsh/xonsh/pull/4919?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh) | Coverage Δ | |
|---|---|---|
| [xonsh/procs/specs.py](https://codecov.io/gh/xonsh/xonsh/pull/4919/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh#diff-eG9uc2gvcHJvY3Mvc3BlY3MucHk=) | `70.20% <100.00%> (-3.21%)` | :arrow_down: |
| [xonsh/macutils.py](https://codecov.io/gh/xonsh/xonsh/pull/4919/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh#diff-eG9uc2gvbWFjdXRpbHMucHk=) | `0.00% <0.00%> (-80.00%)` | :arrow_down: |
| [xonsh/winutils.py](https://codecov.io/gh/xonsh/xonsh/pull/4919/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh#diff-eG9uc2gvd2ludXRpbHMucHk=) | `0.00% <0.00%> (-47.55%)` | :arrow_down: |
| [xonsh/platform.py](https://codecov.io/gh/xonsh/xonsh/pull/4919/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh#diff-eG9uc2gvcGxhdGZvcm0ucHk=) | `46.62% <0.00%> (-19.65%)` | :arrow_down: |
| [xonsh/completers/path.py](https://codecov.io/gh/xonsh/xonsh/pull/4919/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh#diff-eG9uc2gvY29tcGxldGVycy9wYXRoLnB5) | `56.41% <0.00%> (-15.39%)` | :arrow_down: |
| [xonsh/lazyimps.py](https://codecov.io/gh/xonsh/xonsh/pull/4919/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh#diff-eG9uc2gvbGF6eWltcHMucHk=) | `57.37% <0.00%> (-14.76%)` | :arrow_down: |
| [xonsh/procs/readers.py](https://codecov.io/gh/xonsh/xonsh/pull/4919/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh#diff-eG9uc2gvcHJvY3MvcmVhZGVycy5weQ==) | `47.00% <0.00%> (-11.06%)` | :arrow_down: |
| [xonsh/xoreutils/\_which.py](https://codecov.io/gh/xonsh/xonsh/pull/4919/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh#diff-eG9uc2gveG9yZXV0aWxzL193aGljaC5weQ==) | `27.56% <0.00%> (-10.26%)` | :arrow_down: |
| [xonsh/jobs.py](https://codecov.io/gh/xonsh/xonsh/pull/4919/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh#diff-eG9uc2gvam9icy5weQ==) | `42.24% <0.00%> (-9.12%)` | :arrow_down: |
| [xonsh/xoreutils/uptime.py](https://codecov.io/gh/xonsh/xonsh/pull/4919/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh#diff-eG9uc2gveG9yZXV0aWxzL3VwdGltZS5weQ==) | `21.51% <0.00%> (-8.87%)` | :arrow_down: |
| ... and [32 more](https://codecov.io/gh/xonsh/xonsh/pull/4919/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh) | |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=xonsh)

jnoortheen: Thanks @yaxollum !

Patch:
diff --git a/news/fix-procproxy-capture.rst b/news/fix-procproxy-capture.rst
new file mode 100644
index 00000000..8d71c963
--- /dev/null
+++ b/news/fix-procproxy-capture.rst
@@ -0,0 +1,23 @@
+**Added:**
+
+* <news item>
+
+**Changed:**
+
+* With ``$THREAD_SUBPROCS=False``: When a callable alias is executed with ``![]``, its standard output and standard error are no longer captured. This is because a separate thread is required in order to both capture the output and stream it to the terminal while the alias is running.
+
+**Deprecated:**
+
+* <news item>
+
+**Removed:**
+
+* <news item>
+
+**Fixed:**
+
+* With ``$THREAD_SUBPROCS=False``: When ``cd`` is used with an invalid directory, the error message is now correctly displayed.
+
+**Security:**
+
+* <news item>
diff --git a/xonsh/procs/specs.py b/xonsh/procs/specs.py
index dcd8be5e..c1168b40 100644
--- a/xonsh/procs/specs.py
+++ b/xonsh/procs/specs.py
@@ -737,7 +737,9 @@ def _update_last_spec(last):
         return
     callable_alias = callable(last.alias)
     if callable_alias:
-        pass
+        if last.cls is ProcProxy and captured == "hiddenobject":
+            # a ProcProxy run using ![] should not be captured
+            return
     else:
         cmds_cache = XSH.commands_cache
         thable = (


Test patch:
diff --git a/tests/procs/test_specs.py b/tests/procs/test_specs.py
index bb22d9c4..826b867b 100644
--- a/tests/procs/test_specs.py
+++ b/tests/procs/test_specs.py
@@ -166,3 +166,18 @@ def test_callable_alias_cls(thread_subprocs, xession):
     spec = cmds_to_specs(cmds, captured="stdout")[0]
     proc = spec.run()
     assert proc.f == obj
+
+
+@pytest.mark.parametrize("captured", ["hiddenobject", False])
+def test_procproxy_not_captured(xession, captured):
+    xession.aliases["tst"] = lambda: 0
+    cmds = (["tst", "/root"],)
+
+    xession.env["THREAD_SUBPROCS"] = False
+    specs = cmds_to_specs(cmds, captured)
+
+    assert specs[0].cls is ProcProxy
+
+    # neither stdout nor stderr should be captured
+    assert specs[0].stdout is None
+    assert specs[0].stderr is None