panic adding default value to .proto file

I’m trying to set a default, by changing

fs.FilesystemEncoderType encoder_type = 35;

to

fs.FilesystemEncoderType encoder_type = 35 [(ext.default) = "passthru"];

But I get the panic below raised here. I’ve tried all kinds of workarounds, but nothing’s worked. Any ideas why this is panicking? It appears to me I’m exactly mimicking CopyRangeMethod which works, so I’m stumped.

panic: fs.FilesystemEncoderType [recovered]
        panic: fs.FilesystemEncoderType

goroutine 1 [running]:
github.com/alecthomas/kong.catch(0xc0001cde88)
        github.com/alecthomas/kong@v0.2.17/kong.go:398 +0xa5
panic({0x13e3a00, 0x12ffcc0})
        runtime/panic.go:1038 +0x215
github.com/syncthing/syncthing/lib/util.SetDefaults({0x13d2720, 0xc000304398})
        github.com/syncthing/syncthing/lib/util/utils.go:88 +0x838
github.com/syncthing/syncthing/lib/util.SetDefaults({0x13ada80, 0xc000304398})
        github.com/syncthing/syncthing/lib/util/utils.go:92 +0x26a
github.com/syncthing/syncthing/lib/util.SetDefaults({0x13dc9a0, 0xc000304000})
        github.com/syncthing/syncthing/lib/util/utils.go:92 +0x26a
github.com/syncthing/syncthing/lib/util.SetDefaults({0x13dcc20, 0xc000304000})
        github.com/syncthing/syncthing/lib/util/utils.go:92 +0x26a
github.com/syncthing/syncthing/lib/config.ReadXML({_, _}, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...})
        github.com/syncthing/syncthing/lib/config/config.go:151 +0x65
github.com/syncthing/syncthing/lib/config.Load({0xc0000316b0, 0x30}, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...}, ...)
        github.com/syncthing/syncthing/lib/config/wrapper.go:162 +0x11a
main.loadOrDefaultConfig({0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...}, ...)
        github.com/syncthing/syncthing/cmd/syncthing/main.go:761 +0x86
main.maybeReportPanics()
        github.com/syncthing/syncthing/cmd/syncthing/monitor.go:567 +0x6a
main.monitorMain({{0x0}, 0x0, 0x0, {0x0, 0x0}, 0x0, {0x0, 0x0}, {0x0, 0x0}, ...})
        github.com/syncthing/syncthing/cmd/syncthing/monitor.go:99 +0x545
main.serveOptions.Run({{0x0}, 0x0, 0x0, {0x0, 0x0}, 0x0, {0x0, 0x0}, {0x0, 0x0}, ...})
        github.com/syncthing/syncthing/cmd/syncthing/main.go:409 +0x75d
reflect.Value.call({0x13ef6a0, 0x1db7780, 0x1d46e20}, {0x13fb22e, 0x4}, {0xc0001cdc08, 0x0, 0xc0001cdbb8})
        reflect/value.go:543 +0x814
reflect.Value.Call({0x13ef6a0, 0x1db7780, 0x10}, {0xc0001cdc08, 0x0, 0x0})
        reflect/value.go:339 +0xc5
github.com/alecthomas/kong.callMethod({0x13fac3f, 0x3}, {0x13ef6a0, 0x1db7780, 0x3}, {0x13ef6a0, 0x1db7780, 0xc675c5}, 0xc00015e500)
        github.com/alecthomas/kong@v0.2.17/callbacks.go:71 +0x4e7
github.com/alecthomas/kong.(*Context).RunNode(0xc00015cd80, 0xc00017a380, {0x0, 0x0, 0x0})
        github.com/alecthomas/kong@v0.2.17/context.go:715 +0x40b
github.com/alecthomas/kong.(*Context).Run(0x128bba0, {0x0, 0x0, 0x0})
        github.com/alecthomas/kong@v0.2.17/context.go:732 +0xa5
main.main()
        github.com/syncthing/syncthing/cmd/syncthing/main.go:260 +0x3af

goroutine 6 [chan receive]:
github.com/syncthing/notify.(*recursiveTree).dispatch(0xc0000766e0)
        github.com/syncthing/notify@v0.0.0-20210616190510-c6b7342338d2/tree_recursive.go:125 +0x4d
created by github.com/syncthing/notify.newRecursiveTree
        github.com/syncthing/notify@v0.0.0-20210616190510-c6b7342338d2/tree_recursive.go:119 +0x15b

goroutine 8 [select]:
main.(*autoclosedFile).closerLoop(0xc0002ee2a0)
        github.com/syncthing/syncthing/cmd/syncthing/monitor.go:530 +0x77
created by main.newAutoclosedFile
        github.com/syncthing/syncthing/cmd/syncthing/monitor.go:470 +0x1e7

goroutine 9 [syscall]:
os/signal.signal_recv()
        runtime/sigqueue.go:169 +0x98
os/signal.loop()
        os/signal/signal_unix.go:24 +0x19
created by os/signal.Notify.func1.1
        os/signal/signal.go:151 +0x2c

Did you copy the marshalling/unmarshalling stuff as well, with the ParseDefault method? That’s needed to convert the string to the enum.

Yes, it’s at lib/fs/encoder_types.go. Everything runs fine without the

[(ext.default) = "passthru"]

But when I add it, it panics on Linux and Windows. I haven’t tried cross-compiling yet.

You lack the ParseDefault method.

2 Likes

You’re right. I’m an idiot. I had copy/pasted from lib/fs/types.go which doesn’t have ParseDefault. I should have used lib/fs/copyrangemethod.go. Thanks for catching, and sorry for the noise.

2 Likes