Skip to content

Commit d970ef1

Browse files
authored
Add ErrorID and warningID for all user-facing code (#617)
* Add warning IDs for where missing * Add errorID where missing * Add errorIDs to class generators and update regenerate types with errorIDs * Add errorID to checkCustomConstraint method of TimeSeries
1 parent 5aa27d9 commit d970ef1

39 files changed

+120
-67
lines changed

+file/Dataset.m

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,19 @@
121121

122122
%constrained
123123
% error unless it defines the object.
124-
125-
if isempty(obj.type)
126-
error('You shouldn''t be calling getProps on an untyped dataset');
127-
end
128-
129-
if obj.isConstrainedSet && ~obj.definesType
130-
error('You shouldn''t be calling getProps on a constrained dataset');
131-
end
132-
124+
125+
assert(...
126+
~isempty(obj.type), ...
127+
'NWB:Dataset:UnsupportedOperation', ...
128+
'The method `getProps` should not be called on an untyped dataset.' ...
129+
);
130+
131+
assert( ...
132+
~obj.isConstrainedSet || obj.definesType, ...
133+
'NWB:Dataset:UnsupportedOperation', ...
134+
'The method `getProps` should not be called on constrained dataset.' ...
135+
);
136+
133137
if ~isempty(obj.dtype)
134138
props('data') = obj.dtype;
135139
end

+file/Group.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,14 @@
146146
%should never happen
147147

148148
if obj.isConstrainedSet && ~obj.definesType
149-
error('getProps shouldn''t be called on a constrained set.');
149+
error('NWB:Group:UnsupportedOperation', ...
150+
'The method `getProps` should not be called on a constrained dataset.');
150151
end
152+
assert( ...
153+
~obj.isConstrainedSet || obj.definesType, ...
154+
'NWB:Group:UnsupportedOperation', ...
155+
'The method `getProps` should not be called on a constrained group.' ...
156+
);
151157

152158
%datasets
153159
for i=1:length(obj.datasets)

+file/fillConstructor.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@
100100
end
101101
end
102102

103-
%warn for missing namespaces/property types
103+
% warn for missing namespaces/property types
104+
warningId = 'NWB:ClassGenerator:NamespaceOrTypeNotFound';
104105
warnmsg = ['`' parentName '`''s constructor is unable to check for type `%1$s` ' ...
105106
'because its namespace or type specifier could not be found. Try generating ' ...
106107
'the namespace or class definition for type `%1$s` or fix its schema.'];
@@ -109,7 +110,7 @@
109110
invalidWarn = invalid & (dynamicConstrained | isAnonymousType) & ~isAttribute;
110111
invalidVars = varnames(invalidWarn);
111112
for i=1:length(invalidVars)
112-
warning(warnmsg, invalidVars{i});
113+
warning(warningId, warnmsg, invalidVars{i});
113114
end
114115
varnames = lower(varnames);
115116

+file/fillCustomConstraint.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
customConstraintStr = sprintf( [...
1313
'function checkCustomConstraint(obj)\n', ...
1414
' assert(~isempty(obj.timestamps) || ~isempty(obj.starting_time), ...\n', ...
15+
' ''NWB:TimeSeries:TimeNotSpecified'', ...\n ', ...
1516
' "''timestamps'' or ''starting_time'' must be specified")\n', ...
1617
' if ~isempty(obj.starting_time)\n', ...
1718
' assert(~isempty(obj.starting_time_rate), ...\n', ...
19+
' ''NWB:TimeSeries:RateMissing'', ...\n', ...
1820
' "''starting_time_rate'' must be specified when ''starting_time'' is specified")\n', ...
1921
' end\n', ...
2022
'end'] );

+file/fillProps.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
case 'object'
5959
refTypeName = 'Object';
6060
otherwise
61-
error('Invalid reftype found whilst filling Constructor prop docs.');
61+
error('NWB:ClassGenerator:InvalidRefType', ...
62+
'Invalid reftype found while filling description for class property "%s".', propName);
6263
end
6364
typeStr = sprintf('%s Reference to %s', refTypeName, prop.dtype('target_type'));
6465
else
@@ -71,7 +72,8 @@
7172
case 'object'
7273
refTypeName = 'object';
7374
otherwise
74-
error('Invalid reftype found whilst filling Constructor prop docs.');
75+
error('NWB:ClassGenerator:InvalidRefType', ...
76+
'Invalid reftype found while filling description for class property "%s".', propName);
7577
end
7678
typeStr = sprintf('%s Reference to %s', refTypeName, prop('target_type'));
7779
elseif isa(prop, 'file.interface.HasProps')

+file/fillValidators.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
' return;'...
241241
'end'...
242242
'if ~istable(val) && ~isstruct(val) && ~isa(val, ''containers.Map'')'...
243-
[' error(''Property `' name '` must be a table,struct, or containers.Map.'');']...
243+
[' error(''NWB:Type:InvalidPropertyType'', ''Property `' name '` must be a table, struct, or containers.Map.'');']...
244244
'end'...
245245
'vprops = struct();'...
246246
}, newline);
@@ -294,8 +294,7 @@
294294

295295
classNameSplit = strsplit(className, '.');
296296
shortName = classNameSplit{end};
297-
298-
errorStr = sprintf( 'error(''Unable to set the ''''%s'''' property of class ''''<a href="matlab:doc %s">%s</a>'''' because it is read-only.'')', name, className, shortName);
297+
errorStr = sprintf( 'error(''NWB:Type:ReadOnlyProperty'', ''Unable to set the ''''%s'''' property of class ''''<a href="matlab:doc %s">%s</a>'''' because it is read-only.'')', name, className, shortName);
299298

300299
if ischar(value)
301300
condition = strjoin({ ...
@@ -311,7 +310,8 @@
311310
% Note: According to the documentation for Attribute specification keys
312311
% (https://schema-language.readthedocs.io/en/latest/description.html#sec-attributes-spec),
313312
% the above cases should be sufficient.
314-
error('Unhandled case')
313+
error('NWB:ClassGenerator:ReadOnlyValidatorNotImplemented', ...
314+
'Read-only validator is not implemented for values of type "%s"', class(value))
315315
end
316316

317317
fdvstr = strjoin({...

+io/getBaseType.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
id = [prefix suffix];
4747
else
48-
error('Type `%s` is not a supported raw type', type);
48+
error('NWB:IO:UnsupportedBaseType', ...
49+
'Type `%s` is not a supported raw type', type);
4950
end
5051
end

+io/parseGroup.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@
116116
if any(leads)
117117
%since set has been edited, we bubble up deletion of the old keys.
118118
subset = elide(pvalue, prop(leads), pvar);
119-
elided = [elided; subset];
119+
elided = [elided; subset]; %#ok<AGROW>
120120
if pvalue.Count == 0
121121
drop(i) = true;
122122
elseif any(strcmp(pvar, prop))
123123
elided(pvar) = pvalue;
124124
drop(i) = true;
125125
else
126-
warning('Unable to match property `%s` under prefix `%s`',...
126+
warning('NWB:Parse:UnmatchedProperty', 'Unable to match property `%s` under prefix `%s`',...
127127
pvar, prefix);
128128
end
129129
end

+io/resolvePath.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
%process slash tokens
1010
o = nwb;
11-
errmsg = 'Could not resolve path `%s`.';
1211
while ~isempty(tokens)
1312
if isa(o, 'types.untyped.Set')
1413
[o, tokens] = resolveSet(o, tokens);
@@ -18,7 +17,7 @@
1817
[o, tokens] = resolveObj(o, tokens);
1918
end
2019
if isempty(o)
21-
error(errmsg, path);
20+
error('NWB:IO:UnresolvedPath', 'Could not resolve path `%s`.', path);
2221
end
2322
end
2423
end

+io/timestamp2datetime.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@
113113
elseif ischar(timestamps)
114114
cells = {timestamps};
115115
else
116-
errorId = "NWB:timestamp2datetime:MustBeCharCellArrayOrString";
117-
errorMsg = ['timestamps must be a string, character array, ', ...
118-
'or cell array of strings/character arrays.'];
119-
error(errorId, errorMsg);
116+
error('NWB:timestamp2datetime:MustBeCharCellArrayOrString', ...
117+
[ 'Timestamps must be a string, character array, ', ...
118+
'or cell array of strings/character arrays.' ]);
120119
end
121120
end

0 commit comments

Comments
 (0)