-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(bindings/C): Implement error with error message (#3250)
* Implement opendal_error * docs * tests * error msg example * free * separate the valgrind test w/ original test * docs * add opendal_operator_new result * refactor the test to use new operator init logic * refactor the examples to use the new operator_ptr init logic * add .gitignore * add error_msg tests to valgrind * rename basicrw.c to basic.c * resolve comments * fix fmt * Fix zig Signed-off-by: Xuanwo <[email protected]> * Fix go Signed-off-by: Xuanwo <[email protected]> * Fix swift Signed-off-by: Xuanwo <[email protected]> * Format code Signed-off-by: Xuanwo <[email protected]> --------- Signed-off-by: Xuanwo <[email protected]> Co-authored-by: Xuanwo <[email protected]>
- Loading branch information
1 parent
f1035ea
commit 9515e8b
Showing
25 changed files
with
674 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,10 @@ build/ | |
docs/ | ||
|
||
*.o | ||
|
||
examples/* | ||
!examples/ | ||
!examples/*.h | ||
!examples/*.c | ||
!examples/*.cc | ||
!examples/*.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include "assert.h" | ||
#include "opendal.h" | ||
#include "stdio.h" | ||
|
||
// this example shows how to get error message from opendal_error | ||
int main() | ||
{ | ||
/* Initialize a operator for "memory" backend, with no options */ | ||
opendal_result_operator_new result = opendal_operator_new("memory", 0); | ||
assert(result.operator_ptr != NULL); | ||
assert(result.error == NULL); | ||
|
||
opendal_operator_ptr* op = result.operator_ptr; | ||
|
||
/* The read is supposed to fail */ | ||
opendal_result_read r = opendal_operator_blocking_read(op, "/testpath"); | ||
assert(r.error != NULL); | ||
assert(r.error->code == OPENDAL_NOT_FOUND); | ||
|
||
/* Lets print the error message out */ | ||
struct opendal_bytes* error_msg = &r.error->message; | ||
for (int i = 0; i < error_msg->len; ++i) { | ||
printf("%c", error_msg->data[i]); | ||
} | ||
|
||
/* free the error since the error is not NULL */ | ||
opendal_error_free(r.error); | ||
|
||
/* the operator_ptr is also heap allocated */ | ||
opendal_operator_free(op); | ||
} |
Oops, something went wrong.