How to use the pyang.error.add_error_code function in pyang

To help you get started, we’ve selected a few pyang examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mbj4668 / pyang / pyang / plugins / restconf.py View on Github external
statements.add_keyword_with_children(yd)
    statements.add_keywords_with_no_explicit_config(yd)

    # Register the special grammar
    for stmt, occurence, (arg, rules), add_to_stmts in restconf_stmts:
        grammar.add_stmt((restconf_module_name, stmt), (arg, rules))
        grammar.add_to_stmts_rules(add_to_stmts,
                                   [((restconf_module_name, stmt), occurence)])

    # Add validation functions
    statements.add_validation_fun('expand_2',
                                  [yd],
                                  v_yang_data)

    # Register special error codes
    error.add_error_code('RESTCONF_YANG_DATA_CHILD', 1,
                         "the 'yang-data' extension must have exactly one " +
                         "child that is a container")
github mbj4668 / pyang / pyang / plugins / lint.py View on Github external
error.add_error_code(
            'LINT_EXPLICIT_DEFAULT', 4,
            'RFC 8407: 4.4: '
            + 'statement "%s" is given with its default value "%s"')
        error.add_error_code(
            'LINT_MISSING_REQUIRED_SUBSTMT', 3,
            '%s: '
            + 'statement "%s" must have a "%s" substatement')
        error.add_error_code(
            'LINT_MISSING_RECOMMENDED_SUBSTMT', 4,
            '%s: '
            + 'statement "%s" should have a "%s" substatement')
        error.add_error_code(
            'LINT_BAD_NAMESPACE_VALUE', 4,
            'RFC 8407: 4.9: namespace value should be "%s"')
        error.add_error_code(
            'LINT_BAD_MODULENAME_PREFIX_1', 4,
            'RFC 8407: 4.1: '
            + 'the module name should start with the string %s')
        error.add_error_code(
            'LINT_BAD_MODULENAME_PREFIX_N', 4,
            'RFC 8407: 4.1: '
            + 'the module name should start with one of the strings %s')
        error.add_error_code(
            'LINT_NO_MODULENAME_PREFIX', 4,
            'RFC 8407: 4.1: '
            + 'no module name prefix string used')
        error.add_error_code(
            'LINT_BAD_REVISION', 3,
            'RFC 8407: 4.7: '
            + 'the module\'s revision %s is older than '
            + 'submodule %s\'s revision %s')
github mbj4668 / pyang / pyang / plugins / lint.py View on Github external
'RFC 8407: 4.1: '
            + 'the module name should start with one of the strings %s')
        error.add_error_code(
            'LINT_NO_MODULENAME_PREFIX', 4,
            'RFC 8407: 4.1: '
            + 'no module name prefix string used')
        error.add_error_code(
            'LINT_BAD_REVISION', 3,
            'RFC 8407: 4.7: '
            + 'the module\'s revision %s is older than '
            + 'submodule %s\'s revision %s')
        error.add_error_code(
            'LINT_TOP_MANDATORY', 3,
            'RFC 8407: 4.10: '
            + 'top-level node %s must not be mandatory')
        error.add_error_code(
            'LINT_NOT_HYPHENATED', 4,
            '%s is not hyphenated, e.g., using upper-case or underscore')

        # override std error string
        error.add_error_code(
            'LONG_IDENTIFIER', 3,
            'RFC 8407: 4.3: identifier %s exceeds %s characters')
github mbj4668 / pyang / pyang / plugins / check_update.py View on Github external
error.add_error_code(
            'CHK_LEAFREF_PATH_CHANGED', 1,
            "the leafref's path has illegally changed")
        error.add_error_code(
            'CHK_ENUM_VALUE_CHANGED', 1,
            "the value for enum '%s', has changed from %s to %s"
            + " (RFC 6020: 10, p5, bullet 1)")
        error.add_error_code(
            'CHK_BIT_POSITION_CHANGED', 1,
            "the position for bit '%s', has changed from %s to %s"
            + " (RFC 6020: 10, p5, bullet 2)")
        error.add_error_code(
            'CHK_RESTRICTION_CHANGED', 1,
            "the %s has been illegally restricted"
            + " (RFC 6020: 10, p5, bullet 3)")
        error.add_error_code(
            'CHK_UNION_TYPES', 1,
            "the member types in the union have changed")
github mbj4668 / pyang / pyang / plugins / check_update.py View on Github external
error.add_error_code(
            'CHK_NEW_WHEN', 1,
            "a new when expression cannot be added")
        error.add_error_code(
            'CHK_UNDECIDED_WHEN', 4,
            "this when expression may be different than before")
        error.add_error_code(
            'CHK_UNDECIDED_PRESENCE', 4,
            "this presence expression may be different than before")
        error.add_error_code(
            'CHK_IMPLICIT_DEFAULT', 1,
            "the leaf had an implicit default")
        error.add_error_code(
            'CHK_BASE_TYPE_CHANGED', 1,
            "the base type has illegally changed from %s to %s")
        error.add_error_code(
            'CHK_LEAFREF_PATH_CHANGED', 1,
            "the leafref's path has illegally changed")
        error.add_error_code(
            'CHK_ENUM_VALUE_CHANGED', 1,
            "the value for enum '%s', has changed from %s to %s"
            + " (RFC 6020: 10, p5, bullet 1)")
        error.add_error_code(
            'CHK_BIT_POSITION_CHANGED', 1,
            "the position for bit '%s', has changed from %s to %s"
            + " (RFC 6020: 10, p5, bullet 2)")
        error.add_error_code(
            'CHK_RESTRICTION_CHANGED', 1,
            "the %s has been illegally restricted"
            + " (RFC 6020: 10, p5, bullet 3)")
        error.add_error_code(
            'CHK_UNION_TYPES', 1,
github mbj4668 / pyang / pyang / plugins / check_update.py View on Github external
error.add_error_code(
            'CHK_DEF_REMOVED', 1,
            "the %s '%s', defined at %s is illegally removed")
        error.add_error_code(
            'CHK_DEF_ADDED', 1,
            "the %s '%s' is illegally added")
        error.add_error_code(
            'CHK_DEF_ADDED2', 1,
            "the %s '%s' is illegally added in %s %s")
        error.add_error_code(
            'CHK_DEF_CHANGED', 1,
            "the %s '%s' is illegally changed from '%s'")
        error.add_error_code(
            'CHK_INVALID_STATUS', 1,
            "new status %s is not valid since the old status was %s")
        error.add_error_code(
            'CHK_CHILD_KEYWORD_CHANGED', 1,
            "the %s '%s' is illegally changed to a %s")
        error.add_error_code(
            'CHK_MANDATORY_CONFIG', 1,
            "the node %s is changed to config true, but it is mandatory")
        error.add_error_code(
            'CHK_NEW_MANDATORY', 1,
            "the mandatory node %s is illegally added")
        error.add_error_code(
            'CHK_BAD_CONFIG', 1,
            "the node %s is changed to config false")
        error.add_error_code(
            'CHK_NEW_MUST', 1,
            "a new must expression cannot be added")
        error.add_error_code(
            'CHK_UNDECIDED_MUST', 4,
github mbj4668 / pyang / pyang / plugins / check_update.py View on Github external
'CHK_BAD_REVISION', 1,
            "new revision %s is not newer than old revision %s"
            + " (RFC 6020: 10, p2)")
        error.add_error_code(
            'CHK_DEF_REMOVED', 1,
            "the %s '%s', defined at %s is illegally removed")
        error.add_error_code(
            'CHK_DEF_ADDED', 1,
            "the %s '%s' is illegally added")
        error.add_error_code(
            'CHK_DEF_ADDED2', 1,
            "the %s '%s' is illegally added in %s %s")
        error.add_error_code(
            'CHK_DEF_CHANGED', 1,
            "the %s '%s' is illegally changed from '%s'")
        error.add_error_code(
            'CHK_INVALID_STATUS', 1,
            "new status %s is not valid since the old status was %s")
        error.add_error_code(
            'CHK_CHILD_KEYWORD_CHANGED', 1,
            "the %s '%s' is illegally changed to a %s")
        error.add_error_code(
            'CHK_MANDATORY_CONFIG', 1,
            "the node %s is changed to config true, but it is mandatory")
        error.add_error_code(
            'CHK_NEW_MANDATORY', 1,
            "the mandatory node %s is illegally added")
        error.add_error_code(
            'CHK_BAD_CONFIG', 1,
            "the node %s is changed to config false")
        error.add_error_code(
            'CHK_NEW_MUST', 1,
github mbj4668 / pyang / pyang / plugins / ietf.py View on Github external
if not ctx.opts.ietf:
            return
        self._setup_ctx(ctx)

        statements.add_validation_fun(
            'grammar', ['description'],
            lambda ctx, s: self.v_chk_description(ctx, s))

        # register our error codes
        error.add_error_code(
            'IETF_MISSING_RFC8174', 4,
            'the module seems to use RFC 2119 keywords, but the required'
            + ' text from RFC 8174 is not found'
            + ' (see pyang --ietf-help for details).')

        error.add_error_code(
            'IETF_MISSING_TRUST_LEGAL_PROVISIONING', 4,
            'RFC 8407: 3.1: '
            + 'The IETF Trust Copyright statement seems to be'
            + ' missing (see pyang --ietf-help for details).')
github mbj4668 / pyang / pyang / plugins / smi.py View on Github external
grammar.add_to_stmts_rules(add_to_stmts,
                                   [((smi_module_name, stmt), occurence)])

    # Add validation step
    statements.add_validation_phase('smi_set_oid', after='inherit_properties')
    statements.add_validation_fun('smi_set_oid',
                                  [(smi_module_name, 'oid')],
                                  v_set_oid)
    statements.add_validation_fun('smi_set_oid',
                                  [(smi_module_name, 'subid')],
                                  v_set_subid)

    # Register special error codes
    error.add_error_code('SMIv2_BAD_SUBID', 1,
                         "subid needs an oid or subid statement in an ancestor")
    error.add_error_code('SMIv2_SUBID_AND_OID', 1,
                         "subid and oid cannot be given at the same time")
github mbj4668 / pyang / pyang / plugins / check_update.py View on Github external
optparser.add_options(optlist)

        # register our error codes
        error.add_error_code(
            'CHK_INVALID_MODULENAME', 1,
            "the module's name MUST NOT be changed"
            + " (RFC 6020: 10, p3)")
        error.add_error_code(
            'CHK_INVALID_NAMESPACE', 1,
            "the module's namespace MUST NOT be changed"
            + " (RFC 6020: 10, p3)")
        error.add_error_code(
            'CHK_NO_REVISION', 1,
            "a revision statement MUST be present"
            + " (RFC 6020: 10, p2)")
        error.add_error_code(
            'CHK_BAD_REVISION', 1,
            "new revision %s is not newer than old revision %s"
            + " (RFC 6020: 10, p2)")
        error.add_error_code(
            'CHK_DEF_REMOVED', 1,
            "the %s '%s', defined at %s is illegally removed")
        error.add_error_code(
            'CHK_DEF_ADDED', 1,
            "the %s '%s' is illegally added")
        error.add_error_code(
            'CHK_DEF_ADDED2', 1,
            "the %s '%s' is illegally added in %s %s")
        error.add_error_code(
            'CHK_DEF_CHANGED', 1,
            "the %s '%s' is illegally changed from '%s'")
        error.add_error_code(