hairyhenderson/gomplate

gomplate produces no result and no error

AndrewSav opened this issue · 3 comments

This is a recording of my bash session:

asavinykh@shkaf:~$ curl -sSfLo gomplate https://github.com/hairyhenderson/gomplate/releases/download/v3.11.5/gomplate_linux-amd64
asavinykh@shkaf:~$ chmod +x gomplate
asavinykh@shkaf:~$ ./gomplate -v
gomplate version 3.11.5
asavinykh@shkaf:~$ printf "templates:\n  dir: /foo/bar" > .gomplate.yaml
asavinykh@shkaf:~$ ./gomplate -f asdf -f gfklhjdfklh -f qhwfrqer -f xc
asavinykh@shkaf:~$

If .gomplate.yaml is

templates:
  dir: /foo/bar

which is consistent with the documentation.

Usually if a program cannot process input for any reason it is a good idea to produce a human readable error. That fact that it does not do it here feels like a bug to me.

Edit

This code seems to call os.Exit in a defer, it causes panics to be suppressed as noted in a comment here, which is the reason for the program to produce no output at all. Even if a panic is indicative of a bug, it is probably would be best to still let the panic produce its output, so the empty output does not confuse the user and a bit easier to troubleshoot.

panic: reflect: reflect.Value.Set using unaddressable value [recovered]
	panic: reflect: reflect.Value.Set using unaddressable value [recovered]
	panic: reflect: reflect.Value.Set using unaddressable value

goroutine 1 [running]:
github.com/hairyhenderson/yaml.handleErr(0xc0007bf2d0)
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/yaml.go:294 +0x111
panic({0x20116e0?, 0xc0006d0cf0?})
	C:/Users/admas$/scoop/apps/go/current/src/runtime/panic.go:920 +0x290
github.com/hairyhenderson/yaml.handleErr(0xc0007be4d0)
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/yaml.go:294 +0x111
panic({0x20116e0?, 0xc0006d0cf0?})
	C:/Users/admas$/scoop/apps/go/current/src/runtime/panic.go:920 +0x290
reflect.flag.mustBeAssignableSlow(0x15)
	C:/Users/admas$/scoop/apps/go/current/src/reflect/value.go:272 +0xa8
reflect.flag.mustBeAssignable(0x15)
	C:/Users/admas$/scoop/apps/go/current/src/reflect/value.go:259 +0x49
reflect.Value.Set({0x218b8a0, 0x0, 0x15}, {0x218b8a0, 0xc0006d24b0, 0x15})
	C:/Users/admas$/scoop/apps/go/current/src/reflect/value.go:2254 +0x45
github.com/hairyhenderson/yaml.(*decoder).mapping(0xc00055b9d0, 0xc000563b80, {0x218b8a0, 0x0, 0x15})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/decode.go:823 +0x4f1
github.com/hairyhenderson/yaml.(*decoder).unmarshal(0xc00055b9d0, 0xc000563b80, {0x218b8a0, 0x0, 0x15})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/decode.go:510 +0x4e5
github.com/hairyhenderson/yaml.(*Node).Decode(0xc000563b80, {0x218b8a0, 0x0})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/yaml.go:149 +0x193
github.com/hairyhenderson/gomplate/v3/internal/config.(*Templates).UnmarshalYAML(0xc00022ae08, 0xc000563b80)
	C:/Users/admas$/Documents/GitHub/gomplate/internal/config/types.go:24 +0x5b
github.com/hairyhenderson/yaml.(*decoder).callUnmarshaler(0xc00055b960, 0xc000563b80, {0x193e96df9d8, 0xc00022ae08})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/decode.go:366 +0x5f
github.com/hairyhenderson/yaml.(*decoder).prepare(0xc00055b960, 0xc000563b80, {0x2248b20, 0xc00022ae08, 0x195})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/decode.go:423 +0x3e5
github.com/hairyhenderson/yaml.(*decoder).unmarshal(0xc00055b960, 0xc000563b80, {0x2248b20, 0xc00022ae08, 0x195})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/decode.go:502 +0x334
github.com/hairyhenderson/yaml.(*decoder).mappingStruct(0xc00055b960, 0xc000563a40, {0x2528e60, 0xc00022adc0, 0x199})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/decode.go:935 +0xb85
github.com/hairyhenderson/yaml.(*decoder).mapping(0xc00055b960, 0xc000563a40, {0x2528e60, 0xc00022adc0, 0x199})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/decode.go:786 +0x53f
github.com/hairyhenderson/yaml.(*decoder).unmarshal(0xc00055b960, 0xc000563a40, {0x2528e60, 0xc00022adc0, 0x199})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/decode.go:510 +0x4e5
github.com/hairyhenderson/yaml.(*decoder).document(0xc00055b960, 0xc0005639a0, {0x2528e60, 0xc00022adc0, 0x199})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/decode.go:527 +0xab
github.com/hairyhenderson/yaml.(*decoder).unmarshal(0xc00055b960, 0xc0005639a0, {0x2528e60, 0xc00022adc0, 0x199})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/decode.go:498 +0x296
github.com/hairyhenderson/yaml.(*Decoder).Decode(0xc0006d0b70, {0x23ac240, 0xc00022adc0})
	C:/Users/admas$/go/pkg/mod/github.com/hairyhenderson/yaml@v0.0.0-20220618171115-2d35fca545ce/yaml.go:131 +0x1d6
github.com/hairyhenderson/gomplate/v3/internal/config.Parse({0x29d41a0, 0xc0006acaf0})
	C:/Users/admas$/Documents/GitHub/gomplate/internal/config/configfile.go:26 +0xc5
github.com/hairyhenderson/gomplate/v3/internal/cmd.readConfigFile(0xc00056a500)
	C:/Users/admas$/Documents/GitHub/gomplate/internal/cmd/config.go:88 +0x38b
github.com/hairyhenderson/gomplate/v3/internal/cmd.loadConfig(0xc00056a500, {0xc00069a3c0, 0x0, 0x2})
	C:/Users/admas$/Documents/GitHub/gomplate/internal/cmd/config.go:35 +0x151
github.com/hairyhenderson/gomplate/v3/internal/cmd.NewGomplateCmd.func1(0xc00056a500, {0xc00069a3c0, 0x0, 0x2})
	C:/Users/admas$/Documents/GitHub/gomplate/internal/cmd/main.go:85 +0x139
github.com/spf13/cobra.(*Command).execute(0xc00056a500, {0xc0000960d0, 0x2, 0x3})
	C:/Users/admas$/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:856 +0xac9
github.com/spf13/cobra.(*Command).ExecuteC(0xc00056a500)
	C:/Users/admas$/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:974 +0x9ce
github.com/spf13/cobra.(*Command).Execute(0xc00056a500)
	C:/Users/admas$/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:902 +0x32
github.com/spf13/cobra.(*Command).ExecuteContext(0xc00056a500, {0x29f0c58, 0xc0006d2000})
	C:/Users/admas$/go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:895 +0x73
github.com/hairyhenderson/gomplate/v3/internal/cmd.Main({0x29f0c58, 0xc0006d2000}, {0xc0000960d0, 0x2, 0x3}, {0x29d41a0, 0xc000088080}, {0x29d41c0, 0xc000088088}, {0x29d41c0, ...})
	C:/Users/admas$/Documents/GitHub/gomplate/internal/cmd/main.go:184 +0x17f
main.main()
	C:/Users/admas$/Documents/GitHub/gomplate/cmd/gomplate/main.go:22 +0x1b1

Hm.. this panic was fixed more than a year ago, how come it's not in the latest binaries?

Thanks for digging into this @AndrewSav - I'll clean things up so the panic isn't suppressed.

As to why the fix isn't in recent releases - I think that fix made it in after the 3.11.0 release, and 4.0 hasn't been released yet. Yes it's been a long time...

@hairyhenderson This is still an issue on the latest, 3.11.7, could you please re-open? Steps to reproduce are in the op, just change .5 for .7

PS. Never mind reopening, I opened a new one to track this: #2060