diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/exception.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/exception.c index fec9a103b4e23..28214be247090 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/exception.c +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/exception.c @@ -189,12 +189,25 @@ int printExceptionAndFreeV(JNIEnv *env, jthrowable exc, int noPrintFlags, if (!rootCause) { fprintf(stderr, "(unable to get root cause for %s)\n", className); } else { - fprintf(stderr, "%s", rootCause); + // Trim overly long rootCause message after new-line. + const char *newlnIndex = strchr(rootCause, '\n'); + int displayLen = 80; + if (newlnIndex != NULL) { + int newLen = (int) (newlnIndex - rootCause); + if (newLen > 10 && newLen < 200) { + // Keep message a reasonable length. + displayLen = newLen; + } + } + fprintf(stderr, "%.*s\n", displayLen, rootCause); } - if (!stackTrace) { - fprintf(stderr, "(unable to get stack trace for %s)\n", className); - } else { - fprintf(stderr, "%s", stackTrace); + if (!(noPrintFlags & NOSTACK_FILE_NOT_FOUND)) { + // Do not print stack for file not found + if (!stackTrace) { + fprintf(stderr, "(unable to get stack trace for %s)\n", className); + } else { + fprintf(stderr, "%s", stackTrace); + } } } diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/exception.h b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/exception.h index cdf93a16065db..1f68576139318 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/exception.h +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/exception.h @@ -65,6 +65,7 @@ */ #define PRINT_EXC_ALL 0x00 #define NOPRINT_EXC_FILE_NOT_FOUND 0x01 +#define NOSTACK_FILE_NOT_FOUND 0x100 #define NOPRINT_EXC_ACCESS_CONTROL 0x02 #define NOPRINT_EXC_UNRESOLVED_LINK 0x04 #define NOPRINT_EXC_PARENT_NOT_DIRECTORY 0x08 diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c index ed150925cdb81..45f60d5af9292 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c @@ -1247,7 +1247,7 @@ static hdfsFile hdfsOpenFileImpl(hdfsFS fs, const char *path, int flags, jReplication, jBlockSize); } if (jthr) { - ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL, + ret = printExceptionAndFree(env, jthr, NOSTACK_FILE_NOT_FOUND, "hdfsOpenFile(%s): FileSystem#%s(%s)", path, method, signature); goto done; }