GothenburgBitFactory / taskwarrior

Taskwarrior - Command line Task Management
https://taskwarrior.org
MIT License
4.34k stars 292 forks source link

UnicodeDecodeError coming from a hook #2495

Closed Tinchops closed 3 years ago

Tinchops commented 3 years ago

tasksh 1.2.0 Platform: Linux

Compiler Version: 6.3.0 20170516 Caps: +stdc +stdc_hosted +c8 +i32 +l32 +vp32 +time_t32 Compliance: C++11

Build Features Built: Jul 2 2017 11:06:44 CMake: 3.7.2 libreadline: 7.0 Build type: None

Configuration TASKRC: TASKDATA: PATH: /home/tincho/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games Taskwarrior: /usr/local/bin/task 2.5.3 Taskwarrior: /usr/bin/task 2.5.3 Taskwarrior: /bin/task 2.5.3


Steps to reproduce it: (it also happens with other tasks without special characters.)

tasksh> add tarea con acento á. [task add tarea con acento á.] Created task 40.

tasksh> 40 start [task 40 start] Traceback (most recent call last): File "/home/tincho/.task/hooks/on-modify.timewarrior", line 60, in os.system('timew start ' + combined.decode() + ' :yes') UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 18: ordinal not in range(128) Hook Error: Expected feedback from failing hook script: on-modify.timewarrior

tasksh> 40 [task 40] No command specified - assuming 'information'.

Name Value ID 40 Description tarea con acento á. Status Pending Entered 2021-06-03 16:02:03 (12s) Last modified 2021-06-03 16:02:03 (12s) Virtual tags LATEST PENDING READY UNBLOCKED UUID 53a74bd0-efe0-4571-94a4-c4f3fd5c40f7 Urgency 0

tbabej commented 3 years ago

Hi @Tinchops ,

thanks for seeking out help here :) I think in your case the problem actually does not originate in Taskwarrior itself, but in the on-modify.timewarrior hook that you're using:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 18: ordinal not in range(128)
Hook Error: Expected feedback from failing hook script: on-modify.timewarrior

According to that traceback that you see:

Traceback (most recent call last):
  File "/home/tincho/.task/hooks/on-modify.timewarrior", line 60, in <module>
    os.system('timew start ' + combined.decode() + ' :yes')

I'd suggest explicitly specifying the encoding of the input to utf-8 explicitly. That is, I suspect replacing line 60 with:

    os.system('timew start ' + combined.decode("utf-8") + ' :yes')

should fix your problem :)

Tinchops commented 3 years ago

@tbabej Thank you for reply :D

In the on-modify.timewarrior is specified the utf-8 encoding for line 56:

56 combined = ' '.join(['"%s"' % tag for tag in tags]).encode('utf-8').strip()

Anyway I try the suggestion, with simple and double quote:

    58 # Started task.
     59 if 'start' in new and not 'start' in old:
     60     os.system('timew start ' + combined.decode("utf-8") + ' :yes')
     61
     62 # Stopped task.
     63 elif not 'start' in new and 'start' in old:
     64     os.system('timew stop ' + combined.decode("utf-8") + ' :yes')
     65
     66 # Any task that is active, with a non-pending status should not be tracked.
     67 elif 'start' in new and new['status'] != 'pending':
     68     os.system('timew stop ' + combined.decode("utf-8") + ' :yes')

The outputs are:

tasksh> 40
[task 40]
No command specified - assuming 'information'.

Name          Value
ID            40
Description   tarea con acento á.
Status        Pending
Entered       2021-06-03 20:54:39 (5s)
Last modified 2021-06-03 20:54:39 (5s)
Virtual tags  LATEST PENDING READY UNBLOCKED
UUID          c9311cc9-c562-4d3d-9a90-8ccd4ab8150e
Urgency          0

tasksh> 40 start
[task 40 start]
Traceback (most recent call last):
  File "/home/tincho/.task/hooks/on-modify.timewarrior", line 60, in <module>
    os.system('timew start ' + combined.decode('utf-8') + ' :yes')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 30: ordinal not in range(128)
tasksh> 40 start
[task 40 start]
Traceback (most recent call last):
  File "/home/tincho/.task/hooks/on-modify.timewarrior", line 60, in <module>
    os.system('timew start ' + combined.decode("utf-8") + ' :yes')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 30: ordinal not in range(128)
Hook Error: Expected feedback from failing hook script: on-modify.timewarrior
tbabej commented 3 years ago

Now that I think about it, I think this problem was actually already fixed. Would you consider updating the hook script to the latest version, available here?

See https://github.com/GothenburgBitFactory/timewarrior/issues/123 for reference.

Tinchops commented 3 years ago

@tbabej with the new version the issue is solved! Thank you!

In case it helps:

I am using the latest version of timewarrior. I downloaded source and compile.

~ $ timew --version
1.4.3

The file I used was copied from that compilation:

~ $ ls -l /usr/share/doc/timewarrior/ext/on-modify.timewarrior
-rw-r--r-- 1 root root 2443 May  6  2018 /usr/share/doc/timewarrior/ext/on-modify.timewarrior
tbabej commented 3 years ago

Hmmm, that's interesting. Did you ever install timewarrior from a package? @lauft

lauft commented 3 years ago

@tbabej Not on my machine, but it happened before that users had their bugs solved by copying the newer on-modify hook from the recently installed Timewarrior. It may be benificial not to copy the hook script but to link it instead... 🤔

Tinchops commented 3 years ago

Hmmm, that's interesting. Did you ever install timewarrior from a package? @lauft

@tbabej , yes! The first install I was made from a package, then I did the upgrade from source.

tbabej commented 3 years ago

@Tinchops That's my best guess then. I think the script path you reference, /usr/share/doc/timewarrior/ext/on-modify.timewarrior comes from the package installation and the newer version of the script ended up somewhere else, likely /usr/local/share/... Perhaps try locate on-modify.timewarrior or find /usr -type f -name 'on-modify.timewarrior', and you might find the other location :slightly_smiling_face:

Tinchops commented 3 years ago

@tbabej you are right

~ $ find /usr -type f -name 'on-modify.timewarrior'
/usr/share/doc/timewarrior/ext/on-modify.timewarrior
/usr/local/share/doc/timew/ext/on-modify.timewarrior
~ $ ls -l /usr/share/doc/timewarrior/ext/on-modify.timewarrior
-rw-r--r-- 1 root root 2443 May  6  2018 /usr/share/doc/timewarrior/ext/on-modify.timewarrior
~ $ ls -l /usr/local/share/doc/timew/ext/on-modify.timewarrior
-rw-r--r-- 1 root root 3206 May 16 07:41 /usr/local/share/doc/timew/ext/on-modify.timewarrior