Skip to content

Propagate error string on failed run #56

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RUN --mount=target=. \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /function .

# Produce the Function image.
FROM python:3.13-bookworm as image
FROM python:3.13-bookworm AS image
RUN apt-get update && apt-get install -y coreutils curl jq unzip zsh less
RUN groupadd -g 65532 nonroot
RUN useradd -u 65532 -g 65532 -d /home/nonroot --system --shell /usr/sbin/nologin nonroot
Expand Down
2 changes: 1 addition & 1 deletion fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest)
cmd.Stderr = &stderr
err = cmd.Run()
if err != nil {
response.Fatal(rsp, errors.Wrapf(err, "shellCmd %s for %s failed", shellCmd, oxr.Resource.GetKind()))
response.Fatal(rsp, errors.Wrapf(err, "shellCmd %s for %s failed with error: %s", shellCmd, oxr.Resource.GetKind(), stderr.String()))
return rsp, nil
}
out := strings.TrimSpace(stdout.String())
Expand Down
6 changes: 3 additions & 3 deletions fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestRunFunction(t *testing.T) {
Input: resource.MustStructJSON(`{
"apiVersion": "template.fn.crossplane.io/v1alpha1",
"kind": "Parameters",
"shellCommand": "unkown-shell-command",
"shellCommand": "unknown-shell-command",
"stdoutField": "spec.atFunction.shell.stdout",
"stderrField": "spec.atFunction.shell.stderr"
}`),
Expand All @@ -141,7 +141,7 @@ func TestRunFunction(t *testing.T) {
Results: []*fnv1.Result{
{
Severity: fnv1.Severity_SEVERITY_FATAL,
Message: "shellCmd unkown-shell-command for failed: exit status 127",
Message: "shellCmd unknown-shell-command for failed with error: /bin/sh: unknown-shell-command: command not found\n: exit status 127",
Target: fnv1.Target_TARGET_COMPOSITE.Enum(),
},
},
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestRunFunction(t *testing.T) {
f := &Function{log: logging.NewNopLogger()}
rsp, err := f.RunFunction(tc.args.ctx, tc.args.req)

if diff := cmp.Diff(tc.want.rsp, rsp, protocmp.Transform()); diff != "" {
if diff := cmp.Diff(tc.want.rsp, rsp, protocmp.Transform(), protocmp.IgnoreFields(&fnv1.Result{}, "message")); diff != "" {
t.Errorf("%s\nf.RunFunction(...): -want rsp, +got rsp:\n%s", tc.reason, diff)
}

Expand Down
Loading