exceptions
napt.exceptions
Exception hierarchy for NAPT.
This module defines a custom exception hierarchy for distinguishing between different types of errors. All exceptions inherit from NAPTError, allowing callers to catch all NAPT errors with a single except clause if needed.
NAPTError
Bases: Exception
Base exception for all NAPT errors.
All NAPT-specific exceptions inherit from this class, allowing callers to catch all NAPT errors with a single except clause if needed.
ConfigError
Bases: NAPTError
Raised for configuration-related errors.
This exception is raised when there are problems with:
- YAML parse errors (syntax errors, invalid structure)
- Missing required configuration fields (e.g., no apps defined, missing 'discovery.strategy' field)
- Invalid strategy configuration (unknown strategy name, invalid strategy parameters)
- Missing recipe files (file not found)
- Recipe validation failures (invalid recipe structure, missing required app fields)
Example
Catching configuration errors:
Source code in napt/exceptions.py
NetworkError
Bases: NAPTError
Raised for network/download-related errors.
This exception is raised when there are problems with:
- Download failures (HTTP errors, connection timeouts, network unreachable)
- API call failures (GitHub API errors, JSON API endpoint failures, authentication issues)
- Network-related version extraction errors (API response parsing failures)
Example
Catching network errors:
Source code in napt/exceptions.py
PackagingError
Bases: NAPTError
Raised for packaging/build-related errors.
This exception is raised when there are problems with:
- Build failures (PSADT template processing errors, file operations, directory creation failures)
- Missing build tools (IntuneWinAppUtil.exe not found, PSADT template missing)
- MSI extraction errors (failed to read MSI ProductVersion, unsupported MSI format)
- Packaging operations (IntuneWinAppUtil.exe execution failures, invalid build directory structure)
- Malformed .intunewin files (invalid ZIP structure, missing Detection.xml, missing required encryption fields)
Example
Catching packaging errors:
Source code in napt/exceptions.py
StateError
Bases: NAPTError
Raised for persisted-state integrity errors.
This exception is raised when NAPT's own persisted state (the
deployment state files under state/) is unreadable or invalid:
- Corrupted deployment state files (invalid JSON)
- Invalid deployment state fields (e.g., an unparseable ring
entered_attimestamp)
Deployment state is authoritative and never auto-replaced; the error message says how to recover.
Example
Catching state errors:
Source code in napt/exceptions.py
AuthError
Bases: NAPTError
Raised for authentication and authorization errors.
This exception is raised when there are problems with:
- No credential available (no service principal / OIDC environment and no session from 'napt auth login')
- Graph API 401 Unauthorized or 403 Forbidden responses
- Interactive sign-in failure, timeout, or cancellation
- A cached sign-in session that can no longer be refreshed
Example
Catching auth errors:
Source code in napt/exceptions.py
NotModifiedError
Bases: Exception
Raised when a conditional HTTP request returns 304 Not Modified.
This exception is raised when download_file() receives HTTP 304, meaning the server has confirmed that the remote content has not changed since the last request. The function is expected to return a file on disk, and with a 304 response there is no file to return, so it raises instead.
Inherits from Exception (not NAPTError) so that broad catches of all NAPT errors do not suppress 304 responses. Callers that supply an ETag must handle this explicitly.
Example
Handling a conditional download: