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

Get rid of glog.fatal #2900

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions clog/clog.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,6 @@ func Errorf(ctx context.Context, format string, args ...interface{}) {
glog.ErrorDepth(1, msg)
}

func Fatalf(ctx context.Context, format string, args ...interface{}) {
if !glog.V(0) {
return
}
msg, _ := formatMessage(ctx, false, false, format, args...)
glog.FatalDepth(1, msg)
}

func Infof(ctx context.Context, format string, args ...interface{}) {
infof(ctx, false, false, format, args...)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/devtool/devtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func main() {

tmp, err := ioutil.TempDir("", "livepeer")
if err != nil {
glog.Fatalf("Can't create temporary directory: %v", err)
glog.Exitf("Can't create temporary directory: %v", err)
}
defer os.RemoveAll(tmp)

Expand All @@ -100,13 +100,13 @@ func main() {
dataDir := filepath.Join(*baseDataDir, t+"_"+acc)
err = os.MkdirAll(dataDir, 0755)
if err != nil {
glog.Fatalf("Can't create directory %v", err)
glog.Exitf("Can't create directory %v", err)
}

keystoreDir := filepath.Join(dataDir, "keystore")
err = moveDir(tempKeystoreDir, keystoreDir)
if err != nil {
glog.Fatal(err)
glog.Exit(err)
}
cfg.KeystoreDir = keystoreDir
cfg.IsBroadcaster = isBroadcaster
Expand All @@ -130,7 +130,7 @@ func main() {
tDataDir := filepath.Join(*baseDataDir, "transcoder_"+acc)
err = os.MkdirAll(tDataDir, 0755)
if err != nil {
glog.Fatalf("Can't create directory %v", err)
glog.Exitf("Can't create directory %v", err)
}
createTranscoderRunScript(acc, tDataDir, serviceHost)
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/devtool/devtool/devtool_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func RemoteConsole(cfg DevtoolConfig) (string, error) {

client, err := rpc.Dial(cfg.Endpoint)
if err != nil {
glog.Fatalf("Unable to attach to remote geth: %v", err)
glog.Exitf("Unable to attach to remote geth: %v", err)
return "", err
}
// get mining account
Expand All @@ -83,11 +83,11 @@ func RemoteConsole(cfg DevtoolConfig) (string, error) {
var accounts []string
err = client.Call(&accounts, "eth_accounts")
if err != nil {
glog.Fatalf("Error finding mining account: %v", err)
glog.Exitf("Error finding mining account: %v", err)
return "", err
}
if len(accounts) == 0 {
glog.Fatal("Can't find mining account")
glog.Exit("Can't find mining account")
return "", errors.New("can't find mining account")
}
gethMiningAccount = accounts[0]
Expand All @@ -96,7 +96,7 @@ func RemoteConsole(cfg DevtoolConfig) (string, error) {

tmp, err := ioutil.TempDir("", "console")
if err != nil {
glog.Fatalf("Can't create temporary directory: %v", err)
glog.Exitf("Can't create temporary directory: %v", err)
return "", err
}
defer os.RemoveAll(tmp)
Expand All @@ -111,7 +111,7 @@ func RemoteConsole(cfg DevtoolConfig) (string, error) {

console, err := console.New(config)
if err != nil {
glog.Fatalf("Failed to start the JavaScript console: %v", err)
glog.Exitf("Failed to start the JavaScript console: %v", err)
return "", err
}
defer console.Stop(false)
Expand All @@ -131,7 +131,7 @@ func RemoteConsole(cfg DevtoolConfig) (string, error) {
glog.Infof("Running eth script: %s", getEthControllerScript)
console.Evaluate(getEthControllerScript)
if printer.Len() == 0 {
glog.Fatal("Can't find deployed controller")
glog.Exit("Can't find deployed controller")
return "", errors.New("can't find deployed controller")
}
ethController = strings.Split(printer.String(), "\n")[0]
Expand Down Expand Up @@ -361,7 +361,7 @@ func CreateKey(keystoreDir string) string {

account, err := keyStore.NewAccount(passphrase)
if err != nil {
glog.Fatal(err)
glog.Exit(err)
}
glog.Infof("Using ETH account: %v", account.Address.Hex())
return account.Address.Hex()
Expand Down
2 changes: 1 addition & 1 deletion cmd/livepeer/livepeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
ff.WithConfigFileParser(ff.PlainParser),
)
if err != nil {
glog.Fatal("Error parsing config: ", err)
glog.Exit("Error parsing config: ", err)

Check warning on line 51 in cmd/livepeer/livepeer.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/livepeer.go#L51

Added line #L51 was not covered by tests
}

vFlag.Value.Set(*verbosity)
Expand Down
41 changes: 17 additions & 24 deletions cmd/livepeer/starter/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,28 +322,24 @@
func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
if *cfg.MaxSessions == "auto" && *cfg.Orchestrator {
if *cfg.Transcoder {
glog.Fatal("-maxSessions 'auto' cannot be used when both -orchestrator and -transcoder are specified")
return
glog.Exit("-maxSessions 'auto' cannot be used when both -orchestrator and -transcoder are specified")

Check warning on line 325 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L325

Added line #L325 was not covered by tests
}
core.MaxSessions = 0
} else {
intMaxSessions, err := strconv.Atoi(*cfg.MaxSessions)
if err != nil || intMaxSessions <= 0 {
glog.Fatal("-maxSessions must be 'auto' or greater than zero")
return
glog.Exit("-maxSessions must be 'auto' or greater than zero")

Check warning on line 331 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L331

Added line #L331 was not covered by tests
}

core.MaxSessions = intMaxSessions
}

if *cfg.Netint != "" && *cfg.Nvidia != "" {
glog.Fatal("both -netint and -nvidia arguments specified, this is not supported")
return
glog.Exit("both -netint and -nvidia arguments specified, this is not supported")

Check warning on line 338 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L338

Added line #L338 was not covered by tests
}

if *cfg.DetectionSampleRate <= 0 {
glog.Fatal("-detectionSampleRate must be greater than zero")
return
glog.Exit("-detectionSampleRate must be greater than zero")

Check warning on line 342 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L342

Added line #L342 was not covered by tests
}

blockPollingTime := time.Duration(*cfg.BlockPollingInterval) * time.Second
Expand Down Expand Up @@ -476,8 +472,7 @@
if *cfg.TestTranscoder {
transcoderCaps, err = core.TestTranscoderCapabilities(devices, tf)
if err != nil {
glog.Fatal(err)
return
glog.Exit(err)

Check warning on line 475 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L475

Added line #L475 was not covered by tests
}
} else {
// no capability test was run, assume default capabilities
Expand Down Expand Up @@ -585,18 +580,16 @@
if (ethAcctAddr == ethcommon.Address{}.Hex()) || ethKeystoreAddr == ethAcctAddr {
*cfg.EthAcctAddr = ethKeystoreAddr
} else {
glog.Fatal("-ethKeystorePath and -ethAcctAddr were both provided, but ethAcctAddr does not match the address found in keystore")
return
glog.Exit("-ethKeystorePath and -ethAcctAddr were both provided, but ethAcctAddr does not match the address found in keystore")

Check warning on line 583 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L583

Added line #L583 was not covered by tests
}
}
} else {
glog.Fatal(fmt.Errorf(err.Error()))
return
glog.Exit(fmt.Errorf(err.Error()))

Check warning on line 587 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L587

Added line #L587 was not covered by tests
}

//Get the Eth client connection information
if *cfg.EthUrl == "" {
glog.Fatal("Need to specify an Ethereum node JSON-RPC URL using -ethUrl")
glog.Exit("Need to specify an Ethereum node JSON-RPC URL using -ethUrl")

Check warning on line 592 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L592

Added line #L592 was not covered by tests
}

//Set up eth client
Expand Down Expand Up @@ -1037,7 +1030,7 @@
if *cfg.AuthWebhookURL != "" {
parsedUrl, err := validateURL(*cfg.AuthWebhookURL)
if err != nil {
glog.Fatal("Error setting auth webhook URL ", err)
glog.Exit("Error setting auth webhook URL ", err)

Check warning on line 1033 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L1033

Added line #L1033 was not covered by tests
}
glog.Info("Using auth webhook URL ", parsedUrl.Redacted())
server.AuthWebhookURL = parsedUrl
Expand All @@ -1046,7 +1039,7 @@
if *cfg.DetectionWebhookURL != "" {
parsedUrl, err := validateURL(*cfg.DetectionWebhookURL)
if err != nil {
glog.Fatal("Error setting detection webhook URL ", err)
glog.Exit("Error setting detection webhook URL ", err)

Check warning on line 1042 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L1042

Added line #L1042 was not covered by tests
}
glog.Info("Using detection webhook URL ", parsedUrl.Redacted())
server.DetectionWebhookURL = parsedUrl
Expand Down Expand Up @@ -1086,7 +1079,7 @@
if *cfg.OrchWebhookURL != "" {
whurl, err := validateURL(*cfg.OrchWebhookURL)
if err != nil {
glog.Fatal("Error setting orch webhook URL ", err)
glog.Exit("Error setting orch webhook URL ", err)

Check warning on line 1082 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L1082

Added line #L1082 was not covered by tests
}
glog.Info("Using orchestrator webhook URL ", whurl)
n.OrchestratorPool = discovery.NewWebhookPool(bcast, whurl)
Expand Down Expand Up @@ -1125,15 +1118,15 @@
if *cfg.VerifierURL != "" {
_, err := validateURL(*cfg.VerifierURL)
if err != nil {
glog.Fatal("Error setting verifier URL ", err)
glog.Exit("Error setting verifier URL ", err)

Check warning on line 1121 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L1121

Added line #L1121 was not covered by tests
}
glog.Info("Using the Epic Labs classifier for verification at ", *cfg.VerifierURL)
server.Policy = &verification.Policy{Retries: 2, Verifier: &verification.EpicClassifier{Addr: *cfg.VerifierURL}}

// Set the verifier path. Remove once [1] is implemented!
// [1] https://github.com/livepeer/verification-classifier/issues/64
if drivers.NodeStorage == nil && *cfg.VerifierPath == "" {
glog.Fatal("Requires a path to the verifier shared volume when local storage is in use; use -verifierPath or -objectStore")
glog.Exit("Requires a path to the verifier shared volume when local storage is in use; use -verifierPath or -objectStore")

Check warning on line 1129 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L1129

Added line #L1129 was not covered by tests
}
verification.VerifierPath = *cfg.VerifierPath
} else if localVerify {
Expand All @@ -1149,14 +1142,14 @@

suri, err := getServiceURI(n, *cfg.ServiceAddr)
if err != nil {
glog.Fatal("Error getting service URI: ", err)
glog.Exit("Error getting service URI: ", err)

Check warning on line 1145 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L1145

Added line #L1145 was not covered by tests
}
n.SetServiceURI(suri)
// if http addr is not provided, listen to all ifaces
// take the port to listen to from the service URI
*cfg.HttpAddr = defaultAddr(*cfg.HttpAddr, "", n.GetServiceURI().Port())
if !*cfg.Transcoder && n.OrchSecret == "" {
glog.Fatal("Running an orchestrator requires an -orchSecret for standalone mode or -transcoder for orchestrator+transcoder mode")
glog.Exit("Running an orchestrator requires an -orchSecret for standalone mode or -transcoder for orchestrator+transcoder mode")

Check warning on line 1152 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L1152

Added line #L1152 was not covered by tests
}
} else if n.NodeType == core.TranscoderNode {
*cfg.CliAddr = defaultAddr(*cfg.CliAddr, "127.0.0.1", TranscoderCliPort)
Expand Down Expand Up @@ -1246,10 +1239,10 @@

if n.NodeType == core.TranscoderNode {
if n.OrchSecret == "" {
glog.Fatal("Missing -orchSecret")
glog.Exit("Missing -orchSecret")

Check warning on line 1242 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L1242

Added line #L1242 was not covered by tests
}
if len(orchURLs) <= 0 {
glog.Fatal("Missing -orchAddr")
glog.Exit("Missing -orchAddr")

Check warning on line 1245 in cmd/livepeer/starter/starter.go

View check run for this annotation

Codecov / codecov/patch

cmd/livepeer/starter/starter.go#L1245

Added line #L1245 was not covered by tests
}

go server.RunTranscoder(n, orchURLs[0].Host, core.MaxSessions, transcoderCaps)
Expand Down
22 changes: 11 additions & 11 deletions cmd/livepeer_bench/livepeer_bench.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@

f, err := os.Open(*in)
if err != nil {
glog.Fatal("Couldn't open input manifest: ", err)
glog.Exit("Couldn't open input manifest: ", err)
}
p, _, err := m3u8.DecodeFrom(bufio.NewReader(f), true)
if err != nil {
glog.Fatal("Couldn't decode input manifest: ", err)
glog.Exit("Couldn't decode input manifest: ", err)
}
pl, ok := p.(*m3u8.MediaPlaylist)
if !ok {
glog.Fatalf("Expecting media playlist in the input %s", *in)
glog.Exitf("Expecting media playlist in the input %s", *in)
}

accel := ffmpeg.Software
Expand All @@ -72,7 +72,7 @@
accel = ffmpeg.Nvidia
devices, err = common.ParseAccelDevices(*nvidia, accel)
if err != nil {
glog.Fatalf("Error while parsing '-nvidia %v' flag: %v", *nvidia, err)
glog.Exitf("Error while parsing '-nvidia %v' flag: %v", *nvidia, err)
}
}

Expand All @@ -81,7 +81,7 @@
accel = ffmpeg.Netint
devices, err = common.ParseAccelDevices(*netint, accel)
if err != nil {
glog.Fatalf("Error while parsing '-netint %v' flag: %v", *netint, err)
glog.Exitf("Error while parsing '-netint %v' flag: %v", *netint, err)
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@
detectorTc, err = ffmpeg.NewTranscoderWithDetector(detectionOpts.Detector, d)
end := time.Now()
if err != nil {
glog.Fatalf("Could not initialize detector profiles")
glog.Exitf("Could not initialize detector profiles")
}
fmt.Printf("InitDetectorSession time %0.4v\n", end.Sub(t).Seconds())
defer detectorTc.StopTranscoder()
Expand All @@ -170,7 +170,7 @@
end := time.Now()
fmt.Printf("InitDetectorSession time %0.4v for session %v\n", end.Sub(t).Seconds(), i)
if err != nil {
glog.Fatalf("Could not initialize detector")
glog.Exitf("Could not initialize detector")
}
} else {
tc = ffmpeg.NewTranscoder()
Expand Down Expand Up @@ -225,7 +225,7 @@
res, err := tc.Transcode(in, out)
end := time.Now()
if err != nil {
glog.Fatalf("Transcoding failed for session %d segment %d: %v", k, j, err)
glog.Exitf("Transcoding failed for session %d segment %d: %v", k, j, err)
}
if *detectionFreq > 0 && j%*detectionFreq == 0 {
fmt.Printf("%s,%d,%d,%0.4v,%0.4v,%v\n", end.Format("2006-01-02 15:04:05.9999"), k, j, v.Duration, end.Sub(t).Seconds(), res.Encoded[len(res.Encoded)-1].DetectData)
Expand All @@ -238,7 +238,7 @@
srcDur += v.Duration
segCount++
if segTxDur <= v.Duration {
realTimeSegCount += 1

Check warning on line 241 in cmd/livepeer_bench/livepeer_bench.go

View workflow job for this annotation

GitHub Actions / Run tests defined for the project

should replace realTimeSegCount += 1 with realTimeSegCount++
}
mu.Unlock()
iterEnd := time.Now()
Expand All @@ -254,7 +254,7 @@
}
wg.Wait()
if segCount == 0 || srcDur == 0.0 {
glog.Fatal("Input manifest has no segments or total duration is 0s")
glog.Exit("Input manifest has no segments or total duration is 0s")
}
statsTable := tablewriter.NewWriter(os.Stderr)
stats := [][]string{
Expand Down Expand Up @@ -285,7 +285,7 @@
var parsingError error
profiles, parsingError = ffmpeg.ParseProfiles(content)
if parsingError != nil {
glog.Fatal(parsingError)
glog.Exit(parsingError)
}
} else {
// check the built-in profiles
Expand All @@ -298,7 +298,7 @@
}
}
if len(profiles) <= 0 {
glog.Fatalf("No transcoding options provided")
glog.Exitf("No transcoding options provided")
}
}
return profiles
Expand Down
1 change: 0 additions & 1 deletion cmd/livepeer_cli/wizard_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func (w *wizard) stream() {
_, err = ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
// glog.Fatal(err)
fmt.Println(err)
return
}
Expand Down
Loading
Loading