freeconf / yang

Standards-based management for Golang microservices
Apache License 2.0
38 stars 15 forks source link

Panic in freeconf/yang library if two leaf nodes has the same name. #73

Closed davidmat50 closed 1 year ago

davidmat50 commented 1 year ago

If there is duplication of leaf nodes , then an user-friendly error should be thrown to indicate the invalid configuration in yang. But It panics.

github.com/freeconf/yang/meta.(*Container).indexDataDefinition(0xc0000c0900, {0x4eb520?, 0xc0005148c0})
        C:/Users/dama0416/go/pkg/mod/github.com/freeconf/yang@v0.0.0-20230802104523-19bdb306a0c9/meta/core_gen.go:658 +0x1bd      
github.com/freeconf/yang/meta.(*Container).addDataDefinition(0xc0000c0900, {0x4eb520?, 0xc0005148c0?})
        C:/Users/dama0416/go/pkg/mod/github.com/freeconf/yang@v0.0.0-20230802104523-19bdb306a0c9/meta/core_gen.go:648 +0xba       
github.com/freeconf/yang/meta.(*Builder).Leaf(0x4e9e78?, {0x44cb80, 0xc0000c0900}, {0xc00054e118, 0x9})
        C:/Users/dama0416/go/pkg/mod/github.com/freeconf/yang@v0.0.0-20230802104523-19bdb306a0c9/meta/builder.go:508 +0x162       
github.com/freeconf/yang/parser.(*yyParserImpl).Parse(0xc00000c580, {0x4e9e78?, 0xc000518b40?})
        parser.y:1331 +0x6416
github.com/freeconf/yang/parser.yyParse(...)
        yaccpar:153
github.com/freeconf/yang/parser.(*parser).parseModule(0x4e9600?, {0xc00054e000?, 0x173?}, 0x0, {0x4e9e50?, 0xc0001538c0}, 0xc000491a88?)
        C:/Users/dama0416/go/pkg/mod/github.com/freeconf/yang@v0.0.0-20230802104523-19bdb306a0c9/parser/loader.go:80 +0x105       
github.com/freeconf/yang/parser.(*parser).loadAndParseModule(0xc00051e060, 0x20?, {0xc00001a200, 0x19}, {0xc000491b00?, 0x3a954f?}, {0x4e9e50, 0xc0001538c0}, 0xc000491b68?)
        C:/Users/dama0416/go/pkg/mod/github.com/freeconf/yang@v0.0.0-20230802104523-19bdb306a0c9/parser/loader.go:110 +0x285      
github.com/freeconf/yang/parser.LoadModuleWithOptions(0xc000522580, {0xc00001a200, 0x19}, {{0x0?, 0x0?}, {0x0?, 0xc000491c60?}})
        C:/Users/dama0416/go/pkg/mod/github.com/freeconf/yang@v0.0.0-20230802104523-19bdb306a0c9/parser/loader.go:68 +0x13e       
github.com/freeconf/yang/parser.LoadModule(...)
.
.
.
.
.

File used:

module check_similar_identifiers {

    namespace "urn:params:check_similar_identifiers";
    prefix check_similar_identifiers;
    yang-version 1.1;

    container root-container {
        leaf leaf-root {
            type enumeration {
                enum "one";
                enum "two";
            }
        }
        leaf leaf-root {
            type enumeration {
                enum "three";
                enum "four";
            }
        }
    }
}
dhubler commented 1 year ago

fixed