Crash seen while generating go struct.
Hi,
I am seeing below crash while running go run generator/generator.go -path=demo/getting_started/yang -output_file=test.go -package_name=test -compress_paths=true -exclude_modules=ietf-interfaces /Users/manishsahu/go/src/github.com/openconfig/ygot/demo/getting_started/yang/test.yang
goroutine 1 [running]:
github.com/openconfig/ygot/ygen.findMapPaths(0xc420268dc0, 0xc42022ab40, 0xc420270001, 0x4, 0xc4200f13c0, 0x0, 0x0, 0x2)
/Users/manishsahu/go/src/github.com/openconfig/ygot/ygen/gogen.go:1810 +0x4a5
github.com/openconfig/ygot/ygen.writeGoStruct(0xc420268dc0, 0xc42026b6b0, 0xc420268500, 0x101, 0x0, 0x0, 0x15755a5, 0x25, 0x1572058, 0x1f, ...)
/Users/manishsahu/go/src/github.com/openconfig/ygot/ygen/gogen.go:1257 +0xa5e
github.com/openconfig/ygot/ygen.(*YANGCodeGenerator).GenerateGoCode(0xc4200f1e60, 0xc4200c2060, 0x1, 0x1, 0xc420213d30, 0x1, 0x1, 0x1, 0x1013837, 0xc420270008, ...)
/Users/manishsahu/go/src/github.com/openconfig/ygot/ygen/codegen.go:343 +0x6d1
main.main()
/Users/manishsahu/go/src/github.com/openconfig/ygot/generator/generator.go:255 +0x625
My yang file(test.yang) is:
* Copyright (c) 2017 Riverbed Technology.
* All rights reserved.
*/
module test {
namespace "http://riverbed.com/sdp/yang/sdp-example";
prefix sdp-eg;
organization "RiverbedTechnology SDP";
contact "SDP Owner";
description "Sample Yang model for example service pack";
revision 2017-09-19;
container org {
list organisation {
key "name";
description "List of organisations";
leaf name {
type string;
description "Name organisation managed by SDP";
}
leaf address {
type string;
description "Street address for the organisation HQ";
}
leaf creationDate {
type string;
description "Date the organisation was created";
}
leaf status {
type string;
config false;
description "Current status of the organisation";
}
}
}
}
I was able to fix it by changing line 1804 in gogen.go from
if reflect.DeepEqual(traverseElementSchemaPath(k), fieldSlicePath) && k.Parent.Parent.Dir[k.Name].Type.Kind == yang.Yleafref {
to
if reflect.DeepEqual(traverseElementSchemaPath(k), fieldSlicePath) && k.Parent.Dir[k.Name].Type.Kind == yang.Yleafref {
Hi,
This module doesn't conform to the rules that are specified by the OpenConfig style guide -- therefore using -compress_paths will result in undefined behaviour. Please see the documentation here.
We don't currently do validation of whether the OpenConfig rules are implemented before parsing, we trust user input here -- this is something that is possible, but would need something like rewriting the OpenConfig linter in Go to achieve it - this isn't currently high priority.
Please try without compress_paths specified on the command line.
Regards, r.