Add error codes and define errors with it #343
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our error structure in "github.com/0chain/errors" is;
In gosdk we have different error implementation. Sometimes above structure is considered; other time
thrown.Throw
is considered andsometimes
errors.New
orfmt.Errorf
is considered.This makes error handling difficult and error response are inconsistent as well.
Below is just a structure considering error structure from "github.com/0chain/errors". We can work with other structure but it should be
consistently used inside gosdk.
One case:
Say I requested some file refs from 6 blobbers(with 4:2 ratio) and 3 of them gave
too_many_requests
error. If only two had giventoo_many_requests
error then anyway we could take consensus from other 4 blobbers and request is successful. But with three blobbers giving those errors, consensus would not be reached so error would beconsensus_failed
. The application that made this request should have been let know that it wastoo_many_requests
error that caused consensus failure, so that it would wait for some time interval and re-request again.We can define codes as constant values so function would use it. Later some function can check which error it is with errors.Is function with the errors defined below in var.