bennymeg / Fabrication-Toolkit

An JLC PCB Fabrication Plugin for KiCad
Apache License 2.0
307 stars 53 forks source link

[Bug]: string index out of range when compoenent has layer override #171

Open bleroy opened 2 weeks ago

bleroy commented 2 weeks ago

Preflight Checklist

Fabrication Toolkit Version

4.4.1

What operating system are you using?

Windows

Operating System Version

Windows 11

What arch are you using?

x64

Last Known Working Fabrication Toolkit version

No response

Expected Behavior

The plugin should generate files without errors.

Actual Behavior

The generation stops with a "string index out of range" error.

Additional Information

I've tracked it down to the _get_top_or_bottom_side_override_from_footprint method, which assumes temp_layer is not empty. This is easily fixed (this worked and unblocked me):

    def _get_top_or_bottom_side_override_from_footprint(self, footprint) -> str:
        keys = ['JLCPCB Layer Override']
        fallback_keys = ['JlcLayerOverride', 'JLCLayerOverride']

        layer = {
            pcbnew.F_Cu: 'top',
            pcbnew.B_Cu: 'bottom',
        }.get(footprint.GetLayer())

        for key in keys + fallback_keys:
            if footprint_has_field(footprint, key):
                temp_layer = footprint_get_field(footprint, key)
                if len(temp_layer) > 0:
                    if (temp_layer[0] == 'b' or temp_layer[0] == 'B'):
                        layer = "bottom"
                        break
                    elif (temp_layer[0] == 't' or temp_layer[0] == 'T'):
                        layer = "top"
                        break

        return layer