MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/buildpacks / validateSource

Function validateSource

cmd/python/functions_framework/lib/lib.go:104–125  ·  view source on GitHub ↗
(ctx *gcp.Context)

Source from the content-addressed store, hash-verified

102}
103
104func validateSource(ctx *gcp.Context) error {
105 // Fail if the default|custom source file doesn't exist, otherwise the app will fail at runtime but still build here.
106 fnSource, ok := os.LookupEnv(env.FunctionSource)
107 if !ok {
108 mainPYExists, err := ctx.FileExists("main.py")
109 if err != nil {
110 return err
111 }
112 if !mainPYExists {
113 return gcp.UserErrorf("missing main.py and %s not specified. Either create the function in main.py or specify %s to point to the file that contains the function", env.FunctionSource, env.FunctionSource)
114 }
115 } else {
116 fnSourceExists, err := ctx.FileExists(fnSource)
117 if err != nil {
118 return err
119 }
120 if !fnSourceExists {
121 return gcp.UserErrorf("%s specified file %q but it does not exist", env.FunctionSource, fnSource)
122 }
123 }
124 return nil
125}

Callers 1

BuildFnFunction · 0.70

Calls 1

FileExistsMethod · 0.80

Tested by

no test coverage detected