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

Feature/load error messages #134

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion lib/gpt/core/io/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
#
import gpt, cgpt
from gpt.params import params_convention
import os


# load through cgpt backend (openQCD, ...)
def load_cgpt(*a):
result = []
r, metadata = cgpt.load(*a, gpt.default.is_verbose("io"))
if r is None:
raise gpt.LoadError()
raise gpt.LoadError(f"file: {a[0]}")
for gr in r:
grid = gpt.grid(gr[1], eval("gpt." + gr[2]), eval("gpt." + gr[3]), gr[0])
result_grid = []
Expand Down Expand Up @@ -65,6 +66,16 @@ def load(fn, **p):
# rules this one out as well
pass

if not os.path.exists(fn):
# XXX: when implementing non-file URLs, change this error message.
raise FileNotFoundError(f"[Errno 2] No such file or directory: '{fn}'")

if os.path.isfile(fn):
if not os.access(fn, os.R_OK):
raise PermissionError(f"[Errno 13] Permission denied: '{fn}'")
if os.path.isdir(fn):
raise gpt.LoadError(f"Error: '{fn}' is a directory and gpt_io failed to process it (permissions[+x] ok? wrong path?).")

a = [fn]
if len(p) > 0:
a.append(p)
Expand Down