Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Incorrect handling of an empty string by the safe access operator #1209

Open
3 tasks done
mexanoz opened this issue Sep 25, 2024 · 1 comment · May be fixed by #1176
Open
3 tasks done

[BUG] Incorrect handling of an empty string by the safe access operator #1209

mexanoz opened this issue Sep 25, 2024 · 1 comment · May be fixed by #1176
Labels
bug Something isn't working

Comments

@mexanoz
Copy link

mexanoz commented Sep 25, 2024

Checklist before submitting an issue

  • I have searched through the existing closed and open issues for eww and made sure this is not a duplicate
  • I have specifically verified that this bug is not a common user error
  • I am providing as much relevant information as I am able to in this bug report (Minimal config to reproduce the issue for example, if applicable)

Description of the bug

The safe access operator (?.) fails to recognize an empty string on the left side and return null (as it should according to the documentation), instead throwing an error.

Reproducing the issue

The way I encountered this issue was using a deflisten on playerctl output, which outputs a JSON string but produces an empty string when all players are shut down. Here's a minimal eww.yuck (for Wayland):

(deflisten playerctlstatus 'playerctl metadata -aFf \'{"status": "{{status}}"}\'')

(defwidget playerctl []
    (label :text {playerctlstatus?.status}))

(defwindow test
    :geometry (geometry
                  :width "100%"
                  :height "22px"
                  :anchor "bottom center")
    :exclusive true
    :stacking "fg"
    :monitor 0
    (playerctl))

When there is an active player, the label correctly contains its state. However, when the player shuts down, playerctl outputs "" and the logs show an error:

error: Failed to turn `` into a value of type json-value
  ┌─ /home/mex/.config/eww/test-bug/eww.yuck:4:19
  │
4 │     (label :text {playerctlstatus?.status}))
  │                   ───────────────

Expected behaviour

Either

  1. The operator returning a null with an empty string on the left, or
  2. The documentation explicitly stating that the operator only works with a null on the left side and not an empty string.

Additional context

No response

@mexanoz mexanoz added the bug Something isn't working label Sep 25, 2024
@w-lfchen
Copy link
Contributor

will be closed by #1176

note that the docs don't lie, they are just misleading.
currently, the empty string is not supported, a string consisting of 2 " (also referred to as an empty json string) is.

this behavior will be removed by #1176, that pr currently makes indexing "" an error, and adds support for the empty string.

@w-lfchen w-lfchen linked a pull request Sep 25, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants