-
Notifications
You must be signed in to change notification settings - Fork 33
Enhance path validation error messages #1792
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
Changes from all commits
7be5483
3c297bf
4f511e9
e19a1cc
08dcb84
c89f6af
a767980
8871f75
f969d78
4e11b7b
fb33e99
111b04a
750ddfa
ee32925
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,7 +24,7 @@ | |||||
| from typing import NewType | ||||||
|
|
||||||
| from . import get_logger | ||||||
| from .consts import DandiInstance | ||||||
| from .consts import DandiInstance, dandiset_metadata_file | ||||||
| from .dandiapi import DandiAPIClient, RemoteAsset, RemoteDandiset | ||||||
| from .dandiarchive import DandisetURL, parse_dandi_url | ||||||
| from .dandiset import Dandiset | ||||||
|
|
@@ -244,7 +244,11 @@ def resolve(self, path: str) -> tuple[AssetPath, bool]: | |||||
| posixpath.normpath(posixpath.join(self.subpath.as_posix(), path)) | ||||||
| ) | ||||||
| if p.parts and p.parts[0] == os.pardir: | ||||||
| raise ValueError(f"{path!r} is outside of Dandiset") | ||||||
| raise ValueError( | ||||||
| f"{path!r} is outside of Dandiset. " | ||||||
| "Paths cannot use '..' to navigate above the Dandiset root. " | ||||||
| "All assets must remain within the Dandiset directory structure." | ||||||
| ) | ||||||
| return (AssetPath(str(p)), path.endswith("/")) | ||||||
|
|
||||||
| def calculate_moves( | ||||||
|
|
@@ -483,11 +487,17 @@ def get_path(self, path: str, is_src: bool = True) -> File | Folder: | |||||
| rpath, needs_dir = self.resolve(path) | ||||||
| p = self.dandiset_path / rpath | ||||||
| if not os.path.lexists(p): | ||||||
| raise NotFoundError(f"No asset at local path {path!r}") | ||||||
| raise NotFoundError( | ||||||
| f"No asset at local path {path!r}. " | ||||||
CodyCBakerPhD marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| "Verify the path is correct and the file exists locally." | ||||||
| ) | ||||||
| if p.is_dir(): | ||||||
| if is_src: | ||||||
| if p == self.dandiset_path / self.subpath: | ||||||
| raise ValueError("Cannot move current working directory") | ||||||
| raise ValueError( | ||||||
| "Cannot move current working directory. " | ||||||
| "Change to a different directory before moving this location." | ||||||
| ) | ||||||
| files = [ | ||||||
| df.filepath.relative_to(p).as_posix() | ||||||
| for df in find_dandi_files( | ||||||
|
|
@@ -499,7 +509,10 @@ def get_path(self, path: str, is_src: bool = True) -> File | Folder: | |||||
| files = [] | ||||||
| return Folder(rpath, files) | ||||||
| elif needs_dir: | ||||||
| raise ValueError(f"Local path {path!r} is a file") | ||||||
| raise ValueError( | ||||||
| f"Local path {path!r} is a file but a directory was expected. " | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, it is useful for disambiguating a place in a sentence if a really bad value like Though to be fair the |
||||||
| "Use a path ending with '/' for directories." | ||||||
| ) | ||||||
| else: | ||||||
| return File(rpath) | ||||||
|
|
||||||
|
|
@@ -623,7 +636,10 @@ def get_path(self, path: str, is_src: bool = True) -> File | Folder: | |||||
| file_found = False | ||||||
| if rpath == self.subpath.as_posix(): | ||||||
| if is_src: | ||||||
| raise ValueError("Cannot move current working directory") | ||||||
| raise ValueError( | ||||||
| "Cannot move current working directory. " | ||||||
| "Change to a different directory before moving this location." | ||||||
| ) | ||||||
| else: | ||||||
| return Folder(rpath, []) | ||||||
| for p in self.assets.keys(): | ||||||
|
|
@@ -640,7 +656,10 @@ def get_path(self, path: str, is_src: bool = True) -> File | Folder: | |||||
| if relcontents: | ||||||
| return Folder(rpath, relcontents) | ||||||
| if needs_dir and file_found: | ||||||
| raise ValueError(f"Remote path {path!r} is a file") | ||||||
| raise ValueError( | ||||||
| f"Remote path {path!r} is a file but a directory was expected. " | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. definitely should not be both |
||||||
| "Use a path ending with '/' for directories." | ||||||
| ) | ||||||
| elif ( | ||||||
| not needs_dir | ||||||
| and not is_src | ||||||
|
|
@@ -652,7 +671,11 @@ def get_path(self, path: str, is_src: bool = True) -> File | Folder: | |||||
| # remote directory. | ||||||
| return Folder(rpath, []) | ||||||
| else: | ||||||
| raise NotFoundError(f"No asset at remote path {path!r}") | ||||||
| raise NotFoundError( | ||||||
| f"No asset at remote path {path!r}. " | ||||||
CodyCBakerPhD marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| "Verify the path is correct and the asset exists on the server. " | ||||||
| "Use 'dandi ls' to list available assets." | ||||||
| ) | ||||||
|
|
||||||
| def is_dir(self, path: AssetPath) -> bool: | ||||||
| """Returns true if the given path points to a directory""" | ||||||
|
|
@@ -902,7 +925,11 @@ def find_dandiset_and_subpath(path: Path) -> tuple[Dandiset, Path]: | |||||
| path = path.absolute() | ||||||
| ds = Dandiset.find(path) | ||||||
| if ds is None: | ||||||
| raise ValueError(f"{path}: not a Dandiset") | ||||||
| raise ValueError( | ||||||
| f"{path}: not a Dandiset. " | ||||||
| f"The directory does not contain a '{dandiset_metadata_file}' file. " | ||||||
CodyCBakerPhD marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| "Use 'dandi download' to download a dandiset first." | ||||||
| ) | ||||||
| return (ds, path.relative_to(ds.path)) | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.