-
Notifications
You must be signed in to change notification settings - Fork 360
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
Conversation
Loving thisssss |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
cmd/lakectl/cmd/annotate.go
Outdated
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)) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
?
docs/reference/commands.md
Outdated
@@ -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_*' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #2976
There was a problem hiding this 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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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
?
284669d
to
3513f29
Compare
cmd/lakectl/cmd/branch_protect.go
Outdated
@@ -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>", |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DieOnUnexpectedResponse?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
cmd/lakectl/cmd/branch_protect.go
Outdated
"github.com/spf13/cobra" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove whitespace
cmd/lakectl/cmd/common_helpers.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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
cmd/lakectl/cmd/root.go
Outdated
@@ -108,9 +109,18 @@ func getClient() *api.ClientWithResponses { | |||
if u.Path == "" || u.Path == "/" { | |||
serverEndpoint = strings.TrimRight(serverEndpoint, "/") + api.BaseURL | |||
} | |||
httpClient := &http.Client{ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove whitespace
pkg/api/ui_handler.go
Outdated
@@ -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...") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this 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
No description provided.