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

More detailed error messages #30

Merged
merged 1 commit into from
Dec 22, 2019
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
25 changes: 17 additions & 8 deletions +bids/+util/tsvread.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%-Check input arguments
%--------------------------------------------------------------------------
if ~exist(f,'file')
error('Unable to read file ''%s''',f);
error('Unable to read file ''%s'': file not found',f);
end

if nargin < 2, v = ''; end
Expand All @@ -46,17 +46,20 @@
sts = true;
try
x = tsvread(fz{1});
catch
catch err
sts = false;
err_msg = err.message;
end
delete(fz{1});
rmdir(fileparts(fz{1}));
if ~sts, error('Cannot load ''%s''.',f); end
if ~sts
error('Cannot load file ''%s'': %s.',f,err_msg);
end
otherwise
try
x = load(f);
catch
error('Unknown file format.');
error('Cannot read file ''%s'': Unknown file format.',f);
end
end

Expand All @@ -80,7 +83,8 @@
try
x = x.(fn{v});
catch
error('Invalid data index.');
error('Data index out of range: %d (data contains %d fields)',...
v,numel(fn));
end
end
end
Expand All @@ -89,10 +93,12 @@
try
x = x(:,v);
catch
error('Invalid data index.');
error('Data index out of range: %d (data contains $d columns).',...
v,size(x,2));
end
elseif ~isempty(v)
error('Invalid data index.');
error('Invalid data index. When data is numeric, index must be numeric or empty; got a %s',...
class(v));
end
end

Expand Down Expand Up @@ -153,7 +159,10 @@
else
d = {[]};
end
if rem(numel(d{1}),N), error('Varying number of delimiters per line.'); end
if rem(numel(d{1}),N)
error('Invalid DSV file ''%s'': Varying number of delimiters per line.',...
f);
end
d = reshape(d{1},N,[])';
allnum = true;
for i=1:numel(var)
Expand Down
22 changes: 13 additions & 9 deletions +bids/layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
BIDS = root; % or BIDS = bids.layout(root.root);
return;
else
error('Invalid syntax.');
error('Invalid input: root must be a char filename or a BIDS struct; got a %s',...
class(root));
end
else
error('Too many input arguments.');
end

%-BIDS structure
Expand All @@ -47,21 +46,26 @@
%-Validation of BIDS root directory
%==========================================================================
if ~exist(BIDS.dir,'dir')
error('BIDS directory does not exist.');
error('BIDS directory does not exist: ''%s''',BIDS.dir);
elseif ~exist(fullfile(BIDS.dir,'dataset_description.json'),'file')
error('BIDS directory not valid: missing dataset_description.json.');
error('BIDS directory not valid: missing dataset_description.json: ''%s''',...
BIDS.dir);
end

%-Dataset description
%==========================================================================
try
BIDS.description = bids.util.jsondecode(fullfile(BIDS.dir,'dataset_description.json'));
catch
error('BIDS dataset description could not be read.');
catch err
error('BIDS dataset description could not be read: %s',err.message);
end
if ~isfield(BIDS.description,'BIDSVersion') || ~isfield(BIDS.description,'Name')
error('BIDS dataset description not valid.');
if ~isfield(BIDS.description,'BIDSVersion')
error('BIDS dataset description not valid: missing BIDSVersion field');
end
if ~isfield(BIDS.description,'Name')
error('BIDS dataset description not valid: missing Name field');
end

% See also optional README and CHANGES files

%-Optional directories
Expand Down
4 changes: 2 additions & 2 deletions +bids/private/file_utils.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
case 'fpath'
str{n} = fileparts(char(cpath(str(n))));
otherwise
error('Unknown option.');
error('Unknown option: ''%s''',options{1});
end
end
options = {};
Expand Down Expand Up @@ -186,7 +186,7 @@
case 'fplist'
fp = true;
otherwise
error('Invalid syntax.');
error('Invalid action: ''%s''.',action);
end
if nargin < 2
d = pwd;
Expand Down
2 changes: 1 addition & 1 deletion +bids/private/parse_filename.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
try
p = orderfields(p,['filename','ext','type',fields]);
catch
warning('Ignoring file "%s" not matching template.',filename);
warning('Ignoring file ''%s'' not matching template.',filename);
p = struct([]);
end
end
7 changes: 2 additions & 5 deletions +bids/query.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
% Copyright (C) 2016-2018, Guillaume Flandin, Wellcome Centre for Human Neuroimaging
% Copyright (C) 2018--, BIDS-MATLAB developers


if nargin < 2
error('Not enough input arguments.');
end
narginchk(2,Inf);

BIDS = bids.layout(BIDS);

Expand Down Expand Up @@ -147,7 +144,7 @@
result(cellfun('isempty',result)) = [];
end
otherwise
error('Unable to perform BIDS query.');
error('Invalid query input: ''%s''', query);
end


Expand Down
3 changes: 1 addition & 2 deletions tests/bids_runtests.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
fprintf('%s',d(i).name(1:end-2));
feval(d(i).name(1:end-2));
results(i).Passed = true;
catch
catch err
results(i).Failed = true;
err = lasterror;
fprintf('\n%s',err.message);
end

Expand Down
5 changes: 2 additions & 3 deletions tests/test_bids_examples.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ function test_bids_examples(pth)
BIDS = bids.layout(fullfile(pth,d(i).name));
sts(i) = true;
fprintf('.');
catch
catch err
fprintf('X');
le = lasterror;
msg{i} = le.message;
msg{i} = err.message;
end
end
fprintf('\n');
Expand Down