Skip to content

Conversation

karampok
Copy link
Contributor

@karampok karampok commented Jan 29, 2020

According to the linter

func name will be used as log.LogPanicAndExit by other packages, and that stutters; consider calling this PanicAndExit

Contributes #3592


This change is Reviewable

@karampok karampok requested a review from scrye January 29, 2020 09:53
@scrye
Copy link
Contributor

scrye commented Jan 30, 2020

a discussion (no related file):
It feels like both the old and the new name are misleading.

Regarding the old one, at the call site:

defer log.LogPanicAndExit()

the reader would always think "Why am I logging a panic, I might not have one?", "Why am I exiting the application after finishing this goroutine?". Of course, this isn't what happens, but this is what the naming suggested.

Regarding the new one, at the call site:

defer log.PanicAndExit()

similar questions pop up. "Why am I panicking when finishing this goroutine?", "Why am I exiting?".

I think it's better to not hint at what is happening. So something like:

defer log.HandlePanic()

It's more vague ("How is it handled?"), but vague is better than misleading.

It will also free us from the name implying any contracts at the call site, so we can now plug handlers that do not kill a unit test when a goroutine in there panics (which is almost never what the programmer wants, since it black holes valuable test output).


@karampok karampok force-pushed the pub-refactor-log branch 2 times, most recently from 57dcda9 to 633b61b Compare January 30, 2020 08:38
Copy link
Contributor Author

@karampok karampok left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 69 files reviewed, 1 unresolved discussion (waiting on @scrye)

a discussion (no related file):

Previously, scrye (Sergiu Costea) wrote…

It feels like both the old and the new name are misleading.

Regarding the old one, at the call site:

defer log.LogPanicAndExit()

the reader would always think "Why am I logging a panic, I might not have one?", "Why am I exiting the application after finishing this goroutine?". Of course, this isn't what happens, but this is what the naming suggested.

Regarding the new one, at the call site:

defer log.PanicAndExit()

similar questions pop up. "Why am I panicking when finishing this goroutine?", "Why am I exiting?".

I think it's better to not hint at what is happening. So something like:

defer log.HandlePanic()

It's more vague ("How is it handled?"), but vague is better than misleading.

It will also free us from the name implying any contracts at the call site, so we can now plug handlers that do not kill a unit test when a goroutine in there panics (which is almost never what the programmer wants, since it black holes valuable test output).

I do like that, and I made the change.
One thing that is unclear, in the past I remember that if we had omitted the log.logPanicAndExit there was a linter complaining, which seems not to work now. Anybody knows what/where?


Copy link
Contributor

@scrye scrye left a comment

Choose a reason for hiding this comment

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

Reviewed 69 of 69 files at r2.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @karampok)

a discussion (no related file):

Previously, karampok (Konstantinos) wrote…

I do like that, and I made the change.
One thing that is unclear, in the past I remember that if we had omitted the log.logPanicAndExit there was a linter complaining, which seems not to work now. Anybody know what/where?

I've filed https://github.com/Anapaya/scion/issues/2056 because something feels off, I also was unable to trigger the error.



go/lint/log.go, line 47 at r2 (raw file):

		case *ast.FuncLit:
			if !checkFuncLit(pass, f) {
				pass.Reportf(f.Pos(), "First statement should be 'defer LogHandlePanic()")

s/LogHandlePanic/HandlePanic


go/lint/log.go, line 67 at r2 (raw file):

	if pkgNameSave(pass) == "log" {
		ident, ok := deferStmt.Call.Fun.(*ast.Ident)
		if !ok || ident.Name != "LogHandlePanic" {

Same as above.


go/lint/log.go, line 72 at r2 (raw file):

	} else {
		callSel, ok := deferStmt.Call.Fun.(*ast.SelectorExpr)
		if !ok || callSel.Sel.Name != "LogHandlePanic" {

Same as above.

@karampok karampok force-pushed the pub-refactor-log branch 2 times, most recently from 2bea61d to a77f14b Compare February 17, 2020 11:38
Copy link
Contributor Author

@karampok karampok left a comment

Choose a reason for hiding this comment

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

Reviewable status: 32 of 64 files reviewed, 4 unresolved discussions (waiting on @scrye)

a discussion (no related file):

Previously, scrye (Sergiu Costea) wrote…

I've filed https://github.com/Anapaya/scion/issues/2056 because something feels off, I also was unable to trigger the error.

ok



go/lint/log.go, line 47 at r2 (raw file):

Previously, scrye (Sergiu Costea) wrote…

s/LogHandlePanic/HandlePanic

Done.


go/lint/log.go, line 67 at r2 (raw file):

Previously, scrye (Sergiu Costea) wrote…

Same as above.

Done.


go/lint/log.go, line 72 at r2 (raw file):

Previously, scrye (Sergiu Costea) wrote…

Same as above.

Done.

Copy link
Contributor

@scrye scrye left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 39 of 39 files at r3.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@scrye
Copy link
Contributor

scrye commented Feb 19, 2020

a discussion (no related file):
When merging, please make sure the final commit message refers to log.HandlePanic, and not the older message.


@karampok karampok changed the title log: rename to log.PanicAndExit log: rename to logPanicAndExit to HandlePanic Feb 20, 2020
Copy link
Contributor Author

@karampok karampok left a comment

Choose a reason for hiding this comment

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

Reviewable status: 59 of 64 files reviewed, all discussions resolved (waiting on @scrye)

a discussion (no related file):

Previously, scrye (Sergiu Costea) wrote…

When merging, please make sure the final commit message refers to log.HandlePanic, and not the older message.

the commit/PR message should be ok


According to the linter
```
func name will be used as log.LogPanicAndExit by other packages, and that stutters; consider calling this PanicAndExit

```

Contributes scionproto#3592
@karampok karampok changed the title log: rename to logPanicAndExit to HandlePanic log: rename logPanicAndExit to HandlePanic Feb 20, 2020
Copy link
Contributor

@scrye scrye left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 7 files at r4.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@karampok karampok changed the title log: rename logPanicAndExit to HandlePanic log: rename LogPanicAndExit to HandlePanic Feb 20, 2020
@karampok karampok merged commit efc9ded into scionproto:master Feb 20, 2020
@karampok karampok deleted the pub-refactor-log branch March 18, 2020 09:34
stygerma pushed a commit to stygerma/scion that referenced this pull request Mar 26, 2020
According to the linter

```
func name will be used as log.LogPanicAndExit by other packages, and that stutters; consider calling this PanicAndExit
```
The name HandlePanic was picked.

Contributes scionproto#3592
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants