Skip to content

MibStatus does not provide an error message for a failed compile in pysmi/compiler.py #202

@tbpower

Description

@tbpower

Expected behavior

I expected the result from the pysmi compile() function to return a failed MIB name with the "failed" message along with the error message that occurred.

Actual behavior

I received the following result:
IF-MIB: failed

The only way to see the error message is to enable debug logging.

The compile() method is only returning the string "failed" and does not include the error message that was passed to the set_options() function. The line below from compiler.py shows that an error is provided as an argument to set_options().

processed[mibname] = status_failed.set_options(error=exc)

The set_options function:

def set_options(self, **kwargs):
    n = self.__class__(self)
    for k in kwargs:
        setattr(n, k, kwargs[k])
    return n

Detailed steps

  1. Create a typo in the MIB text, e.g. setting the syntax of a variable to "auge32" rather than "Gauge32".

  2. Call the compile method in pysmi/compiler.py. I made the following call in my code to compile a single MIB, IF-MIB in my case.

    results.update(json_mib_comp.compile(*self.mibs, noDeps=True, ignoreErrors=False))

    for mib, rslt in results.items():
    print(f' {mib}: {rslt}')

  3. See result returned from compile().

I received the following result:
IF-MIB: failed

The setattr() call does not actually modify "n" and thus returns the original string "failed". Just for a quick test I replaced the setattr() call with the following, which does return the error.

n = n + ', ' + k + ': ' + kwargs[k].msg

I received the following output:
IF-MIB: failed, error: Bad grammar near token type LOWERCASE_IDENTIFIER, value auge32 at MIB IF-MIB

Python package information

pysmi 1.6.2

Operating system information

Ubuntu 24.04

Python information

Python 3.12

(Optional) Contents of your test script

Relevant log output

2025-08-27 23:25:50,060 pysmi: current MIB source(s): CallbackReader{"<function MibCmpl.cmpl_mibs.<locals>.read_callbk at 0x762926163ec0>"}
2025-08-27 23:25:50,060 pysmi: current compiled MIBs location(s): StubSearcher
2025-08-27 23:25:50,060 pysmi: trying source CallbackReader{"<function MibCmpl.cmpl_mibs.<locals>.read_callbk at 0x762926163ec0>"}
2025-08-27 23:25:50,062 pysmi: failing on  Bad grammar near token type LOWERCASE_IDENTIFIER, value auge32 at MIB IF-MIB, line 223 from CallbackReader{"<function MibCmpl.cmpl_mibs.<locals>.read_callbk at 0x762926163ec0>"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:pysmiPySMI packagebugSomething isn't workingpriority:lowLow priority items.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions