[go: up one dir, main page]

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

feat(datastore): Return Get, GetMulti, Put and PutMulti errors with enhanced details #7061

Merged
merged 9 commits into from
Dec 2, 2022

Conversation

ionicc
Copy link
Contributor
@ionicc ionicc commented Nov 17, 2022

Closes: #7060

Changes

  • Returns enhanced errors by adding more metadata in the errors
  • As present in TODO: checkMultiArgs() logic has been folded in Get() and Put().
  • Unify errors by converting all errors.New to fmt.Errorf

Signed-off-by: Sagar Vakkala <sagarwakawaka@gmail.com>
Signed-off-by: Sagar Vakkala <sagarwakawaka@gmail.com>
Signed-off-by: Sagar Vakkala <sagarwakawaka@gmail.com>
Signed-off-by: Sagar Vakkala <sagarwakawaka@gmail.com>
Signed-off-by: Sagar Vakkala <sagarwakawaka@gmail.com>
@ionicc ionicc requested review from telpirion and a team as code owners November 17, 2022 10:40
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Nov 17, 2022
@ionicc ionicc changed the title Return Get, GetMulti, Put and PutMulti errors with enhanced details feat(datastore): Return Get, GetMulti, Put and PutMulti errors with enhanced details Nov 17, 2022
Signed-off-by: Sagar Vakkala <sagarwakawaka@gmail.com>
Copy link
Contributor
@telpirion telpirion left a comment

Choose a reason for hiding this comment

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

Please revert the unnecessary replacements of errors.New() and I'll take another look. Thank you!

@@ -114,7 +113,7 @@ func NewClient(ctx context.Context, projectID string, opts ...option.ClientOptio
}

if projectID == "" {
return nil, errors.New("datastore: missing project/dataset id")
return nil, fmt.Errorf("datastore: missing project/dataset id")
Copy link
Contributor

Choose a reason for hiding this comment

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

In places where no error is being wrapped, you don't need to replace errors.New().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@telpirion Thank you for the review. I replaced it for consistency, But I've reverted it now. Please take a look!

@@ -134,19 +133,21 @@ func detectProjectID(ctx context.Context, opts ...option.ClientOption) (string,
return "", fmt.Errorf("fetching creds: %w", err)
}
if creds.ProjectID == "" {
return "", errors.New("datastore: see the docs on DetectProjectID")
return "", fmt.Errorf("datastore: see the docs on DetectProjectID")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as previous.

}
return creds.ProjectID, nil
}

var (
// ErrInvalidEntityType is returned when functions like Get or Next are
// passed a dst or src argument of invalid type.
ErrInvalidEntityType = errors.New("datastore: invalid entity type")
ErrInvalidEntityType = fmt.Errorf("datastore: invalid entity type")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as previous.

// ErrInvalidKey is returned when an invalid key is presented.
ErrInvalidKey = errors.New("datastore: invalid key")
ErrInvalidKey = fmt.Errorf("datastore: invalid key")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as previous.

// ErrNoSuchEntity is returned when no entity was found for a given key.
ErrNoSuchEntity = errors.New("datastore: no such entity")
ErrNoSuchEntity = fmt.Errorf("datastore: no such entity")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as previous.

ErrNoSuchEntity = errors.New("datastore: no such entity")
ErrNoSuchEntity = fmt.Errorf("datastore: no such entity")
// ErrDifferentKeyAndDstLength is returned when the length of dst and key are different.
ErrDifferentKeyAndDstLength = fmt.Errorf("datastore: keys and dst slices have different length")
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as previous.

Signed-off-by: Sagar Vakkala <sagarwakawaka@gmail.com>
@ionicc
Copy link
Contributor Author
ionicc commented Nov 24, 2022

@telpirion The comments have been resolved, Could you check this PR again?

@telpirion telpirion added api: datastore Issues related to the Datastore API. automerge Merge the pull request once unit tests and other checks pass. labels Dec 2, 2022
@telpirion telpirion enabled auto-merge (squash) December 2, 2022 19:10
@telpirion telpirion merged commit c82b63a into googleapis:main Dec 2, 2022
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

datastore: Return detailed errors in Get, GetMulti, Put and PutMulti
2 participants