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

Avoid using log.Fatal in pkg/* #1705

Merged
merged 10 commits into from
Apr 18, 2023
Merged

Conversation

wolfogre
Copy link
Member

Although act is a command line tool, it is also a bad idea to use log.Fatal in packages.

To be clear, only packages which are used as libraries. It's fine to use fatal in cmd.

@wolfogre wolfogre requested a review from a team as a code owner March 28, 2023 07:52
@mergify
Copy link
Contributor

mergify bot commented Mar 28, 2023

@wolfogre this pull request has failed checks 🛠

@mergify mergify bot added the needs-work Extra attention is needed label Mar 28, 2023
Comment on lines 12 to 13
// return nil instead of fatal
return nil
Copy link
Member Author

Choose a reason for hiding this comment

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

Just like what net.ParseIP does.

Copy link
Member

Choose a reason for hiding this comment

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

I think it might make sense to return the err here instead of just nil.
Return only nil will hide the error that could be numerous things as net.Dial does connect to a server. I know it's UDP and therefore stateless (no packet is transferred here).
If you are sure that it could only be an IP parsing error, I'm fine with returning nil.

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact, I noticed that it cannot work without internet access, so #1707

@@ -670,3 +664,17 @@ func (w *Workflow) GetJobIDs() []string {
}
return ids
}

var OnDecodeNodeError = func(node yaml.Node, out interface{}, err error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

So it's possible to ignore errors when decoding nodes by setting OnDecodeNodeError to nil.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand changing all methods to return errors is a much larger task than adding a static handler, better than overriding exit in global logrus object...

Other option would be panic with a custom type and catch it by the Planner to return an error like the official json lib.

@KnisterPeter
Copy link
Member

Hi @wolfogre, can you explain a bit on the reasoning of your changes. Are you using some packages outside of act? Did you stumble upon an error?

@ChristopherHX
Copy link
Contributor

If you use act in a self-hosted runner (see https://nektosact.com/integrations.html) you don't want the runner to terminate on such an error. Instead only the job request should fail.

I know @KnisterPeter uses the act cli and not the golang packages, so you are not affected

@wolfogre
Copy link
Member Author

Are you using some packages outside of act?

TBH, yes. I am a maintainer of Gitea. And Gitea has a CICD runner named act_runner, it based on a soft fork of act.

More context:

@mergify
Copy link
Contributor

mergify bot commented Mar 28, 2023

@wolfogre this pull request has failed checks 🛠

@wolfogre
Copy link
Member Author

wolfogre commented Mar 28, 2023

this pull request has failed checks 🛠

Can the maintainers help take a look?

https://github.com/nektos/act/actions/runs/4540659358/jobs/8001848574?pr=1705

image

@KnisterPeter
Copy link
Member

@wolfogre Ah I see. The missing piece for me was that you are a maintainer of gitea. That makes sense.

@codecov
Copy link

codecov bot commented Mar 28, 2023

Codecov Report

Merging #1705 (9ffc5a6) into master (4989f44) will increase coverage by 1.22%.
The diff coverage is 67.03%.

@@            Coverage Diff             @@
##           master    #1705      +/-   ##
==========================================
+ Coverage   61.22%   62.44%   +1.22%     
==========================================
  Files          46       48       +2     
  Lines        7141     7533     +392     
==========================================
+ Hits         4372     4704     +332     
- Misses       2462     2505      +43     
- Partials      307      324      +17     
Impacted Files Coverage Δ
pkg/common/outbound_ip.go 0.00% <0.00%> (ø)
pkg/container/docker_cli.go 82.23% <ø> (ø)
pkg/container/docker_logger.go 52.08% <ø> (ø)
pkg/container/docker_pull.go 33.33% <ø> (ø)
pkg/container/docker_run.go 14.08% <0.00%> (+0.49%) ⬆️
pkg/container/docker_volume.go 0.00% <ø> (ø)
pkg/container/file_collector.go 39.68% <0.00%> (+2.38%) ⬆️
pkg/container/host_environment.go 0.00% <0.00%> (ø)
pkg/exprparser/functions.go 66.32% <0.00%> (-1.04%) ⬇️
pkg/model/workflow.go 41.68% <13.33%> (-0.44%) ⬇️
... and 21 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@mergify mergify bot removed the needs-work Extra attention is needed label Mar 28, 2023
@mergify
Copy link
Contributor

mergify bot commented Mar 31, 2023

@wolfogre this pull request is now in conflict 😩

@mergify mergify bot added the conflict PR has conflicts label Mar 31, 2023
@mergify mergify bot removed the conflict PR has conflicts label Mar 31, 2023
@mergify
Copy link
Contributor

mergify bot commented Mar 31, 2023

@wolfogre this pull request has failed checks 🛠

@mergify mergify bot added the needs-work Extra attention is needed label Mar 31, 2023
@ChristopherHX
Copy link
Contributor

Seems like gitea and act_runner could also tell logrus to do anything else, I don't really know where global logrus is used in gitea and if log.Fatal() should continue to terminate.

// You can edit this code!
// Click here and start typing.
package main

import (
	"fmt"

	"github.com/sirupsen/logrus"
)

func main() {

	logrus.StandardLogger().ExitFunc = func(s int) {
		fmt.Println("Hello, 世界")
	}
	logrus.StandardLogger().Fatal("MEEE")
	logrus.Fatal("MEEE")
	fmt.Println("Hello, 世界")
}

https://go.dev/play/p/TFKi-2hf4fu

@mergify mergify bot removed the needs-work Extra attention is needed label Mar 31, 2023
Copy link
Contributor

@ChristopherHX ChristopherHX left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@@ -670,3 +664,17 @@ func (w *Workflow) GetJobIDs() []string {
}
return ids
}

var OnDecodeNodeError = func(node yaml.Node, out interface{}, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand changing all methods to return errors is a much larger task than adding a static handler, better than overriding exit in global logrus object...

Other option would be panic with a custom type and catch it by the Planner to return an error like the official json lib.

@mergify
Copy link
Contributor

mergify bot commented Apr 17, 2023

@wolfogre this pull request has failed checks 🛠

@mergify mergify bot added the needs-work Extra attention is needed label Apr 17, 2023
@mergify
Copy link
Contributor

mergify bot commented Apr 17, 2023

@wolfogre this pull request has failed checks 🛠

@mergify mergify bot removed the needs-work Extra attention is needed label Apr 17, 2023
@mergify mergify bot merged commit 816a7d4 into nektos:master Apr 18, 2023
makrsmark pushed a commit to makrsmark/act that referenced this pull request Aug 3, 2023
Follow nektos#1705

Reviewed-on: https://gitea.com/gitea/act/pulls/39
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Jason Song <i@wolfogre.com>
Co-committed-by: Jason Song <i@wolfogre.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants