Bug: Exception With --archiveName In Fabrication Toolkit
Hey guys! Let's dive into this bug report regarding the Fabrication Toolkit. The user, bennymeg, encountered an exception when trying to use the --archiveName
option via the command line. Here’s a breakdown of the issue and some insights.
Preflight Checklist
The user confirmed they searched the issue tracker and couldn't find a matching bug report. Good job on doing your homework!
- [x] I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Fabrication Toolkit Version
The version in use is 5.1.0.
KiCad Version
The KiCad version being used is 9.0.
What operating system are you using?
Ubuntu
Operating System Version
Linux 0bb2ed6b788a 6.6.87.2-microsoft-standard-WSL2
What arch are you using?
x64
Last Known Working Fabrication Toolkit version
No response
Expected Behavior
The expected behavior is that passing --archiveName
on the command line should allow specifying the archive name. For example:
python3 -m com_github_bennymeg_JLC-Plugin-for-KiCad.cli -p "G1000 partial panel.kicad_pcb" --archiveName "G1000 partial panel-JLCPCB.zip"
In theory, this command should create an archive with the specified name.
Actual Behavior
Instead, an exception occurs related to not being able to call GetTitleBlock
:
Exception in thread Thread-1:██████████████████████████████--| 97.50% Complete
Traceback (most recent call last):
File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
self.run()
File "/root/.local/share/kicad/9.0/3rdparty/plugins/com_github_bennymeg_JLC-Plugin-for-KiCad/thread.py", line 156, in run
baseName = self.expandTextVariables(self.options[ARCHIVE_NAME])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.local/share/kicad/9.0/3rdparty/plugins/com_github_bennymeg_JLC-Plugin-for-KiCad/thread.py", line 43, in expandTextVariables
titleBlock = pcbnew.GetBoard().GetTitleBlock()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'GetTitleBlock'
This traceback indicates that the GetTitleBlock
method is being called on a NoneType
object, which is causing the AttributeError
. This usually means that pcbnew.GetBoard()
is returning None
when the --archiveName
parameter is used. In other words, the board object isn't properly loaded or accessible when the archive name is specified via the command line.
The key part of this error lies in understanding when and why pcbnew.GetBoard()
might return None
. Possible reasons include:
- Board Loading Issues: The board file isn't being loaded correctly or completely before the
GetTitleBlock()
function is called. This could be due to timing issues within the plugin. - Contextual Problems: When
--archiveName
is specified, the plugin might be operating in a different context where the board isn't readily available. - KiCad API Changes: Although less likely given the version, there could be subtle changes in the KiCad API that affect how the board is accessed.
To further investigate this, you might want to:
- Check Board Existence: Ensure that the board file specified in the command line actually exists and is accessible.
- Debug Board Loading: Add debugging statements around the
pcbnew.GetBoard()
call to check when and why it might be returningNone
. - Review Thread Execution: The error occurs within a thread. Make sure the thread is correctly initialized and synchronized with the main process, particularly concerning board loading.
Additional Information
Interestingly, if the --archiveName
parameter is omitted, everything works fine. This suggests the issue is specifically triggered by the presence of this parameter. This could imply that the --archiveName
parameter is altering the execution path in such a way that the board object isn't properly initialized before GetTitleBlock()
is called. It's like ordering a pizza with a specific topping and suddenly the oven doesn't turn on!
Possible causes and solutions:
-
Parameter Handling: Double-check how the
--archiveName
parameter is parsed and handled. It might be inadvertently interfering with the board loading process. Ensure that the parsing of command-line arguments doesn't skip or alter the board loading step. -
Execution Order: Review the execution order within the plugin when
--archiveName
is used. It’s possible that some initialization steps are being skipped. Make sure the board is fully loaded and initialized before any function that depends on it is called. -
Thread Synchronization: The traceback indicates the error occurs within a thread. Ensure that the thread is correctly synchronized with the main process, especially concerning board loading. Use appropriate locking mechanisms to prevent race conditions where the thread tries to access the board before it is fully loaded.
-
Error Handling: Add more robust error handling around the
pcbnew.GetBoard()
call. If it returnsNone
, log an informative error message and handle the situation gracefully, rather than crashing. This will provide better feedback to the user and make debugging easier. -
KiCad API Compatibility: While less likely, verify that the way you're accessing the board and its title block is still compatible with KiCad 9.0. Check the KiCad API documentation for any changes that might affect this functionality.
-
Minimal Reproducible Example: Try to create a minimal, reproducible example that triggers this bug. This will help isolate the issue and make it easier to debug. Share this example with the developers so they can quickly identify and fix the bug.
-
Configuration Issues: There might be configuration issues related to how KiCad projects are set up or how the plugin is configured. Ensure that all necessary settings are correctly configured for the plugin to function properly.
In conclusion, the error seems to stem from the board object not being properly loaded when the --archiveName
parameter is used. By focusing on how the parameter affects the board loading process and ensuring proper thread synchronization, you should be able to identify and resolve this bug. Keep us updated on your progress, and let us know if you need further assistance!
For more information on KiCad scripting and debugging, you can refer to the official KiCad documentation. KiCad Documentation.