-
Notifications
You must be signed in to change notification settings - Fork 29
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
Logging field specification and value extraction errors #519
Conversation
- add exception when the field cannot be computed - change color of error log in the data export runner - renaming in percentile field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good in general, please look at the comments.
try { | ||
value = ((SingleValueField) field).valueForSubject(subject, timeStamp); | ||
} catch (IncomputableFieldException e){ | ||
// Keep calm and continue processing ... we will back-off | ||
continue; | ||
} catch (ClassCastException cce) { | ||
throw new IllegalArgumentException("Parameters for BackOffField must be of type SingleValueField."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think exception here is redundant, as we are already catching that in initialize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching a different one here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which one? I think we are looping over the same fields which are added through intialize
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ClassCastException
here and ClassNotFoundException
in initialize()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad, i was always reading class. Need to start reading class names more thoroughly :)
@@ -71,11 +71,11 @@ protected void initialize(){ | |||
try { | |||
Field field = fieldRecipe.toField(); | |||
if (!(field instanceof SingleValueField)) | |||
throw new IncomputableFieldException("Parameters for DescriptiveStatisticsField must be of type SingleValueField"); | |||
throw new IllegalArgumentException("Parameters for DescriptiveStatisticsField must be of type SingleValueField"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Earlier we were trying to cast to field and then throwing as cast exception, here we are using a different approach for same thing, it feels to me a little inconsistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't say it's inconsistent as it expresses a different way of doing the same thing, which does not manifest inconsistency in the behaviour itself. I would say that both ways are acceptable. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the consistency of writing code i was talking about not the intended behaviour. It just looks more neat. However it's okay if you would prefer this way
|
||
try { | ||
singleValueFields = new ArrayList<>(); | ||
|
||
for (FieldRecipe fieldRecipe: fields) { | ||
Field field = fieldRecipe.toField(); | ||
if (!(field instanceof SingleValueField)) | ||
throw new IncomputableFieldException("Parameters for LinearCombinationField must be of type SingleValueField"); | ||
throw new IllegalArgumentException("Parameters for LinearCombinationField must be of type SingleValueField"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if we follow the same approach of cast and catching the exception, just to be consistent
throw new IncomputableFieldException(String.format("No attribute found for provider %s and label %s", attribute.provider, attribute.label)); | ||
} else { | ||
attributeObject = attr; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't that the attributeObject
will always be null
when this field is called as the object is private and is not initialised. Can we write it like
Attribute attr = AttributeUtils.getByProviderAndLabel(attribute.provider, attribute.label);
if (null == attr) {
throw new IncomputableFieldException(String.format("No attribute found for provider %s and label %s", attribute.provider, attribute.label));
}
return attr;
and remove the above attributeObject
if (timedValues.isEmpty()) { | ||
throw new IncomputableFieldException(String.format("No TimedValue found for attribute %s", getAttribute().getLabel())); | ||
} | ||
arr.addAll(timedValues.stream().map(timedValue -> { | ||
JSONObject pair = new JSONObject(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's empty we can just return after throwing the exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't get far after the exception is thrown. What I can do is create the json array object after so we don't waste one.
if (timedValue.isEmpty()) { | ||
throw new IncomputableFieldException(String.format("No TimedValue found for attribute %s", getAttribute().getLabel())); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can return from here if it is empty
@@ -69,8 +69,12 @@ public void write(Writer writer, List<Subject> subjects, List<Field> fields, Boo | |||
try { | |||
property.put(field.getLabel(), ((SingleValueField) field).valueForSubject(subject, timeStamp)); | |||
} catch (IncomputableFieldException e) { | |||
log.warn("Could not compute Field {} for Subject {}, reason: {}", field.getLabel(), subject.getLabel(), e.getMessage()); | |||
log.warn("\u001b[0;33m" + "Could not compute Field {} for Subject {}, reason: {}" + "\u001b[m", | |||
field.getLabel(), subject.getLabel(), e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if we could have a constant class containing these formats, so that we dont have to write them again and again when required, we could just refer to those constants.
@arya-hemanshu can you have another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to merge
Description
Fixes #269
Checklist
Created new test(s) (if applicable)Updated the README / documentation (if applicable)