-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
@wolfogre this pull request has failed checks 🛠 |
pkg/common/outbound_ip.go
Outdated
// return nil instead of fatal | ||
return nil |
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 like what net.ParseIP
does.
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 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
.
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.
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) { |
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.
So it's possible to ignore errors when decoding nodes by setting OnDecodeNodeError
to nil.
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 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.
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? |
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 |
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: |
@wolfogre 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 |
@wolfogre Ah I see. The missing piece for me was that you are a maintainer of gitea. That makes sense. |
Codecov Report
@@ 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
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@wolfogre this pull request is now in conflict 😩 |
@wolfogre this pull request has failed checks 🛠 |
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, 世界")
} |
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.
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) { |
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 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.
@wolfogre this pull request has failed checks 🛠 |
@wolfogre this pull request has failed checks 🛠 |
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>
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
.