Skip to content

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

Merged
tisonkun merged 4 commits intoapache:mainfrom
kassane:zig-errorhandler
May 31, 2023
Merged

refactor(bindings/zig): add errors handler and module test#2381
tisonkun merged 4 commits intoapache:mainfrom
kassane:zig-errorhandler

Conversation

@kassane
Copy link
Copy Markdown
Contributor

@kassane kassane commented May 31, 2023

cc: @tisonkun @Xuanwo

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

@github-actions github-actions Bot added the releases-note/refactor The PR does a refactor on code or has a title that begins with "refactor" label May 31, 2023
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 🤣

Comment thread bindings/zig/src/opendal.zig Outdated
Comment thread bindings/zig/src/opendal.zig
@kassane kassane requested review from tisonkun and xyjixyjixyji May 31, 2023 13:47
Copy link
Copy Markdown
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
Copy Markdown
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
@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

Labels

releases-note/refactor The PR does a refactor on code or has a title that begins with "refactor"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants