Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(bindings/zig): add errors handler and module test #2381

Merged
merged 4 commits into from
May 31, 2023
Merged

refactor(bindings/zig): add errors handler and module test #2381

merged 4 commits into from
May 31, 2023

Conversation

kassane
Copy link
Contributor

@kassane kassane commented May 31, 2023

cc: @tisonkun @Xuanwo

  • Add Zig Error Handler
  • Split tests - BDD test with opendal module (sample use)

Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @kassane! Generally looks good. Coments inline.

c.OPENDAL_ALREADY_EXISTS => error.AlreadyExists,
c.OPENDAL_RATE_LIMITED => error.RateLimited,
c.OPENDAL_IS_SAME_FILE => error.IsSameFile,
else => c.OPENDAL_ERROR,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we map all unknown error to Unexpected at least for Java bindings. Maybe here is a full conversion - cc @Xuanwo @Ji-Xinyou this can be first handled in C bindings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In C binding, the unknown error leads to panic, you can see it here since the opendal::Error represents all the errors that could happen. Any ideas? @Xuanwo

Copy link
Contributor Author

@kassane kassane May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible:

Method 1 (unwrap style)

- else => c.OPENDAL_ERROR,
+ else => unreachable,

Method 2

- else => c.OPENDAL_ERROR,
+ else => @panic(str),

Method 3

- else => c.OPENDAL_ERROR,
+ else => @compileError(str),

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible:

Method 1 (unwrap style)

- else => c.OPENDAL_ERROR,
+ else => unreachable,

Method 2

- else => c.OPENDAL_ERROR,
+ else => @panic(str),

Method 3

- else => c.OPENDAL_ERROR,
+ else => @compilerError(str),

I personally prefer compilerError one. I was trying to do that in Rust, but rustc does not support that 🤣

bindings/zig/src/opendal.zig Outdated Show resolved Hide resolved
bindings/zig/src/opendal.zig Show resolved Hide resolved
Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

#2381 (comment) can be a further discussion on error handling policy. I tend to keep the behavior the same with the Rust lib, while @Xuanwo suggest to fallback to Unexpected here #2276 (comment).

@tisonkun
Copy link
Member

Merging...

As an under development binding I'd prefer unblock our contributors. Thank you @kassane!

@tisonkun tisonkun merged commit 016f3ae into apache:main May 31, 2023
18 checks passed
@kassane kassane deleted the zig-errorhandler branch May 31, 2023 14:15
@Xuanwo Xuanwo mentioned this pull request Jun 2, 2023
@suyanhanx suyanhanx mentioned this pull request Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants