🔍 Code Extractor

class ResourceNotFoundError

Maturity: 37

Custom exception class that signals when a requested resource cannot be found in the system.

File:
/tf/active/vicechatdev/CDocs/controllers/__init__.py
Lines:
68 - 70
Complexity:
simple

Purpose

ResourceNotFoundError is a specialized exception class that inherits from ControllerError. It is designed to be raised when operations attempt to access resources (such as documents, files, users, or other entities) that do not exist in the system. This provides a clear, semantic way to handle missing resource scenarios in the CDocs application, allowing calling code to distinguish between different types of errors and respond appropriately. It follows the standard Python exception pattern and can be caught specifically or as part of the broader ControllerError hierarchy.

Source Code

class ResourceNotFoundError(ControllerError):
    """Exception raised when a requested resource is not found."""
    pass

Parameters

Name Type Default Kind
bases ControllerError -

Parameter Details

args: Variable positional arguments passed to the base Exception class. Typically includes an error message string describing which resource was not found and any relevant identifiers.

kwargs: Variable keyword arguments passed to the base Exception class. Can include additional context about the missing resource.

Return Value

Instantiation returns a ResourceNotFoundError exception object that can be raised. When raised, it propagates up the call stack until caught by an exception handler. The exception object contains the message and any additional context passed during instantiation.

Class Interface

Methods

__init__(*args, **kwargs)

Purpose: Initializes the ResourceNotFoundError exception with optional message and context

Parameters:

  • args: Variable positional arguments, typically a string message describing the missing resource
  • kwargs: Variable keyword arguments for additional exception context

Returns: None (constructor)

Attributes

Name Type Description Scope
args tuple Tuple containing the arguments passed to the exception, typically the error message instance

Required Imports

from CDocs.exceptions import ResourceNotFoundError

Usage Example

# Raising the exception when a resource is not found
def get_document(doc_id: str):
    document = database.find_document(doc_id)
    if document is None:
        raise ResourceNotFoundError(f"Document with ID '{doc_id}' not found")
    return document

# Catching the exception
try:
    doc = get_document('12345')
except ResourceNotFoundError as e:
    print(f"Error: {e}")
    # Handle missing resource scenario

# Can also be caught as part of broader ControllerError
try:
    doc = get_document('12345')
except ControllerError as e:
    print(f"Controller error occurred: {e}")

Best Practices

  • Always include a descriptive message when raising this exception, specifying which resource was not found and its identifier
  • Use this exception specifically for missing resources rather than generic errors to enable precise error handling
  • Catch this exception at appropriate levels in your application to provide user-friendly error messages or implement retry logic
  • Consider logging the exception details before re-raising or handling to aid in debugging
  • This exception can be caught specifically as ResourceNotFoundError or more broadly as ControllerError depending on your error handling strategy
  • When raising, include relevant context such as resource type, ID, and any search parameters used
  • In REST API contexts, this exception typically maps to HTTP 404 Not Found responses

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class ResourceNotFoundError_v1 91.3% similar

    A custom exception class that is raised when a requested resource cannot be found in the system.

    From: /tf/active/vicechatdev/CDocs/controllers/admin_controller.py
  • class PermissionError 65.7% similar

    Custom exception class that signals when a user attempts an action they lack permission to perform.

    From: /tf/active/vicechatdev/CDocs/controllers/admin_controller.py
  • class PermissionError_v1 64.7% similar

    Custom exception class raised when a user lacks the necessary permissions to perform a specific action in the CDocs system.

    From: /tf/active/vicechatdev/CDocs/controllers/__init__.py
  • class ControllerError 64.1% similar

    A custom exception class that serves as the base exception for all controller-related errors in the CDocs system.

    From: /tf/active/vicechatdev/CDocs/controllers/__init__.py
  • class BusinessRuleError 57.2% similar

    Custom exception class that signals when a business rule has been violated in the CDocs document management system.

    From: /tf/active/vicechatdev/CDocs/controllers/admin_controller.py
← Back to Browse