opendal icon indicating copy to clipboard operation
opendal copied to clipboard

Should return error with more detail for `validate_path`

Open zwpaper opened this issue 2 years ago • 4 comments

context: https://discord.com/channels/1081052318650339399/1081052319342407715/1087747871656390807

when using Operator.list, we check whether the input is dir by detecting the tailing /, it is documented here https://github.com/apache/incubator-opendal/blob/main/core/src/types/operator/operator.rs#L786,

but it still is easy to be ignored.

as the context discussed, we could enhance the Error to improve the readability.

possible solution:

  1. add a new type like UnexpectedPath or InvalidPath
  2. add more detail to the NotADirectory error

after checking the code, We already had error messages with the error type, we could let the validate_path https://github.com/apache/incubator-opendal/blob/04ca6e5c29f5ddd637f4633f987fe7f5eadc3751/core/src/raw/path.rs#L215 return specific error, so that we can know the details

WDYT @Xuanwo

zwpaper avatar Mar 23 '23 03:03 zwpaper

  1. add more detail to the NotADirectory error

We can start from this way first!

https://github.com/apache/incubator-opendal/blob/04ca6e5c29f5ddd637f4633f987fe7f5eadc3751/core/src/types/operator/blocking_operator.rs#L296-L303

Adding more accurate message instead of read path is not a directory will be helpful.

Xuanwo avatar Mar 23 '23 03:03 Xuanwo

@Xuanwo the only difference is error message?

zwpaper avatar Mar 23 '23 09:03 zwpaper

@Xuanwo the only difference is error message?

ErrorKind, operation are also different.

Xuanwo avatar Mar 23 '23 09:03 Xuanwo

did I misunderstand you? @Xuanwo

it looks like the 2 have the same ErrorKind, NotADirectory and operation is meant to be different, one for list and the other create_dir

https://github.com/apache/incubator-opendal/blob/04ca6e5c29f5ddd637f4633f987fe7f5eadc3751/core/src/types/operator/blocking_operator.rs#L296-L303

https://github.com/apache/incubator-opendal/blob/524b7870878a91bf072283477f11cf317e212fce/core/src/types/operator/operator.rs#L818-L826

zwpaper avatar Mar 23 '23 14:03 zwpaper

The discussion seems to be going in the wrong direction. We want to inform our users that the error (NotADirectory or IsADirectory) is caused by an incorrect input path. We can modify the error description to improve its clarity and effectiveness.

Xuanwo avatar Mar 24 '23 15:03 Xuanwo

yes, that's what I expecting, how about

the path trying to list should end with `/`

as ErrorKind::NotADirectory has shown the meaning not a directory

zwpaper avatar Mar 24 '23 15:03 zwpaper

Great!

Xuanwo avatar Mar 24 '23 15:03 Xuanwo