OneDeadKey / kalamine

Keyboard Layout Maker
MIT License
103 stars 29 forks source link

Unspecified Shift effect is announced as "IndexError: list index out of range" #107

Open jidhub opened 6 months ago

jidhub commented 6 months ago

kalamine make https://github.com/jidhub/thumb-external-keyboard-layouts/blob/e3d0589ed7f980cb1c275e6d388428f2af6e863b/thumbsmodifiersv1.toml

When downloading the above link then running the kalamin make command, I obtain the stacktrace below. Specifying the shift effect as done in first change of https://github.com/jidhub/thumb-external-keyboard-layouts/commit/5676aff33a63a787f2c817d840c949ba96e38658 fixes that. See french details of how I debugged that on https://discord.com/channels/1046720208171175946/1063061534038822942/1206264367822151710

Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.11/pdb.py", line 1775, in main
    pdb._run(target)
  File "/data/data/com.termux/files/usr/lib/python3.11/pdb.py", line 1643, in _run
    self.run(target.code)
  File "/data/data/com.termux/files/usr/lib/python3.11/bdb.py", line 600, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/data/data/com.termux/files/usr/bin/kalamine", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/kalamine/cli.py", line 122, in make
    make_all(layout, Path("dist"))
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/kalamine/cli.py", line 92, in make_all
    layout.svg.write(svg_path, pretty_print=True, encoding="utf-8")
    ^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/kalamine/layout.py", line 577, in svg
    if level_num == 1 and chars[0] == chars[1].lower():
                                      ~~~~~^^^
IndexError: list index out of range
fabi1cazenave commented 6 months ago

Thanks for your bug report, I can reproduce your bug. Note that kalamine is just a keyboard layout maker. It cannot emulate mouse buttons and probably won’t ever be able to do such a thing, which is handled at a lower-level by the OS.

And if I understand correctly, your title is misleading, since you’ve fixed the base char — not the shifted char.

Unless I’ve misunderstood something, we can re-qualify this bug as something like “Better parsing error messages”. WDYT ?

jidhub commented 6 months ago

And if I understand correctly, your title is misleading, since you’ve fixed the base char — not the shifted char.

My change is actually specifying ² as a Shift value of first key, in same line than "1" "2" ..., and the relevant part of the change is:

 ┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┲━━━━━━━━━━┓
-│     │ 1 ! │ 2 > │ 3 < │ 4 $ │ 5 % │ 6 ^ │ 7 & │ 8 * │ 9 ± │ 0 ° │ ° } │ + ¦ ┃          ┃
+│ ²   │ 1 ! │ 2 > │ 3 < │ 4 $ │ 5 % │ 6 ^ │ 7 & │ 8 * │ 9 ± │ 0 ° │ ° } │ + ¦ ┃          ┃
 │ ²   │ & | │ é ~ │ " # │ ' { │ ( [ │ - | │ è ` │ _ \ │ ç ^ │ à @ │ ) ] │ = | ┃ ⌫        ┃
 ┢━━━━━┷━━┱──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┺━━┳━━━━━━━┫

I am sorry that I mixed two unrelated changes to the same commit. lClic and rClic did not prevent kalamine from ending normally (I just checked again).

“Better parsing error messages”.

I suggest: Unspecified Shift for key with "²".

fabi1cazenave commented 6 months ago

Ooohhhh thanks for the explanation. Interesting.