Skip to content
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

Add Error handling for closure parameters #1102

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading