Skip to content

Fix: Added improved logging for debugging purpose #417

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.5.12-dev0

### Fixes

* **Added extensive logging to sharepoint connector**

## 0.5.11

### Features
Expand Down
2 changes: 1 addition & 1 deletion unstructured_ingest/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.11" # pragma: no cover
__version__ = "0.5.12-dev0" # pragma: no cover
64 changes: 56 additions & 8 deletions unstructured_ingest/v2/processes/connectors/sharepoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,72 @@ class SharepointIndexer(OnedriveIndexer):
async def run_async(self, **kwargs: Any) -> AsyncIterator[FileData]:
from office365.runtime.client_request_exception import ClientRequestException

logger.info(f"[{self.connector_type}] Fetching access token...")
token_resp = await asyncio.to_thread(self.connection_config.get_token)

if "error" in token_resp:
raise SourceConnectionError(
f"[{self.connector_type}]: {token_resp['error']} "
f"({token_resp.get('error_description')})"
)
error_message = f"[{self.connector_type}] Authentication error: {token_resp['error']} \
({token_resp.get('error_description')})"
logger.error(error_message)
raise SourceConnectionError(error_message)

logger.info(
f"[{self.connector_type}] Successfully obtained access token. \
Connecting to SharePoint site: {self.connection_config.site}"
)

client = await asyncio.to_thread(self.connection_config.get_client)

try:
site = client.sites.get_by_url(self.connection_config.site).get().execute_query()
logger.info(
f"[{self.connector_type}] Successfully retrieved site object: {site.properties}"
)

site_drive_item = site.drive.get().execute_query().root
except ClientRequestException:
logger.info("Site not found")
if site_drive_item is None:
raise ValueError(
f"[{self.connector_type}] \
No root drive found for site {self.connection_config.site}. \
Please check site permissions or if the site has a document library."
)

logger.info(f"[{self.connector_type}] Successfully retrieved site drive root.")

except ClientRequestException as e:
logger.error(f"[{self.connector_type}] Failed to fetch SharePoint site: {str(e)}")
raise SourceConnectionError(
f"[{self.connector_type}] Site not found or inaccessible: {str(e)}"
)

# Check if a path was provided and attempt to retrieve the specific path
path = self.index_config.path
# Deprecated sharepoint sdk needed a default path. Microsoft Graph SDK does not.
if path and path != LEGACY_DEFAULT_PATH:
site_drive_item = site_drive_item.get_by_path(path).get().execute_query()
logger.info(f"[{self.connector_type}] Fetching site drive item at path: {path}")

try:
site_drive_item = site_drive_item.get_by_path(path).get().execute_query()
logger.info(
f"[{self.connector_type}] \
Successfully retrieved site drive item at path: {path}"
)
except ClientRequestException as e:
logger.error(
f"[{self.connector_type}] Invalid path '{path}'. \
Please verify the path exists in SharePoint. Error: {str(e)}"
)
raise ValueError(
f"[{self.connector_type}] Invalid path '{path}' or path does not exist."
)

# Final validation before proceeding to file retrieval
if site_drive_item is None:
error_msg = f"[{self.connector_type}] \
Unable to retrieve site drive item. \
This may be due to incorrect site URL, \
missing permissions, or an empty document library."
logger.error(error_msg)
raise ValueError(error_msg)

for drive_item in site_drive_item.get_files(
recursive=self.index_config.recursive
Expand Down