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

[ENH] improve error message when folder to index does not exist #601

Merged
merged 1 commit into from
Jul 31, 2023
Merged
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
22 changes: 21 additions & 1 deletion +bids/layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@
addParameter(args, 'use_schema', default_use_schema);
addParameter(args, 'verbose', default_verbose);

parse(args, varargin{:});
try
parse(args, varargin{:});
catch ME
handle_invalid_input(ME, varargin{1});
end

root = args.Results.root;
index_derivatives = args.Results.index_derivatives;
Expand Down Expand Up @@ -212,6 +216,22 @@

end

function handle_invalid_input(ME, root)
% TODO improve as this may send the wrong message on octave
% for ANY failed input parsing
if (~bids.internal.is_octave && ...
bids.internal.starts_with(ME.message, ...
'The value of ''root''')) || ...
bids.internal.is_octave
if ischar(root)
msg = sprintf(['First input argument must be an existing directory.'...
'\nGot: ''%s.'''], root);
bids.internal.error_handling(mfilename(), 'InvalidInput', ...
msg, false);
end
end
end

function value = exclude(filter, entity, label)
value = false;
% skip if not included in filter
Expand Down
6 changes: 6 additions & 0 deletions tests/tests_layout/test_layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
initTestSuite;
end

function test_layout_error_message

assertExceptionThrown(@()bids.layout('foo'), 'layout:InvalidInput');

end

function test_layout_filter()

verbose = false;
Expand Down