Skip to content

Commit c1b9a38

Browse files
authored
fix the platform restriction error providing more educational guidance (#3062)
* fix the platform restriction error providing more educational guidance ahead Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com> * fixed the linting errors Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com> * refactor the logic based on the suggestion Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com> --------- Signed-off-by: RayyanSeliya <rayyanseliya786@gmail.com>
1 parent 8299ee9 commit c1b9a38

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

cmd/build.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ func runBuild(cmd *cobra.Command, _ []string, newClient ClientFactory) (err erro
162162
return
163163
}
164164
if err = cfg.Validate(); err != nil { // Perform any pre-validation
165+
// Layer 2: Catch platform validation error and provide CLI-specific guidance
166+
if errors.Is(err, fn.ErrPlatformNotSupported) {
167+
return fmt.Errorf(`%w
168+
169+
The --platform flag is only supported with the S2I builder.
170+
171+
Try this:
172+
func build --registry <registry> --builder=s2i --platform linux/amd64
173+
174+
Or remove the --platform flag:
175+
func build --registry <registry>
176+
177+
For more options, run 'func build --help'`, err)
178+
}
165179
return
166180
}
167181
if f, err = fn.NewFunction(cfg.Path); err != nil { // Read in the Function
@@ -364,7 +378,7 @@ func (c buildConfig) Validate() (err error) {
364378

365379
// Platform is only supported with the S2I builder at this time
366380
if c.Platform != "" && c.Builder != builders.S2I {
367-
err = errors.New("only S2I builds currently support specifying platform")
381+
err = fn.ErrPlatformNotSupported
368382
return
369383
}
370384

cmd/deploy.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,20 @@ For more detailed deployment options, run 'func deploy --help'`)
281281
return
282282
}
283283
if err = cfg.Validate(cmd); err != nil {
284+
// Layer 2: Catch platform validation error and provide CLI-specific guidance
285+
if errors.Is(err, fn.ErrPlatformNotSupported) {
286+
return fmt.Errorf(`%w
287+
288+
The --platform flag is only supported with the S2I builder.
289+
290+
Try this:
291+
func deploy --registry <registry> --builder=s2i --platform linux/amd64
292+
293+
Or remove the --platform flag:
294+
func deploy --registry <registry>
295+
296+
For more options, run 'func deploy --help'`, err)
297+
}
284298
return
285299
}
286300
if f, err = cfg.Configure(f); err != nil { // Updates f with deploy cfg

pkg/functions/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ var (
2828
// eg "registry required". Then catch the error in the CLI and add the
2929
// cli-specific usage hints there
3030
ErrRegistryRequired = errors.New("registry required to build function, please set with `--registry` or the FUNC_REGISTRY environment variable")
31+
32+
// ErrPlatformNotSupported is returned when a platform is specified for a builder that doesn't support it
33+
ErrPlatformNotSupported = errors.New("platform not supported by builder")
3134
)
3235

3336
// ErrNotInitialized indicates that a function is uninitialized

0 commit comments

Comments
 (0)