Skip to content

AttributeError: 'NoneType' object has no attribute 'groups' on 2-axis machines #134

Description

@leone2805

Describe the bug
The plugin crashes when receiving status reports from a 2-axis GRBL machine (e.g., Laser engraver). The regex in _bgs.py expects at least 3 coordinates (X, Y, Z), but since my machine only reports X and Y, the regex match fails and returns None, causing an AttributeError.

Traceback

2026-05-02 15:00:22,385 - octoprint.util.comm - ERROR - Error while processing hook bettergrblsupport:
Traceback (most recent call last):
  File "/octoprint/plugins/lib/python3.10/site-packages/octoprint/util/comm.py", line 4218, in _readline
    ret = hook(self, ret)
  File "/octoprint/plugins/lib/python3.10/site-packages/octoprint/util/__init__.py", line 1692, in wrapper
    return f(*args, **kwargs)
  File "/octoprint/plugins/lib/python3.10/site-packages/octoprint_bettergrblsupport/__init__.py", line 1112, in hook_gcode_received
    return _bgs.process_grbl_status_msg(self, line)
  File "/octoprint/plugins/lib/python3.10/site-packages/octoprint_bettergrblsupport/_bgs.py", line 598, in process_grbl_status_msg
    response = 'X:{1} Y:{2} Z:{3} E:0 {original}'.format(*match.groups(), original=msg)
AttributeError: 'NoneType' object has no attribute 'groups'

Serial Logs
Here is the raw data being sent by my controller:

Send: ?
Recv: <Idle|MPos:0.000,0.000|FS:0,0|WCO:0.000,0.000>
Recv: ok

Proposed Fix
The regex in process_grbl_status_msg should be updated to make the Z-axis (and additional axes) optional, and the formatting logic should check if match is not None before accessing .groups().

def process_grbl_status_msg(_plugin, msg):
    # This regex makes the 3rd, 4th, 5th, and 6th axes optional
    match = re.search(r'<(-?[^,]+)[,|][WM]Pos:(-?[\d\.]+),(-?[\d\.]+)(?:,(-?[\d\.]+))?(?:,(-?[\d\.]+))?(?:,(-?[\d\.]+))?', msg)
    groups = match.groups()
    # Fallback to 0.000 if Z (groups[3]) is missing
    x = groups[1]
    y = groups[2]
    z = groups[3] if groups[3] is not None else "0.000"
    response = 'X:{0} Y:{1} Z:{2} E:0 {original}'.format(x, y, z, original=msg)
   ....

Version
Better Grbl Support (2.3.2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions