Also notice that the text can not be longer than 2000 characters, otherwise you will get this failure. This was my solution in Matillion:
if len(detailed_error) > 2000:
max_len = len(detailed_error)-2000
context.updateVariable('detailed_error', detailed_error[max_len:])