Skip to content

Conversation

rash1411
Copy link
Contributor

Overview
This pull request fixes the CurrentDir function in the testutils package.
Previously, runtime.Caller(1) was incorrectly used and the ok return value was ignored, potentially causing unexpected behavior or panics.
The function now uses runtime.Caller(0) to correctly refer to its own file and includes proper error handling if the runtime information is unavailable.

Additional Information

  • This fix ensures that CurrentDir() reliably returns the directory of the file where it is defined.
  • It improves code robustness and avoids silent failures by explicitly panicking on runtime errors.

How to Test

  1. Create a small Go file that calls testutils.CurrentDir().
  2. Print the output and verify that it correctly matches the directory path of the testutils package.
  3. Optionally, simulate an environment where runtime.Caller could fail (rare but possible in very restricted environments).

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have commented on my code, particularly in hard-to-understand areas
  • I have performed a self-review of my code
  • If it is a core feature, I have added thorough tests.
  • New and existing unit tests pass locally with my changes

Fix: Correct runtime.Caller usage and handle error in CurrentDir()

- Changed runtime.Caller(1) to runtime.Caller(0) to correctly fetch the current file's directory.
- Added proper check for the 'ok' value returned by runtime.Caller.
- Improved robustness by panicking if runtime information retrieval fails.


Signed-off-by: rash1411 <107741585+rash1411@users.noreply.github.com>
@matthyx matthyx moved this to Triage in KS PRs tracking Apr 28, 2025
@matthyx matthyx moved this from Triage to Needs Reviewer in KS PRs tracking Apr 29, 2025
Copy link
Contributor

@matthyx matthyx left a comment

Choose a reason for hiding this comment

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

thanks @rash1411 !

@matthyx matthyx merged commit 2e9406d into kubescape:master Apr 29, 2025
5 checks passed
@matthyx matthyx moved this from Needs Reviewer to To Archive in KS PRs tracking May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants