Skip to content

Commit

Permalink
Get rid of glog.fatal (#2900)
Browse files Browse the repository at this point in the history
  • Loading branch information
leszko committed Oct 26, 2023
1 parent 6b3c218 commit b954a1c
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 67 deletions.
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 @@ func main() {
ff.WithConfigFileParser(ff.PlainParser),
)
if err != nil {
glog.Fatal("Error parsing config: ", err)
glog.Exit("Error parsing config: ", err)
}

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 DefaultLivepeerConfig() LivepeerConfig {
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")
}
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")
}

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")
}

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

blockPollingTime := time.Duration(*cfg.BlockPollingInterval) * time.Second
Expand Down Expand Up @@ -476,8 +472,7 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
if *cfg.TestTranscoder {
transcoderCaps, err = core.TestTranscoderCapabilities(devices, tf)
if err != nil {
glog.Fatal(err)
return
glog.Exit(err)
}
} else {
// no capability test was run, assume default capabilities
Expand Down Expand Up @@ -585,18 +580,16 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
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")
}
}
} else {
glog.Fatal(fmt.Errorf(err.Error()))
return
glog.Exit(fmt.Errorf(err.Error()))
}

//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")
}

//Set up eth client
Expand Down Expand Up @@ -1037,7 +1030,7 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
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)
}
glog.Info("Using auth webhook URL ", parsedUrl.Redacted())
server.AuthWebhookURL = parsedUrl
Expand All @@ -1046,7 +1039,7 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
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)
}
glog.Info("Using detection webhook URL ", parsedUrl.Redacted())
server.DetectionWebhookURL = parsedUrl
Expand Down Expand Up @@ -1086,7 +1079,7 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
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)
}
glog.Info("Using orchestrator webhook URL ", whurl)
n.OrchestratorPool = discovery.NewWebhookPool(bcast, whurl)
Expand Down Expand Up @@ -1125,15 +1118,15 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {
if *cfg.VerifierURL != "" {
_, err := validateURL(*cfg.VerifierURL)
if err != nil {
glog.Fatal("Error setting verifier URL ", err)
glog.Exit("Error setting verifier URL ", err)
}
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")
}
verification.VerifierPath = *cfg.VerifierPath
} else if localVerify {
Expand All @@ -1149,14 +1142,14 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {

suri, err := getServiceURI(n, *cfg.ServiceAddr)
if err != nil {
glog.Fatal("Error getting service URI: ", err)
glog.Exit("Error getting service URI: ", err)
}
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")
}
} else if n.NodeType == core.TranscoderNode {
*cfg.CliAddr = defaultAddr(*cfg.CliAddr, "127.0.0.1", TranscoderCliPort)
Expand Down Expand Up @@ -1246,10 +1239,10 @@ func StartLivepeer(ctx context.Context, cfg LivepeerConfig) {

if n.NodeType == core.TranscoderNode {
if n.OrchSecret == "" {
glog.Fatal("Missing -orchSecret")
glog.Exit("Missing -orchSecret")
}
if len(orchURLs) <= 0 {
glog.Fatal("Missing -orchAddr")
glog.Exit("Missing -orchAddr")
}

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 @@ func main() {

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 @@ func main() {
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 @@ func main() {
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 @@ func main() {
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 @@ func main() {
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 @@ func main() {
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 Down Expand Up @@ -254,7 +254,7 @@ func main() {
}
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 @@ func parseVideoProfiles(inp string) []ffmpeg.VideoProfile {
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 @@ func parseVideoProfiles(inp string) []ffmpeg.VideoProfile {
}
}
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

0 comments on commit b954a1c

Please sign in to comment.