alamb commented on code in PR #7091:
URL: https://github.com/apache/arrow-datafusion/pull/7091#discussion_r1275396441
##########
datafusion/proto/src/common.rs:
##########
@@ -17,26 +17,17 @@
use datafusion_common::{DataFusionError, Result};
-pub fn csv_delimiter_to_string(b: u8) -> Result<String> {
- let b = &[b];
- let b = std::str::from_utf8(b)
- .map_err(|_| DataFusionError::Internal("Invalid CSV
delimiter".to_owned()))?;
- Ok(b.to_owned())
-}
-
-pub fn str_to_byte(s: &String) -> Result<u8> {
+pub fn str_to_byte(s: &String, flag: &str) -> Result<u8> {
Review Comment:
I know this PR didn't introduce this change, but `str_to_bytes` doesn't need
to be `pub`:
```suggestion
fn str_to_byte(s: &String, flag: &str) -> Result<u8> {
```
##########
datafusion/proto/src/common.rs:
##########
@@ -17,26 +17,17 @@
use datafusion_common::{DataFusionError, Result};
-pub fn csv_delimiter_to_string(b: u8) -> Result<String> {
- let b = &[b];
- let b = std::str::from_utf8(b)
- .map_err(|_| DataFusionError::Internal("Invalid CSV
delimiter".to_owned()))?;
- Ok(b.to_owned())
-}
-
-pub fn str_to_byte(s: &String) -> Result<u8> {
+pub fn str_to_byte(s: &String, flag: &str) -> Result<u8> {
if s.len() != 1 {
- return Err(DataFusionError::Internal(
- "Invalid CSV delimiter".to_owned(),
- ));
+ return Err(DataFusionError::Internal(format!("Invalid CSV {flag}")));
}
Ok(s.as_bytes()[0])
}
-pub fn byte_to_string(b: u8) -> Result<String> {
+pub fn byte_to_string(b: u8, flag: &str) -> Result<String> {
Review Comment:
```suggestion
fn byte_to_string(b: u8, flag: &str) -> Result<String> {
```
##########
datafusion/proto/src/common.rs:
##########
@@ -17,26 +17,17 @@
use datafusion_common::{DataFusionError, Result};
-pub fn csv_delimiter_to_string(b: u8) -> Result<String> {
- let b = &[b];
- let b = std::str::from_utf8(b)
- .map_err(|_| DataFusionError::Internal("Invalid CSV
delimiter".to_owned()))?;
- Ok(b.to_owned())
-}
-
-pub fn str_to_byte(s: &String) -> Result<u8> {
+pub fn str_to_byte(s: &String, flag: &str) -> Result<u8> {
if s.len() != 1 {
- return Err(DataFusionError::Internal(
- "Invalid CSV delimiter".to_owned(),
- ));
+ return Err(DataFusionError::Internal(format!("Invalid CSV {flag}")));
}
Ok(s.as_bytes()[0])
}
-pub fn byte_to_string(b: u8) -> Result<String> {
+pub fn byte_to_string(b: u8, flag: &str) -> Result<String> {
let b = &[b];
let b = std::str::from_utf8(b)
- .map_err(|_| DataFusionError::Internal("Invalid CSV
delimiter".to_owned()))?;
+ .map_err(|_| DataFusionError::Internal(format!("Invalid CSV
{flag}")))?;
Review Comment:
```suggestion
.map_err(|_| DataFusionError::Internal(format!("Invalid CSV {flag}:
can not represent {b:0x} as utf8")))?;
```
##########
datafusion/proto/src/common.rs:
##########
@@ -17,26 +17,17 @@
use datafusion_common::{DataFusionError, Result};
-pub fn csv_delimiter_to_string(b: u8) -> Result<String> {
- let b = &[b];
- let b = std::str::from_utf8(b)
- .map_err(|_| DataFusionError::Internal("Invalid CSV
delimiter".to_owned()))?;
- Ok(b.to_owned())
-}
-
-pub fn str_to_byte(s: &String) -> Result<u8> {
+pub fn str_to_byte(s: &String, flag: &str) -> Result<u8> {
Review Comment:
it might also be clearer if the name of `flag` was something like
`description`
##########
datafusion/proto/src/common.rs:
##########
@@ -17,26 +17,17 @@
use datafusion_common::{DataFusionError, Result};
-pub fn csv_delimiter_to_string(b: u8) -> Result<String> {
- let b = &[b];
- let b = std::str::from_utf8(b)
- .map_err(|_| DataFusionError::Internal("Invalid CSV
delimiter".to_owned()))?;
- Ok(b.to_owned())
-}
-
-pub fn str_to_byte(s: &String) -> Result<u8> {
+pub fn str_to_byte(s: &String, flag: &str) -> Result<u8> {
if s.len() != 1 {
- return Err(DataFusionError::Internal(
- "Invalid CSV delimiter".to_owned(),
- ));
+ return Err(DataFusionError::Internal(format!("Invalid CSV {flag}")));
Review Comment:
I think more specific error messages are more helpful:
```suggestion
return Err(DataFusionError::Internal(format!("Invalid CSV {flag}:
expected single character, got {s}")));
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]