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

Create subdirectories for state DBs if they do not exist #95

Merged
merged 1 commit into from
Feb 23, 2025

Conversation

dgruber
Copy link
Owner

@dgruber dgruber commented Feb 23, 2025

No description provided.

@dgruber dgruber merged commit 21df018 into master Feb 23, 2025
1 of 2 checks passed
@dgruber dgruber deleted the dg-db-dir-creation branch February 23, 2025 12:27
Copy link

Risk Level 3 - /home/runner/work/drmaa2os/drmaa2os/pkg/jobtracker/dockertracker/job.go

The error returned from checkJobTemplate is directly passed back without additional context. Providing more context in the error message can help in debugging and understanding the source of the error.

Suggested changes:


	if err := checkJobTemplate(jt); err != nil {
		return "", fmt.Errorf("invalid job template: %v", err)
	}

View Original Code

	if err := checkJobTemplate(jt); err != nil {
		return "", err
	}

The code can be simplified by directly assigning the boolean values to stdout and stderr based on the condition, reducing redundancy and improving readability.

Suggested changes:


	if jt.OutputPath != "" || jt.ErrorPath != "" {
		stdout := jt.OutputPath != ""
		stderr := jt.ErrorPath != ""

		handleInputOutput(cli,
			ccBody.ID,
			container.AttachOptions{Stream: true, Stdout: stdout, Stderr: stderr, Logs: true},
			jt.OutputPath,
			jt.ErrorPath)
	}

View Original Code

	if jt.OutputPath != "" || jt.ErrorPath != "" {
		stdout := false
		stderr := false

		if jt.OutputPath != "" {
			stdout = true
		}
		if jt.ErrorPath != "" {
			stderr = true
		}

		handleInputOutput(cli,
			ccBody.ID,
			container.AttachOptions{Stream: true, Stdout: stdout, Stderr: stderr, Logs: true},
			jt.OutputPath,
			jt.ErrorPath)
	}

Using panic for error handling in a goroutine is not ideal as it can crash the entire program. Instead, using log.Fatalf provides a more graceful way to handle errors by logging them and exiting the program.

Suggested changes:


	go func() {
		var err error

		var outfile *os.File
		if outfilename == "/dev/stdout" {
			outfile = os.Stdout
		} else {
			outfile, err = os.Create(outfilename)
			if err != nil {
				log.Fatalf("failed to create output file: %v", err)
			}
		}

		var errfile *os.File
		if errfilename == "/dev/stderr" {
			errfile = os.Stderr
		} else {
			errfile, err = os.Create(errfilename)
			if err != nil {
				log.Fatalf("failed to create error file: %v", err)
			}
		}
		stdcopy.StdCopy(outfile, errfile, res.Reader)
		outfile.Close()
		errfile.Close()
		res.Close()
	}()

View Original Code

	go func() {
		var err error

		var outfile *os.File
		if outfilename == "/dev/stdout" {
			outfile = os.Stdout
		} else {
			outfile, err = os.Create(outfilename)
			if err != nil {
				panic(err)
			}
		}

		var errfile *os.File
		if errfilename == "/dev/stderr" {
			errfile = os.Stderr
		} else {
			errfile, err = os.Create(errfilename)
			if err != nil {
				panic(err)
			}
		}
		stdcopy.StdCopy(outfile, errfile, res.Reader)
		outfile.Close()
		errfile.Close()
		res.Close()
	}()


Powered by Code Review GPT

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.

1 participant