Skip to content

Commit

Permalink
fix: Provide better error message when encountering an unknown event
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinbyrne committed Apr 7, 2021
1 parent 1c69862 commit c69a877
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void write(JSONSerializer serializer,
out.write(JSON.toJSONString(valuesField.get(params)));
} catch (Exception e) {
Logger.println("failed to serialize parameters");
Logger.println(e.getMessage());
Logger.println(e);
out.writeNull();
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/appland/appmap/record/EventTemplateRegistry.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.appland.appmap.record;

import com.appland.appmap.config.Properties;
import com.appland.appmap.output.v1.CodeObject;
import com.appland.appmap.output.v1.Event;
import com.appland.appmap.output.v1.Value;
import com.appland.appmap.record.UnknownEventException;
import com.appland.appmap.util.Logger;

import javassist.CtBehavior;

import java.util.ArrayList;
Expand Down Expand Up @@ -57,7 +61,7 @@ public synchronized Integer register(Event event, CtBehavior behavior) {
public Event getTemplate(Integer templateId) {
try {
return eventTemplates.get(templateId);
} catch (ArrayIndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException e) {
// fall through
}
return null;
Expand Down Expand Up @@ -85,8 +89,14 @@ public Event cloneEventTemplate(int templateId, String eventAction)
event.addParameter(param);
}
}
} catch (ArrayIndexOutOfBoundsException e) {
throw new UnknownEventException(String.format("unknown template for ordinal %d", templateId));
} catch (IndexOutOfBoundsException e) {
final String msg = String.format("unknown template for ordinal %d - have we been loaded by a non-system class loader?", templateId);

if (Properties.DebugHooks) {
Logger.println(msg);
}

throw new UnknownEventException(msg);
}

return event;
Expand Down

0 comments on commit c69a877

Please sign in to comment.