RecursionError has empty or trailing-space message instead of 'maximum recursion depth exceeded'
@lsahn-gh já está trabalhando nisso.
Desde 26/7/2026.
Avaliação
Esta issue ainda não foi avaliada.
Descrição
Summary
The RecursionError raised when the recursion guard trips does not carry CPython's message 'maximum recursion depth exceeded'. Depending on which of RustPython's two recursion guards fires first, str(e) is either an empty string or the message with a stray trailing space.
Reproduction
# native C-stack guard (what trips by default, e.g. debug builds)
def f(): f()
try:
f()
except RecursionError as e:
print(repr(str(e)))
# RustPython: ''
# CPython: 'maximum recursion depth exceeded'
# logical depth-limit guard (force it with a low limit)
import sys
sys.setrecursionlimit(60)
def f(): f()
try:
f()
except RecursionError as e:
print(repr(str(e)))
# RustPython: 'maximum recursion depth exceeded ' <- trailing space
# CPython: 'maximum recursion depth exceeded'
CPython always yields exactly 'maximum recursion depth exceeded' (and e.args == ('maximum recursion depth exceeded',)). RustPython yields ('',) or ('maximum recursion depth exceeded ',).
Root cause
crates/vm/src/vm/mod.rs has two guards that construct the RecursionError message inconsistently, and neither matches CPython:
-
Logical depth guard —
check_recursive_call(mod.rs:1877):Err(self.new_recursion_error(format!("maximum recursion depth exceeded {_where}")))With the common
_where == ""this produces a trailing space:"maximum recursion depth exceeded ". -
Native C-stack guard —
with_recursion(mod.rs:1692) andresume_gen_frame(mod.rs:1767):return Err(self.new_recursion_error(_where.to_string())); // 1692, _where == "" for normal calls return Err(self.new_recursion_error(String::new())); // 1767Here
_whereis used as the whole message, so a normal call (empty_where) yields an empty message.
The two functions disagree on whether _where is a suffix appended to "maximum recursion depth exceeded" or the entire message. The fix is to make both paths produce "maximum recursion depth exceeded" (optionally + " while {context}" when context is present, with no trailing space when it is absent).
Reference
Verified against CPython 3.14.5.
Investigated and drafted by Claude; reviewed before filing.
- Linguagem predominante
- Rust
- Estrelas
- 22.4k
- Forks
- 1.5k
- Merge médio
- 15h 18min
- PRs com merge (30d)
- 172
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de RustPython/RustPython
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
RustPython/RustPython#8470 · 2 comentários ·
-
C-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
RustPython/RustPython#7995 · 5 comentários ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
RustPython/RustPython#5577 ·
-
C-bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
RustPython/RustPython#8685 · 7 comentários · 1 reação ·
-
C-compat
RustPython/RustPython#8496 · 1 comentário · 1 responsável ·
Todas as issues de RustPython/RustPython
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
MystenLabs/sui#28056 · 1 comentário ·
-
type/bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
Luminous-Dynamics/mycelix#2577 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
registrystack/registry-stack#1239 ·
-
package-request
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
msys2/MINGW-packages#31806 ·