Add golangci #6418

Merged
kolaente merged 119 commits from golanci into master 2019-06-12 19:41:29 +00:00
kolaente commented 2019-03-23 19:36:50 +00:00 (Migrated from github.com)

This pr adds golangci to Gitea and replaces some linters (which golangci contains). This will (hopefully) enhance code quality.

Golangci lint calls a lot of golang lint tools directly, which make it a lot faster.

This pr adds [golangci](https://github.com/golangci/golangci-lint) to Gitea and replaces some linters (which golangci contains). This will (hopefully) enhance code quality. Golangci lint calls a lot of golang lint tools directly, which make it a lot faster.
kolaente commented 2019-03-23 19:38:50 +00:00 (Migrated from github.com)

Looks like the new ci step works, now we just have to fix all the issues.

Looks like the new ci step works, now we just have to fix all the issues.
kolaente commented 2019-03-24 17:06:07 +00:00 (Migrated from github.com)

Fixed most of the issues, however there are some issues where I don't really know what to do:

modules/indexer/issues/indexer.go:95:32: Error return value of `issueIndexerUpdateQueue.Run` is not checked (errcheck)
        go issueIndexerUpdateQueue.Run()
                                      ^

It looks like issueIndexerUpdateQueue.Run() doesn't return an error in any of its implementations. Could we just remove the error return?

  • Fixed from the hint by @lunny.
models/git_diff.go:387:2: S1001: should use copy() instead of a loop (gosimple)
        for idx, lof := range hunk[:headerLines] {
        ^

I don't know how it is possible to let copy only copy some parts of a slice.

  • Done
models/repo_list.go:149:2: SA9004: only the first constant in this group has an explicit type (staticcheck)
        SearchOrderByAlphabetically        SearchOrderBy = "name ASC"
        ^

I don't really think this is an issue... or is it?

  • @jonasfranz said the check isn't needed at all, so I removed it completly.
routers/user/oauth.go:166:2: SA4006: this value of `errs` is never used (staticcheck)
        errs = form.Validate(ctx.Context, errs)
        ^

If the errors are not checked, can the whole check be removed? Or how can we check for the error?

Fixed most of the issues, however there are some issues where I don't really know what to do: * [ ] ``` modules/indexer/issues/indexer.go:95:32: Error return value of `issueIndexerUpdateQueue.Run` is not checked (errcheck) go issueIndexerUpdateQueue.Run() ^ ``` It looks like `issueIndexerUpdateQueue.Run()` doesn't return an error in any of its implementations. Could we just remove the error return? * [x] Fixed from the hint by @lunny. ``` models/git_diff.go:387:2: S1001: should use copy() instead of a loop (gosimple) for idx, lof := range hunk[:headerLines] { ^ ``` I don't know how it is possible to let `copy` only copy some parts of a slice. * [x] Done ``` models/repo_list.go:149:2: SA9004: only the first constant in this group has an explicit type (staticcheck) SearchOrderByAlphabetically SearchOrderBy = "name ASC" ^ ``` I don't really think this is an issue... or is it? * [x] @jonasfranz said the check isn't needed at all, so I removed it completly. ``` routers/user/oauth.go:166:2: SA4006: this value of `errs` is never used (staticcheck) errs = form.Validate(ctx.Context, errs) ^ ``` If the errors are not checked, can the whole check be removed? Or how can we check for the error?

@kolaente Is golangci support gitea? Since we will host gitea on gitea.com. If golangci don't support gitea, it will not work.

@kolaente Is golangci support gitea? Since we will host gitea on gitea.com. If golangci don't support gitea, it will not work.
kolaente commented 2019-03-25 19:59:35 +00:00 (Migrated from github.com)

@lunny It's just a binary file which runs locally and in drone. Since we run it on our own infrastructure, we're not tied to a particular platform.

IIRC they offer tight ingration with github (things like having a bot which comments on the pr instead of just failing the pipeline) which we won't have. But I see no problem with it just failing the pipeline.

@lunny It's just a binary file which runs locally and in drone. Since we run it on our own infrastructure, we're not tied to a particular platform. IIRC they offer tight ingration with github (things like having a bot which comments on the pr instead of just failing the pipeline) which we won't have. But I see no problem with it just failing the pipeline.
kolaente commented 2019-03-27 19:27:15 +00:00 (Migrated from github.com)

Just merged with Gitea's master, it did containt a lot of new issues which had to be fixed...

Just merged with Gitea's master, it did containt a lot of new issues which had to be fixed...
techknowlogick reviewed 2019-03-27 19:29:22 +00:00

Do we still need this make lint step if golangci-lint covers it? (perhaps alias make lint to make golangci-lint just for backwards compatibility as well.

Do we still need this `make lint` step if golangci-lint covers it? (perhaps alias `make lint` to `make golangci-lint` just for backwards compatibility as well.
techknowlogick reviewed 2019-03-27 19:30:06 +00:00

(or instead of aliasing, just add an echo saying use make golangci-lint instead)

(or instead of aliasing, just add an echo saying use `make golangci-lint` instead)
kolaente (Migrated from github.com) reviewed 2019-03-27 19:32:49 +00:00
kolaente (Migrated from github.com) commented 2019-03-27 19:32:48 +00:00

We probably won't need it, it is indeed covered by golangci.
I will add a deprication message.

We probably won't need it, it is indeed covered by golangci. I will add a deprication message.
kolaente (Migrated from github.com) reviewed 2019-03-27 19:35:51 +00:00
kolaente (Migrated from github.com) commented 2019-03-27 19:35:50 +00:00

Ok, I just noticed we're not using the normal go linter, but revive which looks pretty similar to golangci, so I'd say lets keep it. But maybe rename it, to avoid confusion?

Ok, I just noticed we're not using the normal go linter, but revive which looks pretty similar to golangci, so I'd say lets keep it. But maybe rename it, to avoid confusion?
techknowlogick reviewed 2019-03-27 19:37:17 +00:00

renaming sounds good, I think if renaming is done then a note should be added to the previous name in case we have some docs pointing to make lint.

renaming sounds good, I think if renaming is done then a note should be added to the previous name in case we have some docs pointing to make lint.
kolaente (Migrated from github.com) reviewed 2019-03-27 20:19:13 +00:00
kolaente (Migrated from github.com) commented 2019-03-27 20:19:13 +00:00

@techknowlogick I've renamed it.

@techknowlogick I've renamed it.
sapk (Migrated from github.com) approved these changes 2019-04-03 02:25:52 +00:00
sapk (Migrated from github.com) left a comment

That a lot of missed error checking and more could still be logged in goroutine or defer. This will really improve the codebase and review.
LGTM, I would suggest to disable most of the linter that still failed and manage to enable them one at a time in separates PRs. This will ease the process of review and limit the number of conflict appearing.

That a lot of missed error checking and more could still be logged in goroutine or defer. This will really improve the codebase and review. LGTM, I would suggest to disable most of the linter that still failed and manage to enable them one at a time in separates PRs. This will ease the process of review and limit the number of conflict appearing.
sapk (Migrated from github.com) requested changes 2019-04-03 02:34:22 +00:00
sapk (Migrated from github.com) left a comment

Found one template file to be removed

Found one template file to be removed
@ -23,4 +23,3 @@
tplStars base.TplName = "user/meta/stars"
)
// GetUserByName get user by name
sapk (Migrated from github.com) commented 2019-04-03 02:33:09 +00:00

The related file should be removed /templates/user/meta/stars.tmpl

The related file should be removed `/templates/user/meta/stars.tmpl`
kolaente (Migrated from github.com) reviewed 2019-04-06 07:50:44 +00:00
@ -23,4 +23,3 @@
tplStars base.TplName = "user/meta/stars"
)
// GetUserByName get user by name
kolaente (Migrated from github.com) commented 2019-04-06 07:50:44 +00:00

That file was actually empty, thanks!

That file was actually empty, thanks!
kolaente commented 2019-04-06 08:17:29 +00:00 (Migrated from github.com)

@sapk I think we need to enable these now, I doubt there will be other prs soon otherwise...

@sapk I think we need to enable these now, I doubt there will be other prs soon otherwise...
sapk commented 2019-04-06 21:33:18 +00:00 (Migrated from github.com)

@kolaente It is just a recommendation as PR related to deps or CI tends to be broken as other PR get merged and need work to be fixed before merge. And I trust you but doing a lot of change on a lot of files could be suspicious and need a lot of work to review. Breaking it in small step will ease the process.

@kolaente It is just a recommendation as PR related to deps or CI tends to be broken as other PR get merged and need work to be fixed before merge. And I trust you but doing a lot of change on a lot of files could be suspicious and need a lot of work to review. Breaking it in small step will ease the process.
techknowlogick reviewed 2019-04-13 03:02:44 +00:00
techknowlogick left a comment
Contributor

Some tiny nits. Although the fact that there are so many that are in this PR is it golangci saying we need it this way? If so then that should be reconsidered.

Some tiny nits. Although the fact that there are so many that are in this PR is it golangci saying we need it this way? If so then that should be reconsidered.

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned
@ -298,7 +299,8 @@ func NewTeam(t *Team) (err error) {
Get(new(Team))
if err != nil {

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned
@ -309,7 +311,10 @@ func NewTeam(t *Team) (err error) {
}
if _, err = sess.Insert(t); err != nil {

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned
@ -42,2 +46,4 @@
log.Error("NewRepoRedirect sess.Rollback: %v", errRollback)
}
return err
}

This if statement is not necessary because no matter the outcome err will be returned

This if statement is not necessary because no matter the outcome err will be returned
techknowlogick reviewed 2019-04-13 03:03:56 +00:00

I think a new version was just released so this should be updated to match current version.

I think a new version was just released so this should be updated to match current version.
kolaente commented 2019-04-13 09:20:43 +00:00 (Migrated from github.com)

@techknowlogick These redundant if statements exist just because I put error handling in withough paying attention to the rest around, it's not golanci.
I'll fix these later today.

@techknowlogick These redundant if statements exist just because I put error handling in withough paying attention to the rest around, it's not golanci. I'll fix these later today.
sapk (Migrated from github.com) reviewed 2019-04-13 12:58:50 +00:00
sapk (Migrated from github.com) commented 2019-04-13 12:58:50 +00:00

I think on thoses cases we should return the first error (at end) and log the second.

I think on thoses cases we should return the first error (at end) and log the second.
kolaente (Migrated from github.com) reviewed 2019-04-14 15:25:41 +00:00
kolaente (Migrated from github.com) commented 2019-04-14 15:25:40 +00:00

I've defaulted to the proposal of @sapk for all these issues.

I've defaulted to the proposal of @sapk for all these issues.
kolaente (Migrated from github.com) reviewed 2019-04-14 15:31:43 +00:00
kolaente (Migrated from github.com) commented 2019-04-14 15:31:42 +00:00

Done.

Done.

Fixed most of the issues, however there are some issues where I don't really know what to do:

modules/indexer/issues/indexer.go:95:32: Error return value of `issueIndexerUpdateQueue.Run` is not checked (errcheck)
        go issueIndexerUpdateQueue.Run()
                                      ^

It looks like issueIndexerUpdateQueue.Run() doesn't return an error in any of its implementations. Could we just remove the error return?
I think we could do that.

models/git_diff.go:387:2: S1001: should use copy() instead of a loop (gosimple)
        for idx, lof := range hunk[:headerLines] {
        ^

I don't know how it is possible to let copy only copy some parts of a slice.

copy(newHunk, hunk[:headerLines])
models/repo_list.go:149:2: SA9004: only the first constant in this group has an explicit type (staticcheck)
        SearchOrderByAlphabetically        SearchOrderBy = "name ASC"
        ^

I don't really think this is an issue... or is it?
add SearchOrderBy for every constant line.

routers/user/oauth.go:166:2: SA4006: this value of `errs` is never used (staticcheck)
        errs = form.Validate(ctx.Context, errs)
        ^

If the errors are not checked, can the whole check be removed? Or how can we check for the error?
We should add checking after this line.

> Fixed most of the issues, however there are some issues where I don't really know what to do: > > ``` > modules/indexer/issues/indexer.go:95:32: Error return value of `issueIndexerUpdateQueue.Run` is not checked (errcheck) > go issueIndexerUpdateQueue.Run() > ^ > ``` > It looks like `issueIndexerUpdateQueue.Run()` doesn't return an error in any of its implementations. Could we just remove the error return? I think we could do that. > > ``` > models/git_diff.go:387:2: S1001: should use copy() instead of a loop (gosimple) > for idx, lof := range hunk[:headerLines] { > ^ > ``` > I don't know how it is possible to let `copy` only copy some parts of a slice. ```go copy(newHunk, hunk[:headerLines]) ``` > > ``` > models/repo_list.go:149:2: SA9004: only the first constant in this group has an explicit type (staticcheck) > SearchOrderByAlphabetically SearchOrderBy = "name ASC" > ^ > ``` > I don't really think this is an issue... or is it? add `SearchOrderBy` for every constant line. > > ``` > routers/user/oauth.go:166:2: SA4006: this value of `errs` is never used (staticcheck) > errs = form.Validate(ctx.Context, errs) > ^ > ``` > If the errors are not checked, can the whole check be removed? Or how can we check for the error? We should add checking after this line.
kolaente commented 2019-04-15 09:35:17 +00:00 (Migrated from github.com)

@lunny fixed.

@lunny fixed.
Contributor

Fixed most of the issues, however there are some issues where I don't really know what to do:

modules/indexer/issues/indexer.go:95:32: Error return value of `issueIndexerUpdateQueue.Run` is not checked (errcheck)
        go issueIndexerUpdateQueue.Run()
                                      ^

It looks like issueIndexerUpdateQueue.Run() doesn't return an error in any of its implementations. Could we just remove the error return?

Could just wrap this in an anonymous function:

         go func() {
                  if err := issueIndexerUpdateQueue.Run(); err != nil {
                           log.Error("Error in issueIndexerUpdateQueue.Run(): %v", err)
                  }
         } ()
> Fixed most of the issues, however there are some issues where I don't really know what to do: > > * [ ] > > ``` > modules/indexer/issues/indexer.go:95:32: Error return value of `issueIndexerUpdateQueue.Run` is not checked (errcheck) > go issueIndexerUpdateQueue.Run() > ^ > ``` > It looks like `issueIndexerUpdateQueue.Run()` doesn't return an error in any of its implementations. Could we just remove the error return? Could just wrap this in an anonymous function: ```go go func() { if err := issueIndexerUpdateQueue.Run(); err != nil { log.Error("Error in issueIndexerUpdateQueue.Run(): %v", err) } } () ```
kolaente commented 2019-04-15 20:26:21 +00:00 (Migrated from github.com)

@zeripath Sure I could, but since none of the implementations actually returns an error (the returned is alwasy nil) I'd prefer to alter the signature so the function would never return an error in the first place.

@zeripath Sure I could, but since none of the implementations actually returns an error (the returned is alwasy `nil`) I'd prefer to alter the signature so the function would never return an error in the first place.
Contributor

No worries. Fair enough.

No worries. Fair enough.
kolaente commented 2019-04-16 20:29:06 +00:00 (Migrated from github.com)

@zeripath I've come to the conclusion to not change the function signature and wrap the call in an anonymous function instead as this leaves more room for future implementations.

@zeripath I've come to the conclusion to not change the function signature and wrap the call in an anonymous function instead as this leaves more room for future implementations.
kolaente commented 2019-04-17 09:11:16 +00:00 (Migrated from github.com)

Bleve search tests are failing, not sure why.

Bleve search tests are failing, not sure why.
kolaente commented 2019-04-18 12:33:56 +00:00 (Migrated from github.com)

@lunny do you have an idea about the failing Bleve tests?

@lunny do you have an idea about the failing Bleve tests?
zeripath reviewed 2019-04-18 14:49:34 +00:00
Contributor

This should remain as %s not %v. Golang-ci is wrong here. ColoredValues have a format.

This should remain as %s not %v. Golang-ci is wrong here. ColoredValues have a format.
kolaente (Migrated from github.com) reviewed 2019-04-18 16:44:36 +00:00
kolaente (Migrated from github.com) commented 2019-04-18 16:44:36 +00:00

As disscussed in discord, I'm going to change the signature to return a fmt.Formatter instead.

As disscussed in discord, I'm going to change the signature to return a `fmt.Formatter` instead.

@kolaente It seems not only bleve. I found many failures on CI. https://drone.gitea.io/go-gitea/gitea/8110/1/9

@kolaente It seems not only bleve. I found many failures on CI. https://drone.gitea.io/go-gitea/gitea/8110/1/9
kolaente commented 2019-04-22 11:28:47 +00:00 (Migrated from github.com)
@lunny Looks like it's only bleve: https://drone.gitea.io/go-gitea/gitea/8277/1/10
zeripath reviewed 2019-04-22 20:33:14 +00:00
Contributor

You've changed from crypto/rand to math/rand here. What this deliberate?

You've changed from crypto/rand to math/rand here. What this deliberate?
kolaente (Migrated from github.com) reviewed 2019-04-22 20:38:08 +00:00
kolaente (Migrated from github.com) commented 2019-04-22 20:38:08 +00:00

No, I've changed it back.

No, I've changed it back.
zeripath reviewed 2019-04-22 20:45:08 +00:00
Contributor
			"encoding/json"
			"strconv"

			"code.gitea.io/gitea/models"
```suggestion "encoding/json" "strconv" "code.gitea.io/gitea/models" ```
zeripath reviewed 2019-04-22 20:45:22 +00:00
Contributor
```suggestion ```
zeripath reviewed 2019-04-22 20:45:34 +00:00
Contributor
```suggestion ```
zeripath reviewed 2019-04-22 20:52:43 +00:00
Contributor

Need to move this down to join the rest of the gitea imports

Need to move this down to join the rest of the gitea imports
kolaente (Migrated from github.com) reviewed 2019-04-22 20:58:50 +00:00
kolaente (Migrated from github.com) commented 2019-04-22 20:58:50 +00:00

Fixed.

Fixed.
lunny requested changes 2019-05-06 09:30:39 +00:00
lunny left a comment

Haven't completed the review, but found some issues.

Haven't completed the review, but found some issues.

This should be a wrong change.

This should be a wrong change.

Wrong import order.

Wrong import order.

The logic seems not the same as before.

The logic seems not the same as before.
@ -48,6 +48,9 @@ func renameRepoIsBareToIsEmpty(x *xorm.Engine) error {
if len(indexes) >= 1 {
_, err = sess.Exec("DROP INDEX IDX_repository_is_bare ON repository")
if err != nil {

The err has been resolved on line 59

The `err` has been resolved on line 59
@ -58,6 +58,9 @@ func hashAppToken(x *xorm.Engine) error {
if len(indexes) >= 1 {
_, err = sess.Exec("DROP INDEX UQE_access_token_sha1 ON access_token")
if err != nil {

The err will be handled on line 68

The err will be handled on line 68

why remove this line?

why remove this line?
ngourdon (Migrated from github.com) reviewed 2019-05-08 18:24:30 +00:00
ngourdon (Migrated from github.com) left a comment

Here are some more issues to deal with.
I did not point out every discarded errors as in
160e86fbeb/models/issue_comment_list.go (L97)
imho I think it's a bad idea to update the code to just don't trigger anymore warnings about the errors not handled without dealing with them.

Here are some more issues to deal with. I did not point out every discarded errors as in https://github.com/go-gitea/gitea/blob/160e86fbebcc6b3f29c27385a28984111c5e46fb/models/issue_comment_list.go#L97 imho I think it's a bad idea to update the code to just don't trigger anymore warnings about the errors not handled without dealing with them.
@ -183,3 +184,3 @@
log.Fatal("Failed to bind %s: %v", listenAddr, err)
}
defer listener.Close()
defer func() {
ngourdon (Migrated from github.com) commented 2019-05-08 16:44:39 +00:00

I think this is unnecessary.
You should update the line 184 as it is done a few lines below (L197) to not create a new local err var.
160e86fbeb/cmd/web.go (L184)
160e86fbeb/cmd/web.go (L197-L198)

I think this is unnecessary. You should update the line 184 as it is done a few lines below (L197) to not create a new local `err` var. https://github.com/go-gitea/gitea/blob/160e86fbebcc6b3f29c27385a28984111c5e46fb/cmd/web.go#L184 https://github.com/go-gitea/gitea/blob/160e86fbebcc6b3f29c27385a28984111c5e46fb/cmd/web.go#L197-L198
@ -161,0 +160,4 @@
err := issue.LoadRepo()
if err != nil {
log.Error("LoadRepo: %v", err)
}
ngourdon (Migrated from github.com) commented 2019-05-08 16:32:35 +00:00

The created slice is never used.

	var data map[string]interface{}
The created slice is never used. ```suggestion var data map[string]interface{} ```
ngourdon (Migrated from github.com) commented 2019-05-08 17:02:58 +00:00

The err returned by sess.Insert is lost.
If the sess.Rollback returns no errors, the return statement L178 will return nil.
imho I think this block should always return the err from sess.Insert and only log the err from sess.Rollback

The err returned by sess.Insert is lost. If the sess.Rollback returns no errors, the return statement L178 will return nil. imho I think this block should always return the err from sess.Insert and only log the err from sess.Rollback
ngourdon (Migrated from github.com) commented 2019-05-08 17:03:33 +00:00

The first error is lost.

The first error is lost.
ngourdon (Migrated from github.com) commented 2019-05-08 17:03:53 +00:00

The first error is lost.

The first error is lost.
ngourdon (Migrated from github.com) commented 2019-05-08 17:08:34 +00:00

The first error is lost.

The first error is lost.
@ -231,7 +233,9 @@ func newCommitStatus(sess *xorm.Session, opts NewCommitStatusOptions) error {
ngourdon (Migrated from github.com) commented 2019-05-08 17:09:16 +00:00

The first error is lost.

The first error is lost.
ngourdon (Migrated from github.com) commented 2019-05-08 17:26:08 +00:00

Shouldn't it be (maybe with nil check):

	return "PostProcess: " + p.context + ", " + p.err.Error()
Shouldn't it be (maybe with nil check): ```suggestion return "PostProcess: " + p.context + ", " + p.err.Error() ```
@ -5,6 +5,7 @@
package misc
import (
ngourdon (Migrated from github.com) commented 2019-05-08 17:30:36 +00:00

Wrong order of import

Wrong order of import
ngourdon (Migrated from github.com) commented 2019-05-08 17:36:57 +00:00

OK to change the regexp to raw string, but why change the http method names?

OK to change the regexp to raw string, but why change the http method names?
ngourdon (Migrated from github.com) reviewed 2019-05-08 18:28:02 +00:00
@ -48,6 +48,9 @@ func renameRepoIsBareToIsEmpty(x *xorm.Engine) error {
if len(indexes) >= 1 {
_, err = sess.Exec("DROP INDEX IDX_repository_is_bare ON repository")
if err != nil {
ngourdon (Migrated from github.com) commented 2019-05-08 18:28:01 +00:00

No it is not.
A new local err var is created on line 44 in the block.

No it is not. A new **local** `err` var is created on line 44 in the block.
ngourdon (Migrated from github.com) reviewed 2019-05-08 18:32:15 +00:00
@ -58,6 +58,9 @@ func hashAppToken(x *xorm.Engine) error {
if len(indexes) >= 1 {
_, err = sess.Exec("DROP INDEX UQE_access_token_sha1 ON access_token")
if err != nil {
ngourdon (Migrated from github.com) commented 2019-05-08 18:32:15 +00:00

Same as above.
A new local err var is created on line 54 in the block.

Same as above. A new **local** `err` var is created on line 54 in the block.
kolaente (Migrated from github.com) reviewed 2019-05-08 19:28:03 +00:00
kolaente (Migrated from github.com) commented 2019-05-08 19:28:03 +00:00

Fixed

Fixed
kolaente (Migrated from github.com) reviewed 2019-05-08 19:31:57 +00:00
kolaente (Migrated from github.com) commented 2019-05-08 19:31:57 +00:00

The only thing I did here was to add error handling for the error returned in line 283 and for the one in 289. The logic remains the same.

The only thing I did here was to add error handling for the error returned in line 283 and for the one in 289. The logic remains the same.
kolaente (Migrated from github.com) reviewed 2019-05-08 19:32:08 +00:00
kolaente (Migrated from github.com) commented 2019-05-08 19:32:08 +00:00

Fixed.

Fixed.
kolaente (Migrated from github.com) reviewed 2019-05-08 19:32:29 +00:00
kolaente (Migrated from github.com) commented 2019-05-08 19:32:28 +00:00

Same as my answer before.

Same as my answer before.
kolaente (Migrated from github.com) reviewed 2019-05-08 19:33:30 +00:00
@ -48,6 +48,9 @@ func renameRepoIsBareToIsEmpty(x *xorm.Engine) error {
if len(indexes) >= 1 {
_, err = sess.Exec("DROP INDEX IDX_repository_is_bare ON repository")
if err != nil {
kolaente (Migrated from github.com) commented 2019-05-08 19:33:30 +00:00

@lunny What @ngourdon said.

@lunny What @ngourdon said.
kolaente (Migrated from github.com) reviewed 2019-05-08 19:33:36 +00:00
@ -58,6 +58,9 @@ func hashAppToken(x *xorm.Engine) error {
if len(indexes) >= 1 {
_, err = sess.Exec("DROP INDEX UQE_access_token_sha1 ON access_token")
if err != nil {
kolaente (Migrated from github.com) commented 2019-05-08 19:33:36 +00:00

Same as before.

Same as before.
kolaente (Migrated from github.com) reviewed 2019-05-08 19:37:19 +00:00
kolaente (Migrated from github.com) commented 2019-05-08 19:37:19 +00:00

Good question, I've added it back in.

Good question, I've added it back in.
kolaente (Migrated from github.com) reviewed 2019-05-08 19:39:32 +00:00
@ -161,0 +160,4 @@
err := issue.LoadRepo()
if err != nil {
log.Error("LoadRepo: %v", err)
}
kolaente (Migrated from github.com) commented 2019-05-08 19:39:32 +00:00

It is, in line 171 the map is passed to templates.ExecuteTemplate.

It is, in line 171 the map is passed to `templates.ExecuteTemplate`.
kolaente (Migrated from github.com) reviewed 2019-05-08 19:41:59 +00:00
@ -183,3 +184,3 @@
log.Fatal("Failed to bind %s: %v", listenAddr, err)
}
defer listener.Close()
defer func() {
kolaente (Migrated from github.com) commented 2019-05-08 19:41:59 +00:00

Right, good catch.

Right, good catch.
kolaente (Migrated from github.com) reviewed 2019-05-08 19:45:55 +00:00
kolaente (Migrated from github.com) commented 2019-05-08 19:45:54 +00:00

Sounds like a good idea.

Sounds like a good idea.
kolaente (Migrated from github.com) reviewed 2019-05-08 19:48:47 +00:00
kolaente (Migrated from github.com) commented 2019-05-08 19:48:47 +00:00

I did not change any method names, which ones do you think I changed?

I did not change any method names, which ones do you think I changed?
kolaente (Migrated from github.com) reviewed 2019-05-08 19:48:55 +00:00
kolaente (Migrated from github.com) commented 2019-05-08 19:48:54 +00:00

Changed it so the error is scoped and only available in the if around sess.Rollback().

Changed it so the error is scoped and only available in the if around `sess.Rollback()`.
kolaente commented 2019-05-08 19:51:26 +00:00 (Migrated from github.com)

The bleve test is still failing, @lunny do you have an idea why that is the case?

The bleve test is still failing, @lunny do you have an idea why that is the case?
ngourdon (Migrated from github.com) reviewed 2019-05-08 21:38:55 +00:00
@ -161,0 +160,4 @@
err := issue.LoadRepo()
if err != nil {
log.Error("LoadRepo: %v", err)
}
ngourdon (Migrated from github.com) commented 2019-05-08 21:38:54 +00:00

The value setted on line 161 is overwritten on line 163 or 165.

The value setted on line 161 is overwritten on line 163 or 165.
ngourdon (Migrated from github.com) reviewed 2019-05-08 21:40:30 +00:00
ngourdon (Migrated from github.com) commented 2019-05-08 21:40:30 +00:00

Sorry wasn't clear. You didn't change the names. You changed quotes by backsticks.

Sorry wasn't clear. You didn't change the names. You changed quotes by backsticks.
ngourdon (Migrated from github.com) reviewed 2019-05-08 21:45:45 +00:00
ngourdon (Migrated from github.com) commented 2019-05-08 21:45:44 +00:00

By doing this you changed the behaviour.
The delete is no longer in the if block.
Before the LoginSource was deleted if there was an error. Now it is deleted if there is no errors.

By doing this you changed the behaviour. The delete is no longer in the if block. Before the LoginSource was deleted if there was an error. Now it is deleted if there is no errors.
kolaente (Migrated from github.com) reviewed 2019-05-10 19:40:26 +00:00
kolaente (Migrated from github.com) commented 2019-05-10 19:40:26 +00:00

Yes I did...?

Yes I did...?
kolaente (Migrated from github.com) reviewed 2019-05-10 19:41:15 +00:00
@ -161,0 +160,4 @@
err := issue.LoadRepo()
if err != nil {
log.Error("LoadRepo: %v", err)
}
kolaente (Migrated from github.com) commented 2019-05-10 19:41:15 +00:00

But your suggestion would not pre-allocate a map with 10 items, only make it available.

But your suggestion would not pre-allocate a map with 10 items, only make it available.
ngourdon (Migrated from github.com) reviewed 2019-05-11 13:28:33 +00:00
ngourdon (Migrated from github.com) commented 2019-05-11 13:28:32 +00:00

There's no need.
Raw strings should be used for regexp.MustCompile to avoid having to escape twice. Nothing more.
By the way, the multiples escaping should be deleted. I didn't see it before. I thought there were no escaping.

{regexp.MustCompile("(.*?)/objects/pack/pack-[0-9a-f]{40}\\.pack$"), "GET", getPackFile},
{regexp.MustCompile("(.*?)/objects/pack/pack-[0-9a-f]{40}\\.idx$"), "GET", getIdxFile},

Should be changed to (only one backslash):

{regexp.MustCompile(`(.*?)/objects/pack/pack-[0-9a-f]{40}\.pack$`), "GET", getPackFile},
{regexp.MustCompile(`(.*?)/objects/pack/pack-[0-9a-f]{40}\.idx$`), "GET", getIdxFile},
There's no need. Raw strings should be used for regexp.MustCompile to avoid having to escape twice. Nothing more. By the way, the multiples escaping should be deleted. I didn't see it before. I thought there were no escaping. ``` {regexp.MustCompile("(.*?)/objects/pack/pack-[0-9a-f]{40}\\.pack$"), "GET", getPackFile}, {regexp.MustCompile("(.*?)/objects/pack/pack-[0-9a-f]{40}\\.idx$"), "GET", getIdxFile}, ``` Should be changed to (only one backslash): ``` {regexp.MustCompile(`(.*?)/objects/pack/pack-[0-9a-f]{40}\.pack$`), "GET", getPackFile}, {regexp.MustCompile(`(.*?)/objects/pack/pack-[0-9a-f]{40}\.idx$`), "GET", getIdxFile}, ```
ngourdon (Migrated from github.com) reviewed 2019-05-11 13:52:58 +00:00
@ -161,0 +160,4 @@
err := issue.LoadRepo()
if err != nil {
log.Error("LoadRepo: %v", err)
}
ngourdon (Migrated from github.com) commented 2019-05-11 13:52:58 +00:00

This seems unnecessary because it will not be used. I think that's what raised this issue in the first place IMHO.

This seems unnecessary because it will not be used. I think that's what raised this issue in the first place IMHO.
kolaente (Migrated from github.com) reviewed 2019-05-11 17:19:57 +00:00
kolaente (Migrated from github.com) commented 2019-05-11 17:19:57 +00:00

Ah now I get what you mean, thanks for clarifying 😅 . Fixed it.

Ah now I get what you mean, thanks for clarifying :sweat_smile: . Fixed it.
ngourdon (Migrated from github.com) reviewed 2019-05-29 18:01:46 +00:00
ngourdon (Migrated from github.com) left a comment

Found some tiny issues

Found some tiny issues
ngourdon (Migrated from github.com) commented 2019-05-29 16:15:23 +00:00

It seems err will always be nil here.

It seems `err` will always be nil here.
ngourdon (Migrated from github.com) commented 2019-05-29 16:28:14 +00:00

Why is there different handling of error on Close()?
L159, L248, L301, L453: error is ignored
L345, L393: error is returned to caller

Why is there different handling of error on `Close()`? L159, L248, L301, L453: error is ignored L345, L393: error is returned to caller
ngourdon (Migrated from github.com) commented 2019-05-29 16:33:08 +00:00

As @lunny said before

The logic seems not the same as before.

Before the LoginSource was deleted if there was an error. Now it is deleted if there is no errors.

As @lunny said before > The logic seems not the same as before. Before the LoginSource was deleted if there was an error. Now it is deleted if there is no errors.
ngourdon (Migrated from github.com) commented 2019-05-29 16:35:21 +00:00

Same as above

Same as above
ngourdon (Migrated from github.com) commented 2019-05-29 16:36:17 +00:00
	alphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`)
```suggestion alphaDashDotPattern = regexp.MustCompile(`[^\w-\.]`) ```
ngourdon (Migrated from github.com) commented 2019-05-29 16:57:09 +00:00

IMHO this error should only be logged and the method should return the initial error returned by the Insert().
Same for L488 and L493

IMHO this error should only be logged and the method should return the initial error returned by the `Insert()`. Same for L488 and L493
ngourdon (Migrated from github.com) commented 2019-05-29 17:11:10 +00:00

IMHO this error should only be logged and the method should return the initial error.
Same for L237

IMHO this error should only be logged and the method should return the initial error. Same for L237
ngourdon (Migrated from github.com) commented 2019-05-29 17:26:59 +00:00
	{regexp.MustCompile(`(.*?)/objects/pack/pack-[0-9a-f]{40}\.pack$`), "GET", getPackFile},
```suggestion {regexp.MustCompile(`(.*?)/objects/pack/pack-[0-9a-f]{40}\.pack$`), "GET", getPackFile}, ```
ngourdon (Migrated from github.com) commented 2019-05-29 17:46:33 +00:00
	{regexp.MustCompile(`(.*?)/objects/pack/pack-[0-9a-f]{40}\.idx$`), "GET", getIdxFile},
```suggestion {regexp.MustCompile(`(.*?)/objects/pack/pack-[0-9a-f]{40}\.idx$`), "GET", getIdxFile}, ```
kolaente (Migrated from github.com) reviewed 2019-05-30 19:09:35 +00:00
kolaente (Migrated from github.com) commented 2019-05-30 19:09:35 +00:00

Sounds like a good idea, thanks.

Sounds like a good idea, thanks.
kolaente (Migrated from github.com) reviewed 2019-05-30 19:13:09 +00:00
kolaente (Migrated from github.com) commented 2019-05-30 19:13:09 +00:00

Thanks, fixed

Thanks, fixed
kolaente (Migrated from github.com) reviewed 2019-05-30 19:15:00 +00:00
kolaente (Migrated from github.com) commented 2019-05-30 19:15:00 +00:00

Mhh good point. I've changed it so the error is always returned.

Mhh good point. I've changed it so the error is always returned.
kolaente (Migrated from github.com) reviewed 2019-05-30 19:18:27 +00:00
kolaente (Migrated from github.com) commented 2019-05-30 19:18:26 +00:00

You're right, I did not see that. I've changed it so that an error from x.Delete is at logged.

You're right, I did not see that. I've changed it so that an error from `x.Delete` is at logged.
kolaente commented 2019-05-30 19:43:16 +00:00 (Migrated from github.com)

OK so it looks like I've returned any error (while loading issue details) when calling rows.Close() which always returns an error when there are no more rows left (because all are processed). So in 10/10 cases, this method returns an error if the code before did not errored out. This led to the function erroring out even if it processed all issues correctly. This caused the bleve tests to fail.
I wonder why calling rows.Close() is needed if it always fails because there are no rows left to close...

TL;DR: I hopefully fixed the failing bleve indexer issues (would be interesting though to find out why this was only caught by bleve tests).

OK so it looks like I've returned any error (while loading issue details) when calling `rows.Close()` which _always_ returns an error when there are no more rows left (because all are processed). So in 10/10 cases, this method returns an error if the code before did not errored out. This led to the function erroring out even if it processed all issues correctly. This caused the bleve tests to fail. I wonder why calling `rows.Close()` is needed if it always fails because there are no rows left to close... TL;DR: I hopefully fixed the failing bleve indexer issues (would be interesting though to find out why this was only caught by bleve tests).
kolaente commented 2019-06-06 08:39:11 +00:00 (Migrated from github.com)

Ok, so this test is still failing:

    --- FAIL: TestRepository_AddWikiPage/check_wiki_already_exist (94.76s)
        wiki_test.go:177: 
            	Error Trace:	wiki_test.go:177
            	Error:      	An error is expected but got nil.
            	Test:       	TestRepository_AddWikiPage/check_wiki_already_exist
        wiki_test.go:178: 
            	Error Trace:	wiki_test.go:178
            	Error:      	Should be true
            	Test:       	TestRepository_AddWikiPage/check_wiki_already_exist
FAIL

Does anyone have an idea why?

(Bleve tests are working now)

Ok, so this test is still failing: ``` --- FAIL: TestRepository_AddWikiPage/check_wiki_already_exist (94.76s) wiki_test.go:177: Error Trace: wiki_test.go:177 Error: An error is expected but got nil. Test: TestRepository_AddWikiPage/check_wiki_already_exist wiki_test.go:178: Error Trace: wiki_test.go:178 Error: Should be true Test: TestRepository_AddWikiPage/check_wiki_already_exist FAIL ``` Does anyone have an idea why? (Bleve tests are working now)
richmahn commented 2019-06-06 11:37:24 +00:00 (Migrated from github.com)

@kolaente Could it be that the "Home" wiki page that should already exist for that test doesn't exist, and is created in wiki_test.go 196? Not show these get called and what ensures "Home" exists for that test around line 177.

@kolaente Could it be that the "Home" wiki page that should already exist for that test doesn't exist, and is created in wiki_test.go 196? Not show these get called and what ensures "Home" exists for that test around line 177.
kolaente commented 2019-06-06 13:07:56 +00:00 (Migrated from github.com)

@richmahn Yeah it looks like that home page just does not exist. I tried changing the order of the tests so that the one in L196 is executed first, but that did not change anything. I also tried to change the name to "Another page" instead of "Home" to see if that would work since "Another page" should have been created successfully before that check. Didn't work either, which lets me think I broke something when creating the fixtures/new wikis...

Does anyone know where the wiki fixtures (the git repos) are created in the tests?

@richmahn Yeah it looks like that home page just does not exist. I tried changing the order of the tests so that the one in L196 is executed first, but that did not change anything. I also tried to change the name to "Another page" instead of "Home" to see if that would work since "Another page" should have been created successfully before that check. Didn't work either, which lets me think I broke something when creating the fixtures/new wikis... Does anyone know where the wiki fixtures (the git repos) are created in the tests?
kolaente commented 2019-06-06 13:22:28 +00:00 (Migrated from github.com)

It neither does work when I add "Home" to the list in L153

It neither does work when I add "Home" to the list in L153
kolaente commented 2019-06-06 13:30:06 +00:00 (Migrated from github.com)

OK, so I replaced this:

	defer RemoveTemporaryPath(basePath)

with this

defer func() {
		if err = RemoveTemporaryPath(basePath); err != nil {
			log.Error("Merge: RemoveTemporaryPath: %s", err)
		}
	}()

in models/wiki.go:118

When I revert that, the wiki test passes. and I have absolutly no idea why. Anyon have an idea?

OK, so I replaced this: ```go defer RemoveTemporaryPath(basePath) ``` with this ```go defer func() { if err = RemoveTemporaryPath(basePath); err != nil { log.Error("Merge: RemoveTemporaryPath: %s", err) } }() ``` in models/wiki.go:118 When I revert that, the wiki test passes. and I have absolutly no idea why. Anyon have an idea?
kolaente commented 2019-06-06 13:35:12 +00:00 (Migrated from github.com)

Also when I change my modified defer function call to this

	defer func() {
		err := RemoveTemporaryPath(basePath)
		if err != nil {
			log.Error("Merge: RemoveTemporaryPath: %s", err)
		}
	}()

it works again. And I still have no idea why. Seems very odd.

Also this:

	defer func() {
		if err := RemoveTemporaryPath(basePath); err != nil {
			log.Error("Merge: RemoveTemporaryPath: %s", err)
		}
	}()

seems to work.

So it seems like this is some error with scoping...
Anyone has an idea about why this does not work?

Also when I change my modified `defer` function call to this ```go defer func() { err := RemoveTemporaryPath(basePath) if err != nil { log.Error("Merge: RemoveTemporaryPath: %s", err) } }() ``` it works again. And I still have no idea why. Seems very odd. Also this: ```go defer func() { if err := RemoveTemporaryPath(basePath); err != nil { log.Error("Merge: RemoveTemporaryPath: %s", err) } }() ``` seems to work. So it seems like this is some error with scoping... Anyone has an idea about why this does not work?
richmahn commented 2019-06-06 13:38:47 +00:00 (Migrated from github.com)

@kolaente looks like you need that := instead of = for err :=

@kolaente looks like you need that := instead of = for err :=
kolaente commented 2019-06-06 13:41:31 +00:00 (Migrated from github.com)

@richmahn it looks like it, the unit tests are passing now...

@richmahn it looks like it, the unit tests are passing now...
codecov-io commented 2019-06-06 14:03:12 +00:00 (Migrated from github.com)

Codecov Report

Merging #6418 into master will decrease coverage by 0.2%.
The diff coverage is 26.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6418      +/-   ##
==========================================
- Coverage   41.72%   41.52%   -0.21%     
==========================================
  Files         449      449              
  Lines       61129    61302     +173     
==========================================
- Hits        25506    25454      -52     
- Misses      32310    32494     +184     
- Partials     3313     3354      +41
Impacted Files Coverage Δ
routers/admin/admin.go 0% <ø> (ø) ⬆️
routers/private/hook.go 47.95% <ø> (+0.27%) ⬆️
modules/log/smtp.go 89.36% <ø> (ø) ⬆️
modules/structs/utils.go 0% <ø> (ø) ⬆️
models/repo_list.go 72.08% <ø> (-1.02%) ⬇️
routers/api/v1/repo/repo.go 61.54% <ø> (+0.49%) ⬆️
routers/private/serv.go 34.18% <ø> (-0.42%) ⬇️
models/issue_label.go 62.12% <ø> (+1.38%) ⬆️
modules/git/utils.go 83.72% <ø> (+3.72%) ⬆️
modules/git/commit_info.go 72.54% <ø> (+3.17%) ⬆️
... and 109 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5832f8d...4a865f4. Read the comment docs.

# [Codecov](https://codecov.io/gh/go-gitea/gitea/pull/6418?src=pr&el=h1) Report > Merging [#6418](https://codecov.io/gh/go-gitea/gitea/pull/6418?src=pr&el=desc) into [master](https://codecov.io/gh/go-gitea/gitea/commit/5832f8d90df2d72cb38698c3e9050f2b29717dc7?src=pr&el=desc) will **decrease** coverage by `0.2%`. > The diff coverage is `26.27%`. [![Impacted file tree graph](https://codecov.io/gh/go-gitea/gitea/pull/6418/graphs/tree.svg?width=650&token=t1G57YGbPy&height=150&src=pr)](https://codecov.io/gh/go-gitea/gitea/pull/6418?src=pr&el=tree) ```diff @@ Coverage Diff @@ ## master #6418 +/- ## ========================================== - Coverage 41.72% 41.52% -0.21% ========================================== Files 449 449 Lines 61129 61302 +173 ========================================== - Hits 25506 25454 -52 - Misses 32310 32494 +184 - Partials 3313 3354 +41 ``` | [Impacted Files](https://codecov.io/gh/go-gitea/gitea/pull/6418?src=pr&el=tree) | Coverage Δ | | |---|---|---| | [routers/admin/admin.go](https://codecov.io/gh/go-gitea/gitea/pull/6418/diff?src=pr&el=tree#diff-cm91dGVycy9hZG1pbi9hZG1pbi5nbw==) | `0% <ø> (ø)` | :arrow_up: | | [routers/private/hook.go](https://codecov.io/gh/go-gitea/gitea/pull/6418/diff?src=pr&el=tree#diff-cm91dGVycy9wcml2YXRlL2hvb2suZ28=) | `47.95% <ø> (+0.27%)` | :arrow_up: | | [modules/log/smtp.go](https://codecov.io/gh/go-gitea/gitea/pull/6418/diff?src=pr&el=tree#diff-bW9kdWxlcy9sb2cvc210cC5nbw==) | `89.36% <ø> (ø)` | :arrow_up: | | [modules/structs/utils.go](https://codecov.io/gh/go-gitea/gitea/pull/6418/diff?src=pr&el=tree#diff-bW9kdWxlcy9zdHJ1Y3RzL3V0aWxzLmdv) | `0% <ø> (ø)` | :arrow_up: | | [models/repo\_list.go](https://codecov.io/gh/go-gitea/gitea/pull/6418/diff?src=pr&el=tree#diff-bW9kZWxzL3JlcG9fbGlzdC5nbw==) | `72.08% <ø> (-1.02%)` | :arrow_down: | | [routers/api/v1/repo/repo.go](https://codecov.io/gh/go-gitea/gitea/pull/6418/diff?src=pr&el=tree#diff-cm91dGVycy9hcGkvdjEvcmVwby9yZXBvLmdv) | `61.54% <ø> (+0.49%)` | :arrow_up: | | [routers/private/serv.go](https://codecov.io/gh/go-gitea/gitea/pull/6418/diff?src=pr&el=tree#diff-cm91dGVycy9wcml2YXRlL3NlcnYuZ28=) | `34.18% <ø> (-0.42%)` | :arrow_down: | | [models/issue\_label.go](https://codecov.io/gh/go-gitea/gitea/pull/6418/diff?src=pr&el=tree#diff-bW9kZWxzL2lzc3VlX2xhYmVsLmdv) | `62.12% <ø> (+1.38%)` | :arrow_up: | | [modules/git/utils.go](https://codecov.io/gh/go-gitea/gitea/pull/6418/diff?src=pr&el=tree#diff-bW9kdWxlcy9naXQvdXRpbHMuZ28=) | `83.72% <ø> (+3.72%)` | :arrow_up: | | [modules/git/commit\_info.go](https://codecov.io/gh/go-gitea/gitea/pull/6418/diff?src=pr&el=tree#diff-bW9kdWxlcy9naXQvY29tbWl0X2luZm8uZ28=) | `72.54% <ø> (+3.17%)` | :arrow_up: | | ... and [109 more](https://codecov.io/gh/go-gitea/gitea/pull/6418/diff?src=pr&el=tree-more) | | ------ [Continue to review full report at Codecov](https://codecov.io/gh/go-gitea/gitea/pull/6418?src=pr&el=continue). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta) > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://codecov.io/gh/go-gitea/gitea/pull/6418?src=pr&el=footer). Last update [5832f8d...4a865f4](https://codecov.io/gh/go-gitea/gitea/pull/6418?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
kolaente commented 2019-06-06 14:10:45 +00:00 (Migrated from github.com)

Ci passed! ?

Ci passed! ?
ngourdon commented 2019-06-06 14:19:39 +00:00 (Migrated from github.com)

@kolaente
As you figured out you have to use := in defer func to declare a new local var.
If you do not, you use the err which is the return value (see func declaration).
By doing so, in the defer func you overwrite the ErrWikiAlreadyExist (in your case) by a nil error (because RemoveTemporaryPath do not return an error)

seems there is the same problem in models/wiki.go:254

@kolaente As you figured out you have to use `:=` in defer func to declare a new local var. If you do not, you use the err which is the return value (see func declaration). By doing so, in the defer func you overwrite the ErrWikiAlreadyExist (in your case) by a nil error (because RemoveTemporaryPath do not return an error) seems there is the same problem in models/wiki.go:254
kolaente commented 2019-06-06 17:05:22 +00:00 (Migrated from github.com)

I've looked again at all the cases when a defer function call would log an error and made sure the error would not override any other errors.

With all tests passing, this should be ready to review now (finally).

I've looked again at all the cases when a `defer` function call would log an error and made sure the error would not override any other errors. With all tests passing, this should be ready to review now (finally).
zeripath approved these changes 2019-06-06 17:17:11 +00:00
zeripath reviewed 2019-06-06 17:25:59 +00:00
Contributor

This doesn't look like we're ignoring the empty rows.Close() error....

This doesn't look like we're ignoring the empty rows.Close() error....
zeripath reviewed 2019-06-06 17:27:06 +00:00
@ -439,33 +486,33 @@ func (issues IssueList) loadTotalTrackedTimes(e Engine) (err error) {
}
Contributor

Probably don't need a named err here any more.

Probably don't need a named err here any more.
kolaente (Migrated from github.com) reviewed 2019-06-06 17:29:02 +00:00
kolaente (Migrated from github.com) commented 2019-06-06 17:29:02 +00:00

Well, we're not really using it, only logging it. Do you think I should explicitly ignore it?

Well, we're not really using it, only logging it. Do you think I should explicitly ignore it?
kolaente (Migrated from github.com) reviewed 2019-06-06 17:29:18 +00:00
kolaente (Migrated from github.com) commented 2019-06-06 17:29:17 +00:00

(Also applies to the various other places where I use this)

(Also applies to the various other places where I use this)
kolaente (Migrated from github.com) reviewed 2019-06-06 17:30:57 +00:00
@ -439,33 +486,33 @@ func (issues IssueList) loadTotalTrackedTimes(e Engine) (err error) {
}
kolaente (Migrated from github.com) commented 2019-06-06 17:30:57 +00:00

Right, fixed it.

Right, fixed it.
zeripath reviewed 2019-06-06 17:39:03 +00:00
Contributor

I think we should keep the engine here.

I think we should keep the engine here.
zeripath reviewed 2019-06-06 17:39:22 +00:00
Contributor

I think we should keep the engine here

I think we should keep the engine here
zeripath reviewed 2019-06-06 17:39:51 +00:00
Contributor

This should take the engine, i.e. be getRepositoryByID(e, r.RepoID)

This should take the engine, i.e. be getRepositoryByID(e, r.RepoID)
zeripath reviewed 2019-06-06 17:40:19 +00:00
Contributor

And line 53 should similarly use the provided engine

And line 53 should similarly use the provided engine
zeripath reviewed 2019-06-06 17:40:58 +00:00
Contributor

and line 58 should be getReleaseAttachments(e, r) assuming that exists...

and line 58 should be getReleaseAttachments(e, r) assuming that exists...
kolaente (Migrated from github.com) reviewed 2019-06-06 18:14:18 +00:00
kolaente (Migrated from github.com) commented 2019-06-06 18:14:18 +00:00

But it was never used inside of loadAttributes?

But it was never used inside of `loadAttributes`?
kolaente (Migrated from github.com) reviewed 2019-06-06 18:17:05 +00:00
kolaente (Migrated from github.com) commented 2019-06-06 18:17:04 +00:00

Ah ok. Although that is nothing I changed, but that's why I removed the Engine since it wasn't used at all.

Ah ok. Although that is nothing I changed, but that's why I removed the `Engine` since it wasn't used at all.
kolaente (Migrated from github.com) reviewed 2019-06-06 18:19:41 +00:00
kolaente (Migrated from github.com) commented 2019-06-06 18:19:41 +00:00

Fixed.

Fixed.
zeripath reviewed 2019-06-06 18:41:04 +00:00
Contributor

I think we should explicitly ignore it. Don't log things at error if they're not actually an error. Do you know is the error returned a reasonable type?

I think we should explicitly ignore it. Don't log things at error if they're not actually an error. Do you know is the error returned a reasonable type?
kolaente (Migrated from github.com) reviewed 2019-06-06 18:41:57 +00:00
kolaente (Migrated from github.com) commented 2019-06-06 18:41:56 +00:00

getReleaseAttachments does not exist though.

`getReleaseAttachments` does not exist though.
zeripath reviewed 2019-06-06 18:56:09 +00:00
Contributor

I think it needs to exist - if it doesn't any use of loadAttributes() within a transaction could cause a deadlock

I think it needs to exist - if it doesn't any use of loadAttributes() within a transaction could cause a deadlock
zeripath reviewed 2019-06-06 19:04:44 +00:00
Contributor

(Sorry it's not the fault of this PR but it's worth fixing)

(Sorry it's not the fault of this PR but it's worth fixing)
kolaente (Migrated from github.com) reviewed 2019-06-06 19:29:21 +00:00
kolaente (Migrated from github.com) commented 2019-06-06 19:29:21 +00:00

Since this kind of is a refactoring pr, I thinks it's ok to fix smaller things like this when we stumble upon them, but I'd prefer if these won't get to be the majority of things this pr fixes. So as long as there aren't too many, I'll fix these. Though we should probably do a seperate pr to specifically fix things like this (seperatly).

(I've fixed the thing with GetReleaseAttachments)

Since this kind of is a refactoring pr, I thinks it's ok to fix smaller things like this when we stumble upon them, but I'd prefer if these won't get to be the majority of things this pr fixes. So as long as there aren't too many, I'll fix these. Though we should probably do a seperate pr to specifically fix things like this (seperatly). (I've fixed the thing with `GetReleaseAttachments`)
Contributor

thanks @kolaente !

thanks @kolaente !

conflicted

conflicted
kolaente commented 2019-06-09 19:59:29 +00:00 (Migrated from github.com)

@lunny fixed.

@lunny fixed.
kolaente commented 2019-06-10 14:14:10 +00:00 (Migrated from github.com)

@lunny @sapk please approve.

@lunny @sapk please approve.
lunny reviewed 2019-06-10 14:44:58 +00:00

Is this a bug of xorm of your comment?

Is this a bug of xorm of your comment?
lunny reviewed 2019-06-10 14:46:33 +00:00
@ -161,0 +160,4 @@
err := issue.LoadRepo()
if err != nil {
log.Error("LoadRepo: %v", err)
}

This function should return error as second return parameter I think.

This function should return error as second return parameter I think.
lunny requested changes 2019-06-10 15:19:53 +00:00
@ -7,1 +7,3 @@
import "strings"
import (
"code.gitea.io/gitea/modules/log"
"strings"

import order

import order

maybe this should be return err == nil?

maybe this should be `return err == nil`?
@ -14,2 +14,4 @@
"strings"
"time"
logger "code.gitea.io/gitea/modules/log"

Why we need a package alias here?

Why we need a package alias here?

It seems this change is unnecessary.

It seems this change is unnecessary.

import order

import order
@ -100,2 +100,4 @@
result, n, err := transform.String(charsetEncoding.NewDecoder(), string(buf))
if err != nil {
// return default

Maybe we should add a log here.

Maybe we should add a log here.

just move line 176 here.

just move line 176 here.
@ -345,3 +345,3 @@
curLen := n*newLen + len(s[i:])
replacement := make([]byte, curLen, curLen)
replacement := make([]byte, curLen)

Why change this line?

Why change this line?

I think we need keep line 166 and add check for errs.

I think we need keep line 166 and add check for `errs`.

This line could be removed?

This line could be removed?
kolaente (Migrated from github.com) reviewed 2019-06-10 18:35:30 +00:00
@ -14,2 +14,4 @@
"strings"
"time"
logger "code.gitea.io/gitea/modules/log"
kolaente (Migrated from github.com) commented 2019-06-10 18:35:30 +00:00

Because there is a variable log which was declared in the git package.

Because there is a variable `log` which was declared in the `git` package.
kolaente (Migrated from github.com) reviewed 2019-06-10 18:37:58 +00:00
@ -345,3 +345,3 @@
curLen := n*newLen + len(s[i:])
replacement := make([]byte, curLen, curLen)
replacement := make([]byte, curLen)
kolaente (Migrated from github.com) commented 2019-06-10 18:37:58 +00:00

Because the cap of a new slice is optional and if omitted, it is the same as the provided len. So since it is the same here, there's no need to specify both.

Because the `cap` of a new slice is optional and if omitted, it is the same as the provided `len`. So since it is the same here, there's no need to specify both.
kolaente (Migrated from github.com) reviewed 2019-06-10 18:38:47 +00:00
kolaente (Migrated from github.com) commented 2019-06-10 18:38:46 +00:00

Yes, I overlooked that.

Yes, I overlooked that.
kolaente (Migrated from github.com) reviewed 2019-06-10 18:40:35 +00:00
kolaente (Migrated from github.com) commented 2019-06-10 18:40:35 +00:00

You mean, adding a cherck if len(errs) > 0? And what should happen in that case?

You mean, adding a cherck `if len(errs) > 0`? And what should happen in that case?
kolaente (Migrated from github.com) reviewed 2019-06-10 18:41:42 +00:00
kolaente (Migrated from github.com) commented 2019-06-10 18:41:42 +00:00

But it is used in L124 (and various other places)

But it is used in L124 (and various other places)
kolaente (Migrated from github.com) reviewed 2019-06-10 18:42:49 +00:00
@ -100,2 +100,4 @@
result, n, err := transform.String(charsetEncoding.NewDecoder(), string(buf))
if err != nil {
// return default
kolaente (Migrated from github.com) commented 2019-06-10 18:42:49 +00:00

There are a lot other cases where the default is returned if there was an error, should I log it there too?

There are a lot other cases where the default is returned if there was an error, should I log it there too?
kolaente (Migrated from github.com) reviewed 2019-06-10 18:44:18 +00:00
kolaente (Migrated from github.com) commented 2019-06-10 18:44:17 +00:00

Right.

Right.
kolaente (Migrated from github.com) reviewed 2019-06-10 18:44:36 +00:00
@ -7,1 +7,3 @@
import "strings"
import (
"code.gitea.io/gitea/modules/log"
"strings"
kolaente (Migrated from github.com) commented 2019-06-10 18:44:35 +00:00

Done.

Done.
kolaente (Migrated from github.com) reviewed 2019-06-10 18:46:49 +00:00
kolaente (Migrated from github.com) commented 2019-06-10 18:46:49 +00:00

Kind of, fmt.Fprintf(w, format) would not print anything IIRC since there is no format string. fmt.Fprintf(w, "%s", format) adds this format string. But since all this is doing is returning the error, I adjusted it to just fmt.Fprint(w, format).

Kind of, `fmt.Fprintf(w, format)` would not print anything IIRC since there is no format string. `fmt.Fprintf(w, "%s", format)` adds this format string. But since all this is doing is returning the error, I adjusted it to just `fmt.Fprint(w, format)`.
kolaente (Migrated from github.com) reviewed 2019-06-10 18:46:56 +00:00
kolaente (Migrated from github.com) commented 2019-06-10 18:46:56 +00:00

Done.

Done.
kolaente (Migrated from github.com) reviewed 2019-06-10 18:47:07 +00:00
kolaente (Migrated from github.com) commented 2019-06-10 18:47:07 +00:00

Fixed.

Fixed.
kolaente (Migrated from github.com) reviewed 2019-06-10 18:47:32 +00:00
kolaente (Migrated from github.com) commented 2019-06-10 18:47:31 +00:00

Done.

Done.
lunny reviewed 2019-06-11 00:43:48 +00:00

@kolaente all code.gitea.io packages should be splitted with external packages with blank line. See https://github.com/go-gitea/gitea/blob/master/CONTRIBUTING.md#styleguide

@kolaente all `code.gitea.io` packages should be splitted with external packages with blank line. See https://github.com/go-gitea/gitea/blob/master/CONTRIBUTING.md#styleguide
lunny reviewed 2019-06-11 00:45:10 +00:00

Yes, I think form validate should not be ignored. If there are some errs, we can return first err of errs I think or we can join all the errs as a new err.

Yes, I think form validate should not be ignored. If there are some `errs`, we can return first `err` of `errs` I think or we can join all the `errs` as a new `err`.
lunny reviewed 2019-06-11 00:46:05 +00:00
@ -14,2 +14,4 @@
"strings"
"time"
logger "code.gitea.io/gitea/modules/log"

In this file, there is no other package named log.

In this file, there is no other package named `log`.
lunny reviewed 2019-06-11 00:52:02 +00:00

I don't think fmt.Fprintf(w, format) will not print anything, see https://play.golang.org/p/sjVCTMbTarA

I don't think `fmt.Fprintf(w, format)` will not print anything, see https://play.golang.org/p/sjVCTMbTarA
kolaente (Migrated from github.com) reviewed 2019-06-11 08:31:03 +00:00
kolaente (Migrated from github.com) commented 2019-06-11 08:31:03 +00:00

Oh, now I understand what you mean, I though you wanted me to import it as _. Will fix asap.

Oh, now I understand what you mean, I though you wanted me to import it as `_`. Will fix asap.
kolaente (Migrated from github.com) reviewed 2019-06-11 08:33:56 +00:00
kolaente (Migrated from github.com) commented 2019-06-11 08:33:56 +00:00

Fixed.

Fixed.
kolaente (Migrated from github.com) reviewed 2019-06-11 08:58:34 +00:00
kolaente (Migrated from github.com) commented 2019-06-11 08:58:34 +00:00

I've joined and returned them now.

I've joined and returned them now.
kolaente (Migrated from github.com) reviewed 2019-06-11 09:14:29 +00:00
@ -161,0 +160,4 @@
err := issue.LoadRepo()
if err != nil {
log.Error("LoadRepo: %v", err)
}
kolaente (Migrated from github.com) commented 2019-06-11 09:14:29 +00:00

The problem is it is called in SendAsync which just puts the mail in a queue to be sent. There's not much room for error handling there.

The problem is it is called in `SendAsync` which just puts the mail in a queue to be sent. There's not much room for error handling there.
lunny reviewed 2019-06-11 14:22:10 +00:00

Sorry, missed this. This is different from previous on logic.

Sorry, missed this. This is different from previous on logic.
lunny reviewed 2019-06-11 14:25:42 +00:00
@ -161,0 +160,4 @@
err := issue.LoadRepo()
if err != nil {
log.Error("LoadRepo: %v", err)
}

Or we have to return nil here, otherwise it may panic when invoke issue.Repo.HTMLURL().

Or we have to return nil here, otherwise it may panic when invoke `issue.Repo.HTMLURL()`.
kolaente (Migrated from github.com) reviewed 2019-06-11 14:30:59 +00:00
@ -161,0 +160,4 @@
err := issue.LoadRepo()
if err != nil {
log.Error("LoadRepo: %v", err)
}
kolaente (Migrated from github.com) commented 2019-06-11 14:30:59 +00:00

The problem with this function is the error could never really be handled appropriatly. It would only be bubbled up to then be logged.
I would prefer to leave it as it is, to not having to deal with more complexty bubbling the error up would bring.

The problem with this function is the error could never really be handled appropriatly. It would only be bubbled up to then be logged. I would prefer to leave it as it is, to not having to deal with more complexty bubbling the error up would bring.
kolaente (Migrated from github.com) reviewed 2019-06-11 14:31:45 +00:00
kolaente (Migrated from github.com) commented 2019-06-11 14:31:45 +00:00

So the error from cli.ShowSubcommandHelp(c) should just be logged and then be ignored?

So the error from `cli.ShowSubcommandHelp(c)` should just be logged and then be ignored?
lunny reviewed 2019-06-11 15:36:36 +00:00

I think yes

I think yes
kolaente (Migrated from github.com) reviewed 2019-06-11 20:10:02 +00:00
kolaente (Migrated from github.com) commented 2019-06-11 20:10:02 +00:00

Fixed.

Fixed.
lunny approved these changes 2019-06-12 00:45:36 +00:00
This repo is archived. You cannot comment on pull requests.
No reviewers
No Milestone
No project
No Assignees
3 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: lunny/gitea#6418
No description provided.