gformlib.exceptions

Custom exceptions for gformlib.

This module defines the exception hierarchy used throughout the library. All library-specific exceptions inherit from GFormLibError.

exception gformlib.exceptions.GFormLibError[source]

Bases: Exception

Base exception class for all gformlib errors.

All library-specific exceptions are subclasses of this class, allowing callers to catch any gformlib error with a single except clause:

try:
    client.create_form(config)
except GFormLibError as exc:
    print(f"gformlib error: {exc}")
exception gformlib.exceptions.AuthenticationError[source]

Bases: GFormLibError

Raised when authentication with Google APIs fails.

This may occur when credentials are missing, expired, or lack the required OAuth scopes (forms.body, drive.file, etc.).

Example:

try:
    client = GoogleFormsClient.from_service_account("creds.json")
except AuthenticationError as exc:
    print(f"Auth failed: {exc}")
exception gformlib.exceptions.FormCreationError(message, config=None)[source]

Bases: GFormLibError

Raised when initial form creation via the API fails.

Wraps errors returned by the forms().create() call.

Parameters:
  • message (str)

  • config (Optional[Dict[str, Any]])

Return type:

None

config

The form configuration dict that triggered the error.

exception gformlib.exceptions.FormUpdateError(message, form_id=None)[source]

Bases: GFormLibError

Raised when a batchUpdate call to add questions fails.

Parameters:
  • message (str)

  • form_id (Optional[str])

Return type:

None

form_id

The form that was being updated when the error occurred.

exception gformlib.exceptions.InvalidConfigError(message, field=None)[source]

Bases: GFormLibError

Raised when the supplied form or question configuration is invalid.

This is a client-side validation error raised before any API call is made.

Parameters:
  • message (str)

  • field (Optional[str])

Return type:

None

field

The configuration field that failed validation (if known).

exception gformlib.exceptions.APIError(message, status_code=None, details=None)[source]

Bases: GFormLibError

Raised when the Google Forms API returns an unexpected HTTP error.

Parameters:
  • message (str)

  • status_code (Optional[int])

  • details (Optional[Dict[str, Any]])

Return type:

None

status_code

HTTP status code returned by the API.

details

Parsed JSON error body from the API response.