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

Add error logging and recovery #94

Merged
merged 13 commits into from
May 13, 2019
16 changes: 15 additions & 1 deletion platform_storage_api/fs/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,21 @@ async def get_filestatus(self, path: PurePath) -> FileStatus:
def _remove(self, path: PurePath) -> None:
concrete_path = Path(path)
if concrete_path.is_dir():
shutil.rmtree(concrete_path)
try:
shutil.rmtree(concrete_path)
except OSError as e:
# Debug logging
path = e.filename
parent_path = os.path.dirname(path)
path_access_ok = os.access(path, os.W_OK)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to output a mode.

try:
    path_mode = f"{os.stat(path).st_mode:03o}"
except OSError:
    path_mode = '?'

parent_path_access_ok = os.access(parent_path, os.W_OK)
logger.warning(
f"OSError for path %s, access = %s parent_access = %s",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add also the error message.

Either use the f-string for formatting the whole message or do not use the f prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean e.strerror?

Copy link
Contributor

@serhiy-storchaka serhiy-storchaka May 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the errno attribute. Or better errno.errorcode.get(err.errno, err.errno).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean e.strerror?

str(e)

path,
path_access_ok,
parent_path_access_ok,
)
raise e
else:
concrete_path.unlink()

Expand Down