Skip to content

Commit

Permalink
store_sos: Replace assertion with type mismatch error message
Browse files Browse the repository at this point in the history
  • Loading branch information
nichamon authored and tom95858 committed Nov 27, 2024
1 parent 72a04a1 commit ffd70a8
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions ldms/src/store/store_sos.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,13 @@ __store_metric(sos_obj_t obj, sos_attr_t attr, ldms_set_t set,
ldms_metric_type_to_str(metric_type),
sos_type_map[metric_type]);
if (sos_attr_type(attr) != sos_type_map[metric_type]) {
assert(0);
LOG_(LDMSD_LERROR, "Attribute '%s' type mismatch: " \
"attribute expects %s but got %s.\n",
sos_attr_name(attr),
_sos_type_sym_tbl[sos_attr_type(attr)],
_sos_type_sym_tbl[sos_type_map[metric_type]]);
errno = EINVAL;
return NULL;
}
if (NULL == sos_value_init(value, obj, attr)) {
LOG_(LDMSD_LERROR, "Error initializing '%s' attribute\n",
Expand All @@ -1058,7 +1064,13 @@ __store_metric(sos_obj_t obj, sos_attr_t attr, ldms_set_t set,
ldms_metric_type_to_str(metric_type),
sos_type_map[metric_type]);
if (sos_attr_type(attr) != sos_type_map[metric_type]) {
assert(0);
LOG_(LDMSD_LERROR, "Attribute '%s' type mismatch: " \
"attribute expects %s but got %s.\n",
sos_attr_name(attr),
_sos_type_sym_tbl[sos_attr_type(attr)],
_sos_type_sym_tbl[sos_type_map[metric_type]]);
errno = EINVAL;
return NULL;
}
esz = __element_byte_len(metric_type);
if (metric_type == LDMS_V_CHAR_ARRAY) {
Expand All @@ -1080,7 +1092,13 @@ __store_metric(sos_obj_t obj, sos_attr_t attr, ldms_set_t set,
}
array_len *= esz;
count = sos_value_memcpy(array_value, mval, array_len);
assert(count == array_len);
if (count != array_len) {
LOG_(LDMSD_LERROR, "Attribute '%s' has mismatched length: " \
"expected %zu but got %d.\n", sos_attr_name(attr),
count, array_len);
errno = E2BIG;
return NULL;
}
sos_value_put(array_value);
attr = sos_schema_attr_next(attr);
}
Expand Down Expand Up @@ -1353,13 +1371,20 @@ store(ldmsd_store_handle_t _sh, ldms_set_t set,
si->ts_attr = sos_schema_attr_by_name(si->sos_schema, "timestamp");
si->first_attr = sos_schema_attr_by_name(si->sos_schema,
ldms_metric_name_get(set, metric_arry[0]));
if (si->comp_id_idx < 0)
if (si->comp_id_idx < 0) {
LOG_(LDMSD_LINFO,
"The component_id is missing from the metric set/schema.\n");
if (si->job_id_idx < 0)
}
if (si->job_id_idx < 0) {
LOG_(LDMSD_LERROR,
"The job_id is missing from the metric set/schema.\n");
assert(si->ts_attr);
}
if (!si->ts_attr) {
LOG_(LDMSD_LERROR,
"store_sos: Attribute 'timestamp' is missing.\n");
errno = EINVAL;
goto err;
}
}
if (timeout > 0) {
clock_gettime(CLOCK_REALTIME, &now);
Expand Down

0 comments on commit ffd70a8

Please sign in to comment.