Skip to content

Commit

Permalink
fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
koba1t committed Aug 26, 2022
1 parent 647d667 commit b95f33c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions api/internal/plugins/fnplugin/fnplugin.go
Expand Up @@ -54,11 +54,11 @@ func resourceToRNode(res *resource.Resource) (*yaml.RNode, error) {
func GetFunctionSpec(res *resource.Resource) (*runtimeutil.FunctionSpec, error) {
rnode, err := resourceToRNode(res)
if err != nil {
return nil, fmt.Errorf("%w", err)
return nil, fmt.Errorf("could not convert resource to RNode: %w", err)
}
functionSpec, err := runtimeutil.GetFunctionSpec(rnode)
if err != nil {
return nil, fmt.Errorf("%w", err)
return nil, fmt.Errorf("failed to get FunctionSpec: %w", err)
}
return functionSpec, nil
}
Expand Down
4 changes: 2 additions & 2 deletions api/internal/plugins/loader/loader.go
Expand Up @@ -58,11 +58,11 @@ func (l *Loader) LoadGenerators(
for _, res := range rm.Resources() {
g, err := l.LoadGenerator(ldr, v, res)
if err != nil {
return nil, fmt.Errorf("%w", err)
return nil, fmt.Errorf("failed to load generator: %w", err)
}
generatorOrigin, err := resource.OriginFromCustomPlugin(res)
if err != nil {
return nil, fmt.Errorf("%w", err)
return nil, fmt.Errorf("failed to get origin from CustomPlugin: %w", err)
}
result = append(result, &resmap.GeneratorWithProperties{Generator: g, Origin: generatorOrigin})
}
Expand Down
4 changes: 2 additions & 2 deletions api/krusty/fnplugin_test.go
Expand Up @@ -737,7 +737,7 @@ generators:
fSys,
tmpDir.String())
assert.Error(t, err)
assert.Contains(t, err.Error(), "loading generator plugins: plugin RenderHelmChart."+
assert.Contains(t, err.Error(), "loading generator plugins: failed to load generator: plugin RenderHelmChart."+
"v1alpha1.[noGrp]/demo.[noNs] with mount path '/tmp/dir' is not permitted; mount paths must"+
" be relative to the current kustomization directory")
}
Expand Down Expand Up @@ -770,7 +770,7 @@ generators:
fSys,
tmpDir.String())
assert.Error(t, err)
assert.Contains(t, err.Error(), "loading generator plugins: plugin RenderHelmChart."+
assert.Contains(t, err.Error(), "loading generator plugins: failed to load generator: plugin RenderHelmChart."+
"v1alpha1.[noGrp]/demo.[noNs] with mount path './tmp/../../dir' is not permitted; mount paths must "+
"be under the current kustomization directory")
}
Expand Down
8 changes: 6 additions & 2 deletions kyaml/fn/runtime/runtimeutil/functiontypes.go
Expand Up @@ -206,9 +206,13 @@ func GetFunctionSpec(n *yaml.RNode) (*FunctionSpec, error) {
if err != nil {
return nil, nil
}
if fn, err := getFunctionSpecFromAnnotation(n, meta); err != nil {

fn, err := getFunctionSpecFromAnnotation(n, meta)
if err != nil {
return nil, err
} else if fn != nil {
}

if fn != nil {
return fn, nil
}

Expand Down
2 changes: 1 addition & 1 deletion kyaml/runfn/runfn.go
Expand Up @@ -310,7 +310,7 @@ func (r RunFns) getFunctionFilters(global bool, fns ...*yaml.RNode) (
api := fns[i]
spec, err := runtimeutil.GetFunctionSpec(api)
if err != nil {
return nil, fmt.Errorf("%w", err)
return nil, fmt.Errorf("failed to get FunctionSpec: %w", err)
}
if spec == nil {
// resource doesn't have function spec
Expand Down

0 comments on commit b95f33c

Please sign in to comment.