Skip to content
Permalink
Browse files
reader: improve some error messages (#52)
Change-Id: I974377a676908a9f46c26c45d7a41c7e913298b0
  • Loading branch information
javeme committed Apr 9, 2019
1 parent 6dab02b commit d1b9bf3dc51afa0da5063722f9fa0947d62ca7d4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
@@ -47,7 +47,7 @@

public abstract class AbstractFileReader implements InputReader {

private static final Logger LOG = Log.logger(AbstractFileReader.class);
protected static final Logger LOG = Log.logger(AbstractFileReader.class);

private static final int BUF_SIZE = 5 * 1024 * 1024;

@@ -71,6 +71,7 @@ public FileSource source() {

@Override
public void init() {
LOG.info("Opening source {}", this.source);
try {
this.readers = this.openReaders();
} catch (IOException e) {
@@ -93,7 +94,7 @@ public boolean hasNext() {
@Override
public Line next() {
if (!this.hasNext()) {
throw new NoSuchElementException("Reach end of file");
throw new NoSuchElementException("Reached the end of file");
}
Line line = this.nextLine;
this.nextLine = null;
@@ -117,7 +118,7 @@ protected Line fetch() {
try {
rawLine = this.readNextLine();
} catch (IOException e) {
throw new LoadException("Read next line error", e);
throw new LoadException("Error while reading the next line", e);
}
if (rawLine == null) {
return null;
@@ -166,7 +167,7 @@ private boolean isDuplicateHeader(String line) {
private static BufferedReader createBufferedReader(InputStream stream,
FileSource source)
throws Exception {
E.checkNotNull(stream, "InputStream");
E.checkNotNull(stream, "stream");
try {
Reader csr = createCompressReader(stream, source);
return new BufferedReader(csr, BUF_SIZE);
@@ -51,7 +51,7 @@ protected Readers openReaders() throws IOException {
File[] subFiles = file.listFiles();
if (subFiles == null) {
throw new LoadException(
"Error when list files of path '%s'", file);
"Error while listing the files of path '%s'", file);
}
for (File subFile : subFiles) {
files.add(new ReadableFile(subFile));
@@ -63,7 +63,7 @@ protected Readers openReaders() throws IOException {
private static void checkExistAndReadable(File file) {
if (!file.exists()) {
throw new LoadException(
"Please ensure the file or directory exist: '%s'", file);
"Please ensure the file or directory exists: '%s'", file);
}
if (!file.canRead()) {
throw new LoadException(
@@ -48,11 +48,10 @@ public class HDFSReader extends AbstractFileReader {
public HDFSReader(HDFSSource source) {
super(source);
Configuration config = this.loadConfiguration();
LOG.info("Opening readers for hdfs source {}", source);
try {
this.hdfs = FileSystem.get(URI.create(source.path()), config);
} catch (IOException e) {
throw new LoadException("Failed to create hdfs file system", e);
throw new LoadException("Failed to create HDFS file system", e);
}
Path path = new Path(source.path());
checkExist(this.hdfs, path);
@@ -119,12 +118,12 @@ private static void checkExist(FileSystem fs, Path path) {
try {
if (!fs.exists(path)) {
throw new LoadException(
"Please ensure the file or directory exist: '%s'",
"Please ensure the file or directory exists: '%s'",
path);
}
} catch (IOException e) {
throw new LoadException(
"Some exception occured when check hdfs path '%s' exist",
"An exception occurred while checking HDFS path: '%s'",
path);
}
}
@@ -68,7 +68,7 @@ public boolean hasNext() {
this.batch = this.fetcher.nextBatch();
this.offset = 0;
} catch (Exception e) {
throw new LoadException("Read next row error", e);
throw new LoadException("Error while reading the next row", e);
}
}
return this.batch != null;
@@ -77,7 +77,7 @@ public boolean hasNext() {
@Override
public Line next() {
if (!this.hasNext()) {
throw new NoSuchElementException("Reach end of table");
throw new NoSuchElementException("Reached end of table");
}
return this.batch.get(this.offset++);
}

0 comments on commit d1b9bf3

Please sign in to comment.