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

Fix logger refactoring regression: manager logging add #24847

Merged
merged 2 commits into from May 24, 2023

Conversation

wxiaoguang
Copy link
Contributor

The rotate option is optional.

Test result:

image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 22, 2023
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label May 22, 2023
@wxiaoguang wxiaoguang added this to the 1.20.0 milestone May 22, 2023
@wxiaoguang wxiaoguang added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label May 22, 2023
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 22, 2023
@silverwind
Copy link
Member

silverwind commented May 22, 2023

IIRC, there is a lint rule for such missed second arguments on type casts, we should probably use it.

@wxiaoguang
Copy link
Contributor Author

I do not think we need a lint for this case.

Eg: here is a real use case: for a field t any , the caller1 knows its type must be T1, caller2 knows its type must be T2, so the code could be written as : x := t.(T1) directly for caller1. If there is any bug, the runtime panic tells the developers that "you passed incorrect type here, please fix it".

But if it's written as: x, _ := t.(T1) , it loses the strict type check, the caller1 just gets a default T1, which is unexpected.

If it's written as x, ok := t.(T1), then you need to write another if !ok { panic } to show the error.

So, x := t.(T1) is good enough for many cases.

@silverwind
Copy link
Member

If there is any bug, the runtime panic tells the developers that "you passed incorrect type here, please fix it".

Runtime panics are bad because the condition for the panic may not be hit during testing.

If it's written as x, ok := t.(T1), then you need to write another if !ok { panic } to show the error.

I think forcing this style would be okay. Go is (overly) explicit with it's error handling, just not in this case apparently, but it could be enforced with the linter rule.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels May 23, 2023
@silverwind
Copy link
Member

silverwind commented May 23, 2023

For reference, this is the lint option I'm talking about:

linters-settings:
  errcheck:
    # Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
    # Such cases aren't reported by default.
    # Default: false
    check-type-assertions: true

@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label May 23, 2023
@lunny
Copy link
Member

lunny commented May 23, 2023

For reference, this is the lint option I'm talking about:

linters-settings:
  errcheck:
    # Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
    # Such cases aren't reported by default.
    # Default: false
    check-type-assertions: true

Maybe another PR.

@lunny lunny merged commit 979f080 into go-gitea:main May 24, 2023
15 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label May 24, 2023
zjjhot added a commit to zjjhot/gitea that referenced this pull request May 24, 2023
* upstream/main:
  Fix `@font-face` overrides (go-gitea#24855)
  Fix logger refactoring regression: manager logging add (go-gitea#24847)
  Remove publish docs CI workflow (go-gitea#24889)
  Fix double border and adjust width for user profile page (go-gitea#24870)
  Support changing git config through `app.ini`, use `diff.algorithm=histogram` by default (go-gitea#24860)
  Fix flakey test in logger test (go-gitea#24883)
  Run stylelint on .vue files (go-gitea#24865)
  Update `CONTRIBUTING.md` (go-gitea#24492)
  Do not call nil handler for a dummy queue (go-gitea#24880)
  Remove unnecessary usage prefix from doc titles (go-gitea#24869)
  Add API for Label templates (go-gitea#24602)

# Conflicts:
#	.stylelintrc.yaml
#	web_src/css/font_i18n.css
@wxiaoguang wxiaoguang deleted the fix-manager-logging branch May 24, 2023 02:20
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Aug 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants