Skip to content

Bug: bare except clauses catch KeyboardInterrupt and SystemExit #5065

@mango766

Description

@mango766

Bug Description

Several places in the codebase use bare except: clauses which catch KeyboardInterrupt and SystemExit in addition to regular exceptions. This prevents proper Celery worker shutdown and can mask critical errors.

Affected Files

  1. apps/ops/celery/utils.py line 45:
try:
    uuid.UUID(task_id)
except:  # catches KeyboardInterrupt/SystemExit
    return os.path.join(PROJECT_DIR, 'data', 'caution.txt')

Should use except (ValueError, AttributeError): since uuid.UUID() only raises ValueError on invalid UUIDs.

  1. apps/application/flow/step_node/tool_node/impl/base_tool_node.py line 54:
except:  # catches KeyboardInterrupt/SystemExit
    return value

Should use except (json.JSONDecodeError, TypeError, ValueError): since the try block calls json.loads() and type comparisons.

Impact

During Celery worker shutdown or when a user sends SIGINT:

  • KeyboardInterrupt is silently swallowed, preventing graceful shutdown
  • SystemExit is caught, which can cause processes to hang instead of terminating

This follows the Python best practice documented in PEP 8: "When catching exceptions, mention specific exceptions whenever possible instead of using a bare except: clause."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions