Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

main.py (and others): Move Try Statements to Result #34

@onkoe

Description

@onkoe

In almost all Python projects, try statements are used to handle errors. However, they act as :GOTO statements, and I'd like to avoid them in any important project files.

The modern replacement for try statements is to use the Result type in Rust. But since we're in Python, we'd need to use a Result implementation, such as... result.

Motivations

Result forces you to:

  • handle your errors
  • cover all potential cases
  • deal with errors without interrupting control flow

It fixes some issues from try, such as:

  • jumping between flow paths
  • not handling errors correctly
  • having confusing, unmaintainable error handling

In other words, even with very little understanding, programmers become nearly perfect in almost all error handling situations. Migrating to result from try is a worthy cause that will lead to improved error handling and better maintainability.

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