Skip to content
Open
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def print_messages(prefix, count):
for i in range(1, count + 1):
suffix = "" if i == 1 else f" {i}"
print(f"{prefix}{suffix}")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error Handling Missing

The print_messages function lacks error handling for print operations. In non-interactive environments, stdout might be unavailable, causing unexpected script termination when output is redirected to a closed pipe.

Suggested change
print(f"{prefix}{suffix}")
def print_messages(prefix, count):
try:
for i in range(1, count + 1):
suffix = "" if i == 1 else f" {i}"
print(f"{prefix}{suffix}")
except IOError as e:
import sys
sys.stderr.write(f"Error writing to stdout: {e}\n")
Standards
  • CWE-755
  • ISO-IEC-25010-Reliability-Fault-Tolerance


print_messages("Hello world", 3)

print_messages("Test PR 2", 4)