Skip to content

Conversation

@touchweb-vincent
Copy link

@touchweb-vincent touchweb-vincent commented Oct 31, 2025

Hi

I added some debug output to include the content of e.context, which comes from the TextX library in Python.

Currently, we only have the line and column numbers, along with a very brief message about the expected format.

This addition should provide more context and make troubleshooting easier when exceptions occur.

@touchweb-vincent touchweb-vincent changed the title fix: add more data for data (context) fix: add more data for debug (context) Oct 31, 2025
Copy link
Contributor

@airween airween left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes themselves looks good to me, but please add some more informative description, what's the reason that you've added this PR.

@touchweb-vincent
Copy link
Author

I honestly don’t know what else to say - it’s just additional debugging. It seems to be something native to TextX, which I’m not familiar with, as I don’t know the Python ecosystem.

@airween
Copy link
Contributor

airween commented Oct 31, 2025

I honestly don’t know what else to say - it’s just additional debugging.

Then you should add that: the PR adds more information and helps debugging. And you can explain why did you think that the context is necessary.

@touchweb-vincent
Copy link
Author

You're right, I’ve updated the PR accordingly.

@airween
Copy link
Contributor

airween commented Nov 1, 2025

You're right, I’ve updated the PR accordingly.

Thanks, I think now it's fine.

But I tried your modification with a real example (I made a rule with wrong syntax and tried to parse that), and unfortunately I got this:

arpeggio.NoMatch: Expected 'accuracy:' ...

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/airween/src/secrules_parsing/src/secrules_parsing/parser.py", line 36, in process_rules
    model = modsec_mm.model_from_file(rule_file)
    ...

textx.exceptions.TextXSyntaxError: None:9:58: error: Expected 'accuracy:' ...

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/airween/src/secrules_parsing/src/secrules_parsing/cli.py", line 90, in run
    models = process_rules(args.files, args.verbose, args.debug)
  File "/home/airween/src/secrules_parsing/src/secrules_parsing/parser.py", line 43, in process_rules
    "context": e.context,
AttributeError: 'TextXSyntaxError' object has no attribute 'context'

Is there any version dependency for textx?

@touchweb-vincent
Copy link
Author

I did a standard install - I don’t remember running any exotic commands.

pip show textx

Name: textX
Version: 3.1.1
Summary: Meta-language for DSL implementation inspired by Xtext
Home-page: https://github.com/textX/textX
Author: Igor R. Dejanovic
Author-email: igor.dejanovic@gmail.com
License: MIT
Location: /.venv/lib/python3.11/site-packages
Requires: Arpeggio
Required-by: secrules-parsing

pip index versions textx

textx (4.2.3)
Available versions: 4.2.3, 4.2.2, 4.2.1, 4.2.0, 4.1.0, 4.0.1, 4.0.0, 3.1.1, 3.1.0, 3.0.0, 2.3.0, 2.2.0, 2.1.0, 2.0.1, 1.8.0, 1.7.1, 1.7.0, 1.6.1, 1.6, 1.5.2, 1.5.1, 1.5, 1.4, 1.3.1, 1.3, 1.2, 1.1.1, 1.1, 1.0, 0.4.2, 0.4.1, 0.4, 0.3.1, 0.3, 0.2.1, 0.2, 0.1.2, 0.1.1
INSTALLED: 3.1.1
LATEST: 4.2.3

Can you show me what you tested, please? I’ll probably get the same error.

@airween
Copy link
Contributor

airween commented Nov 3, 2025

I did a standard install - I don’t remember running any exotic commands.

pip show textx

Name: textX Version: 3.1.1

uhmm, it seems like I have (had) an old version:

$ pip3 show textx
Name: textX
Version: 2.3.0
...

Now I upgraded and have this one:

$ pip3 show textx
Name: textx
Version: 4.2.3
...

but the error is still exists.

Can you show me what you tested, please? I’ll probably get the same error.

Sure:

$ cat fpplug_3.conf 

SecRule TX:FALSE-POSITIVE-REPORT-PLUGIN_FILTER_IP "@gt 0" \
    "id:9525140,\
    phase:5,\
    pass,\
    t:none,t:length,\
    nolog,\
    ver:'false-positive-report-plugin/1.0.0',\
    setvar:'tx.false-positive-report-plugin_remote_addr=,%{remote_addr},',\
    skipAfter:FALSE-POSITIVE-REPORT-PLUGIN-END,\
    chain"
    SecRule TX:FALSE-POSITIVE-REPORT-PLUGIN_REMOTE_ADDR "!@within ,%{tx.false-positive-report-plugin_filter_ip}," \
        "t:none"

$ poetry run secrules-parser -c --output-type github -f fpplug_3.conf
...
Traceback (most recent call last):
  File "/home/airween/.cache/pypoetry/virtualenvs/secrules-parsing-UNC6XTUb-py3.9/lib/python3.9/site-packages/textx/model.py", line 291, in _parse
    return self.parser_model.parse(self)
...
arpeggio.NoMatch: Expected 'accuracy:' or 'block' or 'accept' or 'deny' or 'drop' or 'pass' or 'pause' or 'append' or 'auditlog' or 'capture' or 'chain' or 'ctl:' or 'deprecatevar:' or 'exec:' or 'expirevar:' or 'id:' or 'initcol:' or 'logdata:' or 'log' or 'maturity:' or 'msg:' or 'multiMatch' or 'noauditlog' or 'nolog' or 'phase:' or 'prepend:' or 'proxy:' or 'redirect:' or 'rev:' or 'sanitiseArg:' or 'sanitiseMatched' or 'sanitiseMatchedBytes:' or 'sanitiseRequestHeader:' or 'sanitiseResponseHeader:' or 'severity:' or 'setuid:' or 'setrsc:' or 'setsid:' or 'setenv:' or 'setvar:' or 'skip:' or 'skipAfter:' or 'status:' or 't:' or 'tag:'' or 'ver:'' or 'xmlns:' at position /home/airween/src/secrules_parsing/fpplug_3.conf:(9, 58) => 'ote_addr=,*%{remote_a'.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/airween/src/secrules_parsing/src/secrules_parsing/parser.py", line 36, in process_rules
    model = modsec_mm.model_from_file(rule_file)
...
textx.exceptions.TextXSyntaxError: None:9:58: error: Expected 'accuracy:' or 'block' or 'accept' or 'deny' or 'drop' or 'pass' or 'pause' or 'append' or 'auditlog' or 'capture' or 'chain' or 'ctl:' or 'deprecatevar:' or 'exec:' or 'expirevar:' or 'id:' or 'initcol:' or 'logdata:' or 'log' or 'maturity:' or 'msg:' or 'multiMatch' or 'noauditlog' or 'nolog' or 'phase:' or 'prepend:' or 'proxy:' or 'redirect:' or 'rev:' or 'sanitiseArg:' or 'sanitiseMatched' or 'sanitiseMatchedBytes:' or 'sanitiseRequestHeader:' or 'sanitiseResponseHeader:' or 'severity:' or 'setuid:' or 'setrsc:' or 'setsid:' or 'setenv:' or 'setvar:' or 'skip:' or 'skipAfter:' or 'status:' or 't:' or 'tag:'' or 'ver:'' or 'xmlns:' at position /home/airween/src/secrules_parsing/fpplug_3.conf:(9, 58) => 'ote_addr=,*%{remote_a'.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/airween/src/secrules_parsing/src/secrules_parsing/cli.py", line 90, in run
    models = process_rules(args.files, args.verbose, args.debug)
  File "/home/airween/src/secrules_parsing/src/secrules_parsing/parser.py", line 43, in process_rules
    "context": e.context,
AttributeError: 'TextXSyntaxError' object has no attribute 'context'

Note, that the file what I want to parse is wrong on purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants