EnhancerAffect save exception and print the exception message #1224

pull/1229/head
hengyunabc 5 years ago
parent 25c5fb7e7b
commit 41bbedefdb

@ -319,6 +319,7 @@ public class Enhancer implements ClassFileTransformer {
return enhanceClassByteArray;
} catch (Throwable t) {
logger.warn("transform loader[{}]:class[{}] failed.", inClassLoader, className, t);
affect.setThrowable(t);
}
return null;
@ -426,11 +427,12 @@ public class Enhancer implements ClassFileTransformer {
// 过滤掉无法被增强的类
filter(matchingClasses);
logger.info("enhance matched classes: {}", matchingClasses);
affect.setTransformer(this);
try {
ArthasBootstrap.getInstance().getTransformerManager().addTransformer(this, isTracing);
//inst.addTransformer(enhancer, true);
// 批量增强
if (GlobalOptions.isBatchReTransform) {
@ -459,8 +461,9 @@ public class Enhancer implements ClassFileTransformer {
}
}
}
} finally {
//inst.removeTransformer(enhancer);
} catch (Throwable e) {
logger.error("Enhancer error, matchingClasses: {}", matchingClasses, e);
affect.setThrowable(e);
}
return affect;

@ -134,6 +134,12 @@ public abstract class EnhancerCommand extends AnnotatedCommand {
process.register(listener, enhancer);
EnhancerAffect effect = enhancer.enhance(inst);
if (effect.getThrowable() != null) {
process.write(effect.toString() + ", check arthas log: " + LogUtil.loggingFile() + "\n");
process.end(1);
return;
}
if (effect.cCnt() == 0 || effect.mCnt() == 0) {
// no class effected
// might be method code too large

@ -16,6 +16,7 @@ import static java.lang.String.format;
* <br/>
* //
* Created by vlinux on 15/5/19.
* @author hengyunabc 2020-06-01
*/
public final class EnhancerAffect extends Affect {
@ -23,6 +24,9 @@ public final class EnhancerAffect extends Affect {
private final AtomicInteger mCnt = new AtomicInteger();
private ClassFileTransformer transformer;
private long listenerId;
private Throwable throwable;
/**
* dumpClass
*/
@ -101,6 +105,14 @@ public final class EnhancerAffect extends Affect {
this.listenerId = listenerId;
}
public Throwable getThrowable() {
return throwable;
}
public void setThrowable(Throwable throwable) {
this.throwable = throwable;
}
@Override
public String toString() {
final StringBuilder infoSB = new StringBuilder();
@ -122,6 +134,9 @@ public final class EnhancerAffect extends Affect {
mCnt(),
cost(),
listenerId));
if (this.throwable != null) {
infoSB.append("\nEnhance error! exception: " + this.throwable);
}
return infoSB.toString();
}

Loading…
Cancel
Save