diff --git a/news/firstse.rst b/news/firstse.rst
new file mode 100644
index 00000000..8627a726
--- /dev/null
+++ b/news/firstse.rst
@@ -0,0 +1,14 @@
+**Added:** None
+
+**Changed:** None
+
+**Deprecated:** None
+
+**Removed:** None
+
+**Fixed:**
+
+* Fixed issue with ``SyntaxErrors`` being reported on the wrong line
+  when a block of code contained multiple implicit subprocesses.
+
+**Security:** None
diff --git a/xonsh/execer.py b/xonsh/execer.py
index 2fbaf2c8..f9775a5d 100644
--- a/xonsh/execer.py
+++ b/xonsh/execer.py
@@ -177,6 +177,8 @@ class Execer(object):
                                        last_error_col in (e.loc.column + 1,
                                                           e.loc.column)):
                     raise original_error from None
+                elif last_error_line != e.loc.lineno:
+                    original_error = e
                 last_error_col = e.loc.column
                 last_error_line = e.loc.lineno
                 idx = last_error_line - 1

Incorrect line numbers given in traceback when running a xonsh script
Suppose you have a xonsh script with a syntax error in it. A traceback will be generated properly, but it will sometimes incorrectly point to the wrong line in the file if preceded by lines in subprocess mode. The problem seems to be that blank lines and comments are ignored.

For example:
```
$ cat test.xsh
#!/usr/bin/env xonsh

echo "This is line 3"
print ("This is line 4")
x = "This is a string where I forget the closing quote on line 5
echo "This is line 6"

$ ./test.xsh 
Traceback (most recent call last):
  [trimmed traceback]
SyntaxError: ./test.xsh:3:5: ('code: "This is line 3"',)
echo "This is line 3"
     ^
```
It says the error is on line 3, character 5, but it's really on line 5.

However, suppose that first `echo` call is changed to another print call. Then we get the correct line:
```
$ cat test.xsh
#!/usr/bin/env xonsh

print("This is line 3")
print ("This is line 4")
x = "This is a string where I forget the closing quote on line 5
echo "This is line 6"

$ ./test.xsh 
Traceback (most recent call last):
  [trimmed traceback]
SyntaxError: ./test.xsh:5:4: "
x = "This is a string where I forget the closing quote on line 5
    ^
```

Lastly, suppose we replace the `print` call on line 4 with a call in subprocess mode to `echo`. Then the error is now on line 4:

```
$ cat test.xsh
#!/usr/bin/env xonsh

print("This is line 3")
echo "This is line 4"
x = "This is a string where I forget the closing quote on line 5
echo "This is line 6"
$ ./test.xsh 
Traceback (most recent call last):
  [trimmed traceback]
SyntaxError: ./test.xsh:4:5: ('code: "This is line 4"',)
echo "This is line 4"
     ^
```

For reference, here is the entire traceback, which (besides the last part with the line) is identical in all three runs:

```
$ ./test.xsh 
Traceback (most recent call last):
  File "/usr/local/bin/xonsh", line 3, in <module>
    main()
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 20837, in main
    _failback_to_other_shells(args, err)
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 20801, in _failback_to_other_shells
    raise err
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 20835, in main
    return main_xonsh(args)
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 20876, in main_xonsh
    loc=None, mode='exec')
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 2438, in run_script_with_cache
    ccode = compile_code(filename, code, execer, glb, loc, mode)
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 2397, in compile_code
    filename=filename)
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 20054, in compile
    transform=transform)
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 20023, in parse
    tree, input = self._parse_ctx_free(input, mode=mode, filename=filename)
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 20123, in _parse_ctx_free
    raise original_error from None
  File "/usr/local/lib/python3.5/dist-packages/xonsh/__amalgam__.py", line 20110, in _parse_ctx_free
    debug_level=(self.debug_level > 2))
  File "/usr/local/lib/python3.5/dist-packages/xonsh/parsers/base.py", line 349, in parse
    tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)
  File "/usr/local/lib/python3.5/dist-packages/xonsh/ply/ply/yacc.py", line 331, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/usr/local/lib/python3.5/dist-packages/xonsh/ply/ply/yacc.py", line 1199, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/usr/local/lib/python3.5/dist-packages/xonsh/ply/ply/yacc.py", line 193, in call_errorfunc
    r = errorfunc(token)
  File "/usr/local/lib/python3.5/dist-packages/xonsh/parsers/base.py", line 2760, in p_error
    column=p.lexpos))
  File "/usr/local/lib/python3.5/dist-packages/xonsh/parsers/base.py", line 482, in _parse_error
    raise err
SyntaxError: ./test.xsh:4:5: ('code: "This is line 4"',)
echo "This is line 4"
     ^
```
diff --git a/tests/test_integrations.py b/tests/test_integrations.py
index 35939e51..1364a330 100644
--- a/tests/test_integrations.py
+++ b/tests/test_integrations.py
@@ -287,6 +287,18 @@ def test_eof_syntax_error():
     assert ':2:0: EOF in multi-line statement' in err
 
 
+def test_open_quote_syntax_error():
+    script = ('#!/usr/bin/env xonsh\n\n'
+              'echo "This is line 3"\n'
+              'print ("This is line 4")\n'
+              'x = "This is a string where I forget the closing quote on line 5\n'
+              'echo "This is line 6"\n')
+    out, err, rtn = run_xonsh(script, stderr=sp.PIPE)
+    assert """:3:5: ('code: "This is line 3"',)""" not in err
+    assert ':5:4: "' in err
+    assert 'SyntaxError:' in err
+
+
 _bad_case = pytest.mark.skipif(ON_DARWIN or ON_WINDOWS or ON_TRAVIS,
                                reason="bad platforms")
 

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-flake8 pytest-cov
apt-get update apt-get install -y gcc
3.7
requirements-docs.txt requirements-tests.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
Babel==2.14.0
backcall==0.2.0
certifi @ file:///croot/certifi_1671487769961/work/certifi
cffi==1.15.1
charset-normalizer==3.4.1
cloud-sptheme==1.10.1.post20200504175005
codecov==2.1.13
coverage==7.2.7
cryptography==44.0.2
cycler==0.11.0
debugpy==1.7.0
decorator==5.1.1
doctr==1.9.0
docutils==0.19
entrypoints==0.4
exceptiongroup==1.2.2
flake8==3.5.0
fonttools==4.38.0
idna==3.10
imagesize==1.4.1
importlib-metadata==6.7.0
iniconfig==2.0.0
ipykernel==6.16.2
ipython==7.34.0
jedi==0.19.2
Jinja2==3.1.6
jupyter_client==7.4.9
jupyter_core==4.12.0
kiwisolver==1.4.5
MarkupSafe==2.1.5
matplotlib==3.5.3
matplotlib-inline==0.1.6
mccabe==0.6.1
nest-asyncio==1.6.0
numpy==1.21.6
numpydoc==1.5.0
packaging==24.0
parso==0.8.4
pexpect==4.9.0
pickleshare==0.7.5
Pillow==9.5.0
pluggy==1.2.0
ply==3.11
prompt_toolkit==3.0.48
psutil==7.0.0
ptyprocess==0.7.0
py==1.11.0
pycodestyle==2.3.1
pycparser==2.21
pyflakes==1.6.0
Pygments==2.17.2
pyparsing==3.1.4
pytest==7.4.4
pytest-cov==4.1.0
pytest-flake8==1.1.0
pytest-timeout==2.3.1
python-dateutil==2.9.0.post0
pytz==2025.2
PyYAML==6.0.1
pyzmq==26.2.1
requests==2.31.0
six==1.17.0
snowballstemmer==2.2.0
Sphinx==5.3.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
tomli==2.0.1
tornado==6.2
traitlets==5.9.0
typing_extensions==4.7.1
urllib3==2.0.7
wcwidth==0.2.13
-e git+https://github.com/xonsh/xonsh.git@afdc6b027cde64e3a0939e9b2da9f99c2fd2dc96#egg=xonsh
zipp==3.15.0

name: xonsh
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - babel==2.14.0
      - backcall==0.2.0
      - cffi==1.15.1
      - charset-normalizer==3.4.1
      - cloud-sptheme==1.10.1.post20200504175005
      - codecov==2.1.13
      - coverage==7.2.7
      - cryptography==44.0.2
      - cycler==0.11.0
      - debugpy==1.7.0
      - decorator==5.1.1
      - doctr==1.9.0
      - docutils==0.19
      - entrypoints==0.4
      - exceptiongroup==1.2.2
      - flake8==3.5.0
      - fonttools==4.38.0
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - ipykernel==6.16.2
      - ipython==7.34.0
      - jedi==0.19.2
      - jinja2==3.1.6
      - jupyter-client==7.4.9
      - jupyter-core==4.12.0
      - kiwisolver==1.4.5
      - markupsafe==2.1.5
      - matplotlib==3.5.3
      - matplotlib-inline==0.1.6
      - mccabe==0.6.1
      - nest-asyncio==1.6.0
      - numpy==1.21.6
      - numpydoc==1.5.0
      - packaging==24.0
      - parso==0.8.4
      - pexpect==4.9.0
      - pickleshare==0.7.5
      - pillow==9.5.0
      - pluggy==1.2.0
      - ply==3.11
      - prompt-toolkit==3.0.48
      - psutil==7.0.0
      - ptyprocess==0.7.0
      - py==1.11.0
      - pycodestyle==2.3.1
      - pycparser==2.21
      - pyflakes==1.6.0
      - pygments==2.17.2
      - pyparsing==3.1.4
      - pytest==7.4.4
      - pytest-cov==4.1.0
      - pytest-flake8==1.1.0
      - pytest-timeout==2.3.1
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - pyyaml==6.0.1
      - pyzmq==26.2.1
      - requests==2.31.0
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==5.3.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - tomli==2.0.1
      - tornado==6.2
      - traitlets==5.9.0
      - typing-extensions==4.7.1
      - urllib3==2.0.7
      - wcwidth==0.2.13
      - zipp==3.15.0
prefix: /opt/conda/envs/xonsh

tests/test_integrations.py::test_open_quote_syntax_error
tests/test_integrations.py::test_printfile tests/test_integrations.py::test_printname tests/test_integrations.py::test_sourcefile
tests/test_integrations.py::test_script[case0] tests/test_integrations.py::test_script[case1] tests/test_integrations.py::test_script[case2] tests/test_integrations.py::test_script[case3] tests/test_integrations.py::test_script[case4] tests/test_integrations.py::test_script[case5] tests/test_integrations.py::test_script[case6] tests/test_integrations.py::test_script[case7] tests/test_integrations.py::test_script[case8] tests/test_integrations.py::test_script[case9] tests/test_integrations.py::test_script[case10] tests/test_integrations.py::test_script[case11] tests/test_integrations.py::test_script[case12] tests/test_integrations.py::test_script[case13] tests/test_integrations.py::test_script[case14] tests/test_integrations.py::test_script_stderr[case0] tests/test_integrations.py::test_single_command_no_windows[pwd-None-<lambda>] tests/test_integrations.py::test_single_command_no_windows[echo tests/test_integrations.py::test_single_command_no_windows[ls tests/test_integrations.py::test_eof_syntax_error tests/test_integrations.py::test_subshells[\nwith tests/test_integrations.py::test_redirect_out_to_file[pwd-<lambda>]
news/firstse.rst xonsh/execer.py
news/firstse.rst xonsh/execer.py