One Star

[resolved] How to get the error message from the child job

Dear Helpers,
We have a parent job with a tRunJob component. Both jobs have tLogCatcher inside. Inside the
child job execeptions/errors via tDie can occur. How can the error message passed to the parent
job that calls the sub-job via tRunJob? Are there any globalMap parameters or what approach is
applied for that?
I have found that entry
http://www.talendforge.org/forum/viewtopic.php?id=16284
but it doesn't work.
I am very grateful for any help.
Kind regards
Hilderich
16 REPLIES
Seventeen Stars

Re: [resolved] How to get the error message from the child job

You could try globalMap.get("tRunJob_1_CHILD_EXCEPTION_STACKTRACE") in case of your error is caused by an exception. Normal tDie messages couldn't be retrieved this way.
One Star

Re: [resolved] How to get the error message from the child job

Hello jlolling,
Many thanks for answering. Unfortunately I want exactly the tDie message returned to the parent job. The tLogCatcher in the child job is triggerd by tDie and the message is there also received. The question is how to pass it to the parent job? Do you have the answer?
Kind Regards
Hilderich
Community Manager

Re: [resolved] How to get the error message from the child job

Hi Hilderich
Using a tBufferOutput component in the child job to pass the error message from the child job to the main job. Refer to this KB article:
https://help.talend.com/search/all?query=Returning+a+value+from+a+child+Job+to+the+parent+Job&conten...
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Four Stars

Re: [resolved] How to get the error message from the child job

Hi,
There could be many options to do this.
1) Context variable - enable Transmit whole context. This would transfer the value of context variable to child job.
2) use (getter-setter) routine - Set the error value in subjob and get the same value in parent job
3) Use tFixedFlowInput-->tBuffer in subjob for your error message. Retrieve schema in parent job to get the error message
4) If you are using tlogcatcher - output the result sets to flat file. In parent job read that flat file to see the error message
Thanks
Vaibhav
One Star

Re: [resolved] How to get the error message from the child job

Hello shong, sanvaibhav and jlolling,
As I see there are no limits in being creative. I am grateful for your hints.
Kind regards
Hilderich
One Star

Re: [resolved] How to get the error message from the child job

Hello sanvaibhav,
Your suggestion No 1 explains the return mechanism via context variables. I have tried this but
with no success. Both jobs have one identical context variable 'errorInSubjob' and on tRunJob
the option 'Transmit whole context' is activated. After the sub-job failed and returned back to
the parent job this variable is not set properly. Are there any side attentions to take care?
Kind regards
Hilderich
One Star

Re: [resolved] How to get the error message from the child job

Hilderich - "Transmit whole context" goes from Parent to Child, not the other way around. The other methods described here would give you that - Talend in-built global variables, tBufferOutput, a global hashmap variable (set/get), a file).
One Star

Re: [resolved] How to get the error message from the child job

Hello All,
I have solved it with a context variable of type Object and assigned to it a Map.
In the sub-job I have put an entry of type string into the map and then I was able to
read it afterwards in my parent job. I have done my "job".
Kind regards
Hilderich
Four Stars

Re: [resolved] How to get the error message from the child job

Hilderich,
As Willm said, transmit whole context is applicable for parent to child and not from child to parent. But enabling that check box, allows bi-directional flow of variables, else it won't. Resetting the context variable value of parent job is implemented using (getter setter) routines. Suppose I have multiple subjobs called in a job, once I return the context variable value using routine from child to parent job, then again this context variable value is available to all the other subjobs. This way, it becomes easy to manage variables.
Thanks
Vaibhav
One Star

Re: [resolved] How to get the error message from the child job

Hello sanvaibhav,
I cannot grasp why a context variable of type String doesn't work (also not working with
option "transmit whole context" in tRunJob) but it works when this context variable is of
type Object and you assign a HashMap to it in parent and modify its entries in the child
jobs. Then theses values are in a bi-directional access for parent and child afterwards.
That's magic.
tJavaRow (parent)
Map<String,String> errors = new HashMap<String,String>();
errors.put("ERRORS","");
context.errors = errors;
tRunJob (parent) with option "Transmit whole context"
tLogCatcher -> tJavaRow (child)
Map<String,String> errors = (HashMap<String,String>) context.errors;
errors.put("ERRORS", output_row.message);
tLogCatcher -> tJavaRow (parent)
Map<String,String> errors = (HashMap<String,String>) context.errors;
if(StringUtils.isNotBlank(errors.get("ERRORS"))) {
output_row.message = errors.get("ERRORS");
}
Conclusion: That works!
Kind regards
Hilderich
One Star

Re: [resolved] How to get the error message from the child job

I cannot grasp why a context variable of type String doesn't work (also not working with
option "transmit whole context" in tRunJob) but it works when this context variable is of
type Object and you assign a HashMap to it in parent and modify its entries in the child
jobs. Then theses values are in a bi-directional access for parent and child afterwards.
That's magic.

The key to understanding Talend parameter passing, is to understand how Java handles parameter passing. When you pass your Context variables to a child Job (or return values back), you are using the Java parameter passing mechanism. Java Passes by Value. This means that when you transmit your context variables to your child Job, you can't simply reassign the value, for the parent Job to then pick it up.
By passing in a hashmap (mutable object) to the child job in a context, the child job changes it and that hashmap returns the value in the parent that was changed in the child...
See this article for the more complete explanation... http://www.talendbyexample.com/talend-returning-values-from-subjobs.html Scroll down to the section that starts with "Returning Values through Context"
One Star

Re: [resolved] How to get the error message from the child job

The simple truth is that you just will post ads for babysitting jobs online and offer up your babysitting services through bulletin boards and web portals and job hunting sites. The trick is to be careful-especially if you are under age. Always have a parent go with you to meet your potential babysitter job clients before the actual job is to take place.
https://junglejuniors.com.au/
Four Stars

Re: [resolved] How to get the error message from the child job

Hi  Hilderich
Using a tBufferOutput component in the child job to pass the error message from the child job to the main job. Refer to this KB article:
https://help.talend.com/search/all?query=Returning+a+value+from+a+child+Job+to+the+parent+Job&conten...
Shong
tBufferOutput is not working in this case Shong.
need a solution
Four Stars

Re: [resolved] How to get the error message from the child job

tBufferOutput is not working in this case Shong.
need a solution...
One Star

Re: [resolved] How to get the error message from the child job

Exactly Satya!
Shong, 
As Satya said, tBufferOutput doesn't work during error. I mean, it doesn't carry information from child to parent incase of error.
But the same component is successfully carrying data incase of job success. Please take an example and try it....
Regards,
Vijay (abhicool666@gmail.com)
Community Manager

Re: [resolved] How to get the error message from the child job

Hi Vijay
I gave an example in my reply in this the article that use onsubjoberror to trigger a subjob that pass the customized message from the child job to parent job, i have tested it and it works.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business