Skip to content

Commit

Permalink
Add error handling for closure params
Browse files Browse the repository at this point in the history
  • Loading branch information
akats7 committed Nov 28, 2023
1 parent cd19fcb commit 9d47952
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,18 @@ class InstrumentHelper {
private static Map<String, String> getLabels(GroovyMBean mbean, Map<String, Closure> labelFuncs, Map<String, Closure> additionalLabels) {
def labels = [:]
labelFuncs.each { label, labelFunc ->
labels[label] = labelFunc(mbean) as String
try {
labels[label] = labelFunc(mbean) as String
} catch(AttributeNotFoundException e) {
logger.warning("Attribute missing for label:${label}, label was not applied")
}
}
additionalLabels.each { label, labelFunc ->
labels[label] = labelFunc(mbean) as String
try {
labels[label] = labelFunc(mbean) as String
} catch(AttributeNotFoundException e) {
logger.warning("Attribute missing for label:${label}, label was not applied")
}
}
return labels
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,16 @@ class MBeanHelper {
}

Object getBeanAttributeWithTransform(GroovyMBean bean, String attribute){
def transformationClosure = attributeTransformation.get(attribute);
return transformationClosure != null ? transformationClosure(bean) : getBeanAttribute(bean, attribute)
def transformationClosure = attributeTransformation.get(attribute);
if (transformationClosure == null) {
return getBeanAttribute(bean, attribute)
}
try {
return transformationClosure(bean)
} catch(AttributeNotFoundException e) {
logger.warning("Transformed attribute not found in ${bean.name()}")
return null
}
}

static Object getBeanAttribute(GroovyMBean bean, String attribute) {
Expand Down

0 comments on commit 9d47952

Please sign in to comment.