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

log full stack traces on error #37

Merged
merged 3 commits into from
Sep 30, 2015
Merged
Changes from 2 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 @@ -39,7 +39,6 @@ public class PublishHook implements CRUDHook, LightblueFactoryAware {

public static final String HOOK_NAME = "publishHook";
public static final String ENTITY_NAME = "esbEvents";
public static final String ERR_MISSING_ID = HOOK_NAME + ":MissingID";

private LightblueFactory lightblueFactory;
private static transient JsonNodeFactory factory = JsonNodeFactory.withExactBigDecimals(true);
Expand Down Expand Up @@ -102,18 +101,13 @@ public void processHook(EntityMetadata entityMetadata, HookConfiguration hookCon
if (eventConfiguration.getRootIdentityFields() != null && eventConfiguration.getRootIdentityFields().size() > 0) {
event.addRootIdentities(getRootIdentities(event.getIdentity(), eventConfiguration.getRootIdentityFields()));
}
try {
insert(ENTITY_NAME, event);
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException
| InstantiationException | IOException e) {
LOGGER.error("Unexpected error", e);
}

insert(ENTITY_NAME, event);
}
}
}
} catch (IllegalArgumentException | JSONException e) {
LOGGER.error(e.toString());
throw Error.get(HOOK_NAME + ":UnexpectedException", e);
}
}
}
Expand All @@ -133,25 +127,29 @@ private List<Identity> getRootIdentities(List<Identity> identities, List<String>
return rootIdentities;
}

private void insert(String entityName, Object entity) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, IOException,
NoSuchMethodException, InstantiationException {
private void insert(String entityName, Object entity) {
ObjectNode jsonNode = new ObjectNode(JsonNodeFactory.instance);
jsonNode.put("entity", entityName);
ArrayNode data = jsonNode.putArray("data");
data.add(new ObjectMapper().valueToTree(entity));

InsertionRequest ireq = InsertionRequest.fromJson(jsonNode);
Response r = lightblueFactory.getMediator().insert(ireq);
Response r;
try {
r = lightblueFactory.getMediator().insert(ireq);
} catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException | IOException e) {
throw Error.get(HOOK_NAME + ":MediatorException", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means there is a configuration error. You can throw a runtime exception for this one.

}
if (!r.getErrors().isEmpty()) {
// TODO Better Handle Exception
for (Error e : r.getErrors()) {
LOGGER.error(e.toString());
LOGGER.error("Lightblue Error", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more descriptive error message would be useful here. Same for the next one,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use a different logger, and send the error logs to a separate logfile?

}
throw Error.get(HOOK_NAME + ":Error", "Errors while attempting to insert esb events.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Naveen. Log errors, don't throw.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bserdar does the hook framework protect against implementations throwing
unchecked exception?

On Wed, Sep 30, 2015 at 9:27 AM, Burak Serdar notifications@github.com
wrote:

In
publish-hook/src/main/java/com/redhat/lightblue/hook/publish/PublishHook.java
#37 (comment)
:

         }
  •        throw Error.get(HOOK_NAME + ":Error", "Errors while attempting to insert esb events.");
    

Agree with Naveen. Log errors, don't throw.


Reply to this email directly or view it on GitHub
https://github.com/lightblue-platform/lightblue-esb-hook/pull/37/files#r40792451
.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mediator catches all exceptions at the end, and anything that's not handled
ends up at the client side as a generic error.

On Wed, Sep 30, 2015 at 7:28 AM, Naveen Malik notifications@github.com
wrote:

In
publish-hook/src/main/java/com/redhat/lightblue/hook/publish/PublishHook.java
#37 (comment)
:

         }
  •        throw Error.get(HOOK_NAME + ":Error", "Errors while attempting to insert esb events.");
    

@bserdar https://github.com/bserdar does the hook framework protect
against implementations throwing unchecked exception?
… <#1501e71126211ccb_>
On Wed, Sep 30, 2015 at 9:27 AM, Burak Serdar notifications@github.com
wrote: In
publish-hook/src/main/java/com/redhat/lightblue/hook/publish/PublishHook.java
<
https://github.com/lightblue-platform/lightblue-esb-hook/pull/37#discussion_r40792451>
: > } > + throw Error.get(HOOK_NAME + ":Error", "Errors while attempting to
insert esb events."); Agree with Naveen. Log errors, don't throw. — Reply
to this email directly or view it on GitHub <
https://github.com/lightblue-platform/lightblue-esb-hook/pull/37/files#r40792451>
.


Reply to this email directly or view it on GitHub
https://github.com/lightblue-platform/lightblue-esb-hook/pull/37/files#r40792573
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created lightblue-platform/lightblue-core#486

On Wed, Sep 30, 2015 at 9:30 AM, Burak Serdar notifications@github.com
wrote:

In
publish-hook/src/main/java/com/redhat/lightblue/hook/publish/PublishHook.java
#37 (comment)
:

         }
  •        throw Error.get(HOOK_NAME + ":Error", "Errors while attempting to insert esb events.");
    

Mediator catches all exceptions at the end, and anything that's not
handled ends up at the client side as a generic error.
… <#1501e72d29a29673_>
On Wed, Sep 30, 2015 at 7:28 AM, Naveen Malik notifications@github.com
wrote: In
publish-hook/src/main/java/com/redhat/lightblue/hook/publish/PublishHook.java
<
https://github.com/lightblue-platform/lightblue-esb-hook/pull/37#discussion_r40792573>
: > } > + throw Error.get(HOOK_NAME + ":Error", "Errors while attempting to
insert esb events."); @bserdar https://github.com/bserdar <
https://github.com/bserdar> does the hook framework protect against
implementations throwing unchecked exception? … <#1501e71126211ccb_> On
Wed, Sep 30, 2015 at 9:27 AM, Burak Serdar notifications@github.com
wrote: In
publish-hook/src/main/java/com/redhat/lightblue/hook/publish/PublishHook.java
<
https://github.com/lightblue-platform/lightblue-esb-hook/pull/37#discussion_r40792451>
: > } > + throw Error.get(HOOK_NAME + ":Error", "Errors while attempting to
insert esb events."); Agree with Naveen. Log errors, don't throw. — Reply
to this email directly or view it on GitHub <
https://github.com/lightblue-platform/lightblue-esb-hook/pull/37/files#r40792451>
. — Reply to this email directly or view it on GitHub <
https://github.com/lightblue-platform/lightblue-esb-hook/pull/37/files#r40792573>
.


Reply to this email directly or view it on GitHub
https://github.com/lightblue-platform/lightblue-esb-hook/pull/37/files#r40792791
.

} else if (!r.getDataErrors().isEmpty()) {
// TODO Better Handle Exception
for (DataError e : r.getDataErrors()) {
LOGGER.error(e.toString());
LOGGER.error("Lightblue Data Error", e);
}
throw Error.get(HOOK_NAME + ":DataError", "Eata errors while attempting to insert esb events.");
}
}

Expand Down