-
Notifications
You must be signed in to change notification settings - Fork 139
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
Add Validation check to see if func is already initialized #2574
Conversation
Welcome @tarunsunny3! It looks like this is your first PR to knative/func 🎉 |
Hi @tarunsunny3. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/ok-to-test |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2574 +/- ##
==========================================
+ Coverage 58.78% 65.38% +6.59%
==========================================
Files 130 130
Lines 15479 15485 +6
==========================================
+ Hits 9100 10125 +1025
+ Misses 5514 4385 -1129
- Partials 865 975 +110
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
cmd/build.go
Outdated
} | ||
if !hasFunc { | ||
return c, fmt.Errorf("no function has been initialized in the current directory. Please initialize a function by running either:\n- func init --language <your language>\n- func create <function name> --language <your_language>") | ||
} | ||
f, err := fn.NewFunction(c.Path) |
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.
Should not this already return ENOENT
?
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 we could simply check f.Initialized()
instead of introducing new IsFunctionInitialized()
function.
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.
TBH I am surprised that the function returns err==nil
when there is no function. Why it does that @lkingland ?
func/pkg/functions/function.go
Lines 257 to 265 in e6fa020
// If no func.yaml in directory, return the default function which will | |
// have f.Initialized() == false | |
var filename = filepath.Join(root, FunctionFile) | |
if _, err = os.Stat(filename); err != nil { | |
if os.IsNotExist(err) { | |
err = nil | |
} | |
return | |
} |
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.
@lkingland also if you mean zero-value by "default function" , then you also need to zero the path of the f.
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.
Yes, good question. A Function is first a structure in memory, which can be serialized to disk. The path to where the Function is, or will be when initialized, is the only value provided in the constructor, and thus is the only field that is populated with user data when creating a new function from scratch.
Like you say. Just check if f.Initialized()
.
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 still do not like, but can live with it. Just the function docstring says:
NewFunction from a given path. Invalid paths, or no function at path are errors.
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 bet that if you asked 10 programmers what NewFunction(pathWithNoFunction)
returns at least 9 would tell it's an 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.
Thanks @tarunsunny3 for finding out where this check needs to be!
I made a couple of suggestions to 1) use the pre-existing f.Initialzied()
method and 2) print the path of the function in the error message (it's not always in the current directory)
Thanks for the contribution.
Gentle ping @tarunsunny3 . We would love to merge your PR whenever you're ready to make those minor changes. 👍🏻 |
@lkingland Is it fine if it gives an empty output? We could just remove c.Path from the error message altogether or debug why c.Path is empty? |
/ok-to-test |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: matejvasek, tarunsunny3 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Changes
This PR addresses an issue where calling func build without prior function initialization resulted in an irrelevant error message. Now, if func build is invoked before initialization, an appropriate error is shown, guiding users to initialize the function first.
/kind bug
Fixes #2280
Release Note
Docs