Skip to content

Commit

Permalink
More descriptive errors for other handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
benfitzpatrick committed Jan 17, 2024
1 parent 997323e commit 28e76e2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
7 changes: 4 additions & 3 deletions metomi/rose/config_processors/fileinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _process(self, conf_tree, nodes, loc_dao, **kwargs):
source.scheme = scheme
break
self.loc_handlers_manager.parse(source, conf_tree)
except ValueError:
except ValueError as exc:
if source.is_optional:
sources.pop(source.name)
for name in source.used_by_names:
Expand All @@ -216,6 +216,7 @@ def _process(self, conf_tree, nodes, loc_dao, **kwargs):
raise ConfigProcessError(
["file:" + source.used_by_names[0], "source"],
source.name,
exc
)
prev_source = loc_dao.select(source.name)
source.is_out_of_date = (
Expand Down Expand Up @@ -852,7 +853,7 @@ def parse(self, loc, conf_tree):
# Scheme specified in the configuration.
handler = self.get_handler(loc.scheme)
if handler is None:
raise ValueError(loc.name)
raise ValueError(f"don't support scheme {loc.scheme}")
else:
# Scheme not specified in the configuration.
scheme = urlparse(loc.name).scheme
Expand All @@ -861,7 +862,7 @@ def parse(self, loc, conf_tree):
if handler is None:
handler = self.guess_handler(loc)
if handler is None:
raise ValueError(loc.name)
raise ValueError(f"don't know how to process {loc.name}")
else:
handler = self.get_handler(self.DEFAULT_SCHEME)
return handler.parse(loc, conf_tree)
Expand Down
2 changes: 1 addition & 1 deletion metomi/rose/loc_handlers/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def parse(cls, loc, _):
loc.scheme = "fs"
name = os.path.expanduser(loc.name)
if not os.path.exists(name):
raise ValueError(loc.name)
raise ValueError(f"path does not exist or not accessible: {name}")
paths_and_checksums = get_checksum(name)
for path, checksum, access_mode in paths_and_checksums:
loc.add_path(path, checksum, access_mode)
Expand Down
2 changes: 1 addition & 1 deletion metomi/rose/loc_handlers/namelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def parse(self, loc, conf_tree):
if section_value is None:
sections.remove(section)
if not sections:
raise ValueError(loc.name)
raise ValueError(f"could not locate {loc.name}")
return sections

async def pull(self, loc, conf_tree):
Expand Down
2 changes: 1 addition & 1 deletion metomi/rose/loc_handlers/rsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def parse(self, loc, _):
out = self.manager.popen(*cmd, stdin=stdin)[0]
lines = out.splitlines()
if not lines or lines[0] not in [loc.TYPE_BLOB, loc.TYPE_TREE]:
raise ValueError(loc.name)
raise ValueError(f"could not locate {path} on host {host}")
loc.loc_type = lines.pop(0)
if loc.loc_type == loc.TYPE_BLOB:
line = lines.pop(0)
Expand Down
15 changes: 13 additions & 2 deletions t/rose-app-run/05-file.t
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Hello and good bye.
__CONTENT__
OUT=$(cd config/file && cat hello1 hello2 hello3/text)
#-------------------------------------------------------------------------------
tests 62
tests 65
#-------------------------------------------------------------------------------
# Normal mode with free format files.
TEST_KEY=$TEST_KEY_BASE
Expand All @@ -70,7 +70,18 @@ run_fail "$TEST_KEY" rose app-run --config=../config -q \
--define='[file:hello4]source=stuff:ing'
file_cmp "$TEST_KEY.out" "$TEST_KEY.out" </dev/null
file_cmp "$TEST_KEY.err" "$TEST_KEY.err" <<'__CONTENT__'
[FAIL] file:hello4=source=stuff:ing: bad or missing value
[FAIL] file:hello4=source=stuff:ing: don't know how to process stuff:ing
__CONTENT__
test_teardown
#-------------------------------------------------------------------------------
# Normal mode with free format files and a file with an invalid scheme.
TEST_KEY=$TEST_KEY_BASE-invalid-content
test_setup
run_fail "$TEST_KEY" rose app-run --config=../config -q \
--define='schemes=stuff*=where_is_the_stuff' --define='[file:hello4]source=stuff:ing'
file_cmp "$TEST_KEY.out" "$TEST_KEY.out" </dev/null
file_cmp "$TEST_KEY.err" "$TEST_KEY.err" <<'__CONTENT__'
[FAIL] file:hello4=source=stuff:ing: don't support scheme where_is_the_stuff
__CONTENT__
test_teardown
#-------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions t/rose-app-run/06-namelist.t
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ run_fail "$TEST_KEY" rose app-run --config=../config -q \
'--define=[file:shopping-list-3.nl]source=namelist:shopping_list'
file_cmp "$TEST_KEY.out" "$TEST_KEY.out" </dev/null
file_cmp "$TEST_KEY.err" "$TEST_KEY.err" <<'__CONTENT__'
[FAIL] file:shopping-list-3.nl=source=namelist:shopping_list: bad or missing value
[FAIL] file:shopping-list-3.nl=source=namelist:shopping_list: could not locate namelist:shopping_list
__CONTENT__
test_teardown
#-------------------------------------------------------------------------------
Expand All @@ -221,7 +221,7 @@ run_fail "$TEST_KEY" rose app-run --config=../config -q \
'--define=[!namelist:shopping_list]'
file_cmp "$TEST_KEY.out" "$TEST_KEY.out" </dev/null
file_cmp "$TEST_KEY.err" "$TEST_KEY.err" <<'__CONTENT__'
[FAIL] file:shopping-list-3.nl=source=namelist:shopping_list: bad or missing value
[FAIL] file:shopping-list-3.nl=source=namelist:shopping_list: could not locate namelist:shopping_list
__CONTENT__
test_teardown
#-------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion t/rose-app-run/15-file-permission.t
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ run_fail "$TEST_KEY" rose app-run --config=../config -q
file_cmp "$TEST_KEY.out" "$TEST_KEY.out" <<'__OUT__'
__OUT__
file_cmp "$TEST_KEY.err" "$TEST_KEY.err" <<__ERR__
[FAIL] file:qux=source=$TEST_DIR/no_read_target_dir/qux: bad or missing value
[FAIL] file:qux=source=$TEST_DIR/no_read_target_dir/qux: path does not exist or not accessible: $TEST_DIR/no_read_target_dir/qux
__ERR__
chmod u+x $TEST_DIR/no_read_target_dir
rm $TEST_DIR/no_read_target_dir/qux
Expand Down

0 comments on commit 28e76e2

Please sign in to comment.