| 102 | } |
| 103 | |
| 104 | func 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 | } |