Skip to content

Commit 8abd4d5

Browse files
author
Enric Sala
committed
Throw an exception when adding a field with an empty value
1 parent 2cff8d5 commit 8abd4d5

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

influxdb-client/Point.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
% Add a field value
2727
function obj = field(obj, key, value)
28-
if isfloat(value)
28+
if isempty(value)
29+
error('field:emptyValue', 'value of field "%s" is empty', key);
30+
elseif isfloat(value)
2931
obj.Fields{end + 1} = sprintf('%s=%.8g', key, value);
3032
elseif isinteger(value)
3133
obj.Fields{end + 1} = sprintf('%s=%ii', key, value);

influxdb-client/Series.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
% Add a field value
2727
function obj = field(obj, key, value)
2828
if isempty(value)
29-
warning(['value of field ' key ' is empty']);
29+
error('field:emptyValue', 'value of field "%s" is empty', key);
3030
elseif isnumeric(value) || islogical(value)
3131
field = struct('key', key, 'value', value);
3232
obj.Fields{end + 1} = field;

tests/PointTest.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ function build_fails_when_empty_fields(test)
1111
test.verifyError(f, 'toLine:emptyFields');
1212
end
1313

14+
function field_with_empty_value_fails(test)
15+
f = @() Point('weather').fields('temperature', []);
16+
test.verifyError(f, 'field:emptyValue');
17+
end
18+
1419
function single_field(test)
1520
p = Point('weather').fields('temperature', 24.3);
1621
exp = 'weather temperature=24.3';

tests/SeriesTest.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ function fails_when_fields_are_not_set(test)
2929
test.verifyError(@() s.toLine(), 'toLine:emptyFields');
3030
end
3131

32+
function field_with_empty_value_fails(test)
33+
f = @() Series('weather') ...
34+
.fields('temperature', []);
35+
test.verifyError(f, 'field:emptyValue');
36+
end
37+
3238
function single_field(test)
3339
s = Series('weather') ...
3440
.time(test.Time) ...

0 commit comments

Comments
 (0)