Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make exception handling explicit #5202

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Commits on Sep 27, 2024

  1. Configuration menu
    Copy the full SHA
    48781ce View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f5622b7 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    9f866e8 View commit details
    Browse the repository at this point in the history
  4. chore(debain): Remove obsolete helper function

    From this helper's docstring:
    
        Ubuntu cloud images previously included a 'eth0.cfg' that had
        hard coded content.  That file would interfere with the rendered
        configuration if it was present.
    
    This code is no longer relevant due to the following:
    
    1) Ubuntu uses netplan
    2) This appears like an Ubuntu-specific workaround
    3) Debian cloud images use netplan
    holmanb committed Sep 27, 2024
    Configuration menu
    Copy the full SHA
    abe431e View commit details
    Browse the repository at this point in the history
  5. refactor(net): Simplify read_sys_net exception handling

    Remove unnecessary arguments.
    holmanb committed Sep 27, 2024
    Configuration menu
    Copy the full SHA
    324926c View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    3b65a27 View commit details
    Browse the repository at this point in the history
  7. chore(json): Simplify json loading

    Since Python 3.6, json.loads() is capable of receiving arguments of type
    str, bytes, and bytearray. Cloud-init's code historically manually handled type
    conversion. This boilerplate is no longer necessary.
    
    Add docstring and typing to util.load_json().
    holmanb committed Sep 27, 2024
    Configuration menu
    Copy the full SHA
    eec8f50 View commit details
    Browse the repository at this point in the history

Commits on Sep 30, 2024

  1. chore: Make exception handling more explicit

    Cloud-init's codebase makes extensive use of exception handlers which
    catch Exception and then do something based on the assumed exception
    type. This is bad practice and makes it possible for exceptions to be
    unexpectedly ignored. To remedy this, this commit updates cloud-init to
    make `Exception` always be an unknown exception which therefore should
    always produce a log of level `WARN` or higher.
    
    Require a minimum of one of the following in each Exception handler:
    
    - LOG.warning("Unhandled exception: %s", e)
    - util.logexc() - with a log level of WARN or higher
    - re-raise the exception without setting exception type when
      re-raising[1]
    
    Make cloud-init's code adhere to the above set of rules with the
    following changes:
    
    - Limit the scope where Exception is handled to only unexpected error paths.
    - Add new handlers for more specific exception types.
    - Add warning logs or increase log level to WARN in some cases.
    - Add typing where exceptions are returned.
    - Replace various Exception handlers with ProcessExecutionError.
    - Remove handling that does nothing.
    - Remove unused code which handles Exception.
    
    [1] This would likely reduce the scope of the exception and make it
        possible to mask an Exception.
    holmanb committed Sep 30, 2024
    Configuration menu
    Copy the full SHA
    56ad063 View commit details
    Browse the repository at this point in the history

Commits on Oct 1, 2024

  1. Configuration menu
    Copy the full SHA
    02b775d View commit details
    Browse the repository at this point in the history
  2. chore(IOError): Update IOError to OSError

    In Python 3.3+, IOError is an alias of OSError[1]. Some call sites use
    one or the other or both. Standardize on the OSError.
    
    [1] https://docs.python.org/3/library/exceptions.html#IOError
    holmanb committed Oct 1, 2024
    Configuration menu
    Copy the full SHA
    5294901 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    1786f9d View commit details
    Browse the repository at this point in the history