FrankYang0529 opened a new pull request, #15586:
URL: https://github.com/apache/kafka/pull/15586
When an exception is thrown in kafka-delete-records, it propagates through
`main` to the JVM, producing the following message:
```
bin/kafka-delete-records.sh --bootstrap-server localhost:9092
--offset-json-file /tmp/does-not-exist
Exception in thread "main" java.io.IOException: Unable to read file
/tmp/does-not-exist
at org.apache.kafka.common.utils.Utils.readFileAsString(Utils.java:787)
at
org.apache.kafka.tools.DeleteRecordsCommand.execute(DeleteRecordsCommand.java:105)
at
org.apache.kafka.tools.DeleteRecordsCommand.main(DeleteRecordsCommand.java:64)
Caused by: java.nio.file.NoSuchFileException: /tmp/does-not-exist
at
java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at
java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at
java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at
java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218)
at java.base/java.nio.file.Files.newByteChannel(Files.java:380)
at java.base/java.nio.file.Files.newByteChannel(Files.java:432)
at java.base/java.nio.file.Files.readAllBytes(Files.java:3288)
at org.apache.kafka.common.utils.Utils.readFileAsString(Utils.java:784)
... 2 more
```
This is in contrast to the error handling used in other tools, such as the
kafka-log-dirs:
```
bin/kafka-log-dirs.sh --bootstrap-server localhost:9092 --describe
--command-config /tmp/does-not-exist
/tmp/does-not-exist
java.nio.file.NoSuchFileException: /tmp/does-not-exist
at
java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at
java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at
java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at
java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218)
at java.base/java.nio.file.Files.newByteChannel(Files.java:380)
at java.base/java.nio.file.Files.newByteChannel(Files.java:432)
at
java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:422)
at java.base/java.nio.file.Files.newInputStream(Files.java:160)
at org.apache.kafka.common.utils.Utils.loadProps(Utils.java:686)
at org.apache.kafka.common.utils.Utils.loadProps(Utils.java:673)
at
org.apache.kafka.tools.LogDirsCommand.createAdminClient(LogDirsCommand.java:149)
at org.apache.kafka.tools.LogDirsCommand.execute(LogDirsCommand.java:68)
at
org.apache.kafka.tools.LogDirsCommand.mainNoExit(LogDirsCommand.java:54)
at org.apache.kafka.tools.LogDirsCommand.main(LogDirsCommand.java:49)
```
After the fix, the error from kafka-delete-records will be like:
```
Unable to read file /tmp/does-not-exist
java.io.IOException: Unable to read file /tmp/does-not-exist
at org.apache.kafka.common.utils.Utils.readFileAsString(Utils.java:787)
at
org.apache.kafka.tools.DeleteRecordsCommand.execute(DeleteRecordsCommand.java:117)
at
org.apache.kafka.tools.DeleteRecordsCommand.mainNoExit(DeleteRecordsCommand.java:70)
at
org.apache.kafka.tools.DeleteRecordsCommand.main(DeleteRecordsCommand.java:65)
Caused by: java.nio.file.NoSuchFileException: /tmp/does-not-exist
at
java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at
java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at
java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at
java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218)
at java.base/java.nio.file.Files.newByteChannel(Files.java:380)
at java.base/java.nio.file.Files.newByteChannel(Files.java:432)
at java.base/java.nio.file.Files.readAllBytes(Files.java:3288)
at org.apache.kafka.common.utils.Utils.readFileAsString(Utils.java:784)
... 3 more
```
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org