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

Bugfix/2935 lakectl bug on not found html #2966

Merged
merged 10 commits into from
Feb 28, 2022

Conversation

idanovo
Copy link
Contributor

@idanovo idanovo commented Feb 24, 2022

No description provided.

@idanovo idanovo added bug Something isn't working good first issue Good for newcomers area/lakectl Issues related to lakeFS' command line interface (lakectl) include-changelog PR description should be included in next release changelog labels Feb 24, 2022
@idanovo idanovo self-assigned this Feb 24, 2022
@BinyaminSchein
Copy link

Loving thisssss

@idanovo idanovo marked this pull request as ready for review February 27, 2022 11:12
Copy link
Contributor

@arielshaqed arielshaqed left a comment

Choose a reason for hiding this comment

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

Thanks!

1 res/resp mixup that has to be fixed, and some things don't belong in this PR I think.

for _, obj := range resp.JSON200.Results {
logCommitsParams := &api.LogCommitsParams{
Amount: api.PaginationAmountPtr(1),
Objects: &[]string{obj.Path},
}
res, err := client.LogCommitsWithResponse(context, pathURI.Repository, pathURI.Ref, logCommitsParams)
DieOnResponseError(res, err)
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually incorrect, because l.51 assigned to res. Response variables are clearly a mess in here. Right now you're the victim, and the only way out might be to fix them entirely.

If you can, I would feel safely if you could: pick one spelling, and search-and-destroy the entire cmd directory for the other one (git grep -w res cmd/ is your friend, and should return no results once we're done.)

Copy link
Contributor

Choose a reason for hiding this comment

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

tag.go still contains a variable res:

[ariels@fedora lakeFS]$ git grep -w res cmd/
cmd/lakectl/cmd/tag.go:                 res, err := client.GetCommitWithResponse(ctx, tagURI.Repository, commitRef)
cmd/lakectl/cmd/tag.go:                 DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK)

This inconsistency is precisely what got us into trouble on this line. So could you fix that one too, please, even though it is not strictly related to this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

My 2 cents - use different names so we will not verify or check the wrong response by mistake

data := objectCommitData{
Object: obj.Path,
}
if len(res.JSON200.Results) > 0 {
data.Commit = res.JSON200.Results[0]
data.CommitMessage = splitOnNewLine(stringTrimLen((res.JSON200.Results[0].Message), annotateMessageSize))
data.CommitMessage = splitOnNewLine(stringTrimLen(res.JSON200.Results[0].Message, annotateMessageSize))
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems unrelated. Also I am not sure it does what is intended here (I am not sure what is intended here). Maybe leave it to a separate PR?

@@ -206,6 +210,31 @@ func DieOnResponseError(response interface{}, err error) {
DieErr(retrievedErr)
}
}
func DieOnErrorOrUnexpectedStatusCode(response interface{}, err error, expectedStatusCode int) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we refactor parts of HTTPResponseAsError with this? I think it copies some parts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to, but it seems to be kind of difficult because of the structure of ResponseAsError func. All we want in our case is to get the status code from the response when ResponseAsError checks and returns an error on its way to get it. WDYT?

@@ -127,7 +128,7 @@ func ListRepositoriesAndAnalyze(ctx context.Context) error {
case resp.JSON401 != nil:
return &CredentialsError{msgOnErrCredential, resp.JSON401.Message}
// In case we get the "not found" HTML page (the status is 200 and not 404 in this case).
case resp.HTTPResponse != nil && resp.HTTPResponse.StatusCode == 200:
case resp.HTTPResponse != nil && resp.HTTPResponse.StatusCode == 302:
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment doesn't change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which comment? The output comment of the doctor?

@@ -1339,7 +1339,7 @@ lakectl branch-protect add <repo uri> <pattern> [flags]
{:.no_toc}

```
lakectl add lakefs://<repository> 'stable_*'
lakectl branch-protect add lakefs://<repository> 'stable_*'
Copy link
Contributor

Choose a reason for hiding this comment

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

These seem unrelated, and I'd rather the author reviewed this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened #2976

@idanovo idanovo requested a review from arielshaqed February 27, 2022 13:02
Copy link
Contributor

@arielshaqed arielshaqed 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 _, obj := range resp.JSON200.Results {
logCommitsParams := &api.LogCommitsParams{
Amount: api.PaginationAmountPtr(1),
Objects: &[]string{obj.Path},
}
res, err := client.LogCommitsWithResponse(context, pathURI.Repository, pathURI.Ref, logCommitsParams)
DieOnResponseError(res, err)
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK)
Copy link
Contributor

Choose a reason for hiding this comment

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

tag.go still contains a variable res:

[ariels@fedora lakeFS]$ git grep -w res cmd/
cmd/lakectl/cmd/tag.go:                 res, err := client.GetCommitWithResponse(ctx, tagURI.Repository, commitRef)
cmd/lakectl/cmd/tag.go:                 DieOnErrorOrUnexpectedStatusCode(res, err, http.StatusOK)

This inconsistency is precisely what got us into trouble on this line. So could you fix that one too, please, even though it is not strictly related to this PR?

@@ -78,8 +78,8 @@ var tagCreateCmd = &cobra.Command{
force, _ := cmd.Flags().GetBool("force")
if force {
// checking validity of the commitRef before deleting the old one
resp, err := client.GetCommitWithResponse(ctx, tagURI.Repository, commitRef)
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK)
res, err := client.GetCommitWithResponse(ctx, tagURI.Repository, commitRef)
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for being unclear: I really liked this change, it's part of the res -> resp fix. It caused an issue with this PR, so I think we have no choice but to make this unrelated change here. (Technically we could have a preview PR that just fixed this, and then your PR. Too much effort for too little gain probably.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure how we can fix this in this case. We are trying to assign resp in l.84 with a different type. Maybe change res here to be _resp?

@arielshaqed arielshaqed force-pushed the bugfix/2935-lakectl-bug-on-not-found-html branch from 284669d to 3513f29 Compare February 27, 2022 13:48
@idanovo idanovo linked an issue Feb 27, 2022 that may be closed by this pull request
@@ -18,13 +21,13 @@ var branchProtectCmd = &cobra.Command{
var branchProtectListCmd = &cobra.Command{
Use: "list <repo uri>",
Short: "List all branch protection rules",
Example: "lakectl list lakefs://<repository>",
Example: "lakectl branch-protect list lakefs://<repository>",
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch

@@ -119,7 +120,7 @@ var abuseRandomWritesCmd = &cobra.Command{

client := getClient()
resp, err := client.GetRepositoryWithResponse(cmd.Context(), u.Repository)
DieOnResponseError(resp, err)
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion - pick a shorter name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DieOnUnexpectedResponse?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, no good suggestion

for _, obj := range resp.JSON200.Results {
logCommitsParams := &api.LogCommitsParams{
Amount: api.PaginationAmountPtr(1),
Objects: &[]string{obj.Path},
}
res, err := client.LogCommitsWithResponse(context, pathURI.Repository, pathURI.Ref, logCommitsParams)
DieOnResponseError(res, err)
DieOnErrorOrUnexpectedStatusCode(resp, err, http.StatusOK)
Copy link
Contributor

Choose a reason for hiding this comment

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

My 2 cents - use different names so we will not verify or check the wrong response by mistake

"github.com/spf13/cobra"

Copy link
Contributor

Choose a reason for hiding this comment

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

remove whitespace

@@ -41,6 +43,8 @@ const (
const internalPageSize = 1000 // when retreiving all records, use this page size under the hood
const defaultAmountArgumentValue = 100 // when no amount is specified, use this value for the argument

const defaultResponseOnSwaggerClient = http.StatusNoContent
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer to use http.StatusNoContent when needed - the code will be readable without this indirection

@@ -108,9 +109,18 @@ func getClient() *api.ClientWithResponses {
if u.Path == "" || u.Path == "/" {
serverEndpoint = strings.TrimRight(serverEndpoint, "/") + api.BaseURL
}
httpClient := &http.Client{

Copy link
Contributor

Choose a reason for hiding this comment

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

remove whitespace

@@ -80,6 +80,8 @@ func NewHandlerWithDefault(root http.FileSystem, handler http.Handler, defaultPa
}
_, err := root.Open(path.Clean(urlPath))
if err != nil && os.IsNotExist(err) {
fmt.Println("redirecting...")
Copy link
Contributor

Choose a reason for hiding this comment

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

remove println

@@ -80,6 +80,8 @@ func NewHandlerWithDefault(root http.FileSystem, handler http.Handler, defaultPa
}
_, err := root.Open(path.Clean(urlPath))
if err != nil && os.IsNotExist(err) {
fmt.Println("redirecting...")
http.Redirect(w, r, defaultPath, http.StatusFound)
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I remember, you need to return after redirect and not continue the code flow

@idanovo idanovo requested a review from nopcoder February 28, 2022 09:32
Copy link
Contributor

@nopcoder nopcoder left a comment

Choose a reason for hiding this comment

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

Just address other comments

@idanovo idanovo merged commit a8340bf into master Feb 28, 2022
@arielshaqed arielshaqed deleted the bugfix/2935-lakectl-bug-on-not-found-html branch May 8, 2022 07:49
@arielshaqed arielshaqed restored the bugfix/2935-lakectl-bug-on-not-found-html branch May 8, 2022 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/lakectl Issues related to lakeFS' command line interface (lakectl) bug Something isn't working good first issue Good for newcomers include-changelog PR description should be included in next release changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: lakectl get panic when the response is the not found html page
4 participants