Skip to content

Commit

Permalink
Fixed shell blocks not ending on error bug
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianLucas committed Oct 11, 2023
1 parent 798de26 commit c93eb67
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions interpreter/code_interpreters/languages/shell.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import platform
from ..subprocess_code_interpreter import SubprocessCodeInterpreter
import ast
import os

class Shell(SubprocessCodeInterpreter):
Expand Down Expand Up @@ -41,10 +40,6 @@ def preprocess_shell(code):
# Add commands that tell us what the active line is
code = add_active_line_prints(code)

# Wrap in a trap for errors
if platform.system() != 'Windows':
code = wrap_in_trap(code)

# Add end command (we'll be listening for this so we know when it ends)
code += '\necho "## end_of_execution ##"'

Expand All @@ -59,15 +54,4 @@ def add_active_line_prints(code):
for index, line in enumerate(lines):
# Insert the echo command before the actual line
lines[index] = f'echo "## active_line {index + 1} ##"\n{line}'
return '\n'.join(lines)


def wrap_in_trap(code):
"""
Wrap Bash code with a trap to catch errors and display them.
"""
trap_code = """
trap 'echo "An error occurred on line $LINENO"; exit' ERR
set -E
"""
return trap_code + code
return '\n'.join(lines)

0 comments on commit c93eb67

Please sign in to comment.