GothenburgBitFactory / taskwarrior

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

`task config` does not report an error if it cannot write to .taskrc #3611

Open echo-bravo-yahoo opened 2 months ago

echo-bravo-yahoo commented 2 months ago
~ ❯ task context define test project:personal
Are you sure you want to add 'context.test.read' with a value of 'project:personal'? (yes/no) y
Are you sure you want to add 'context.test.write' with a value of 'project:personal'? (yes/no) y
Context 'test' defined (read, write). Use 'task context test' to activate.
~ ❯ task context test
Context 'test' not found.
~ ❯ task context list | grep test
~ ❯ task context delete test
Do you want to delete context 'test'? (yes/no) y
Context 'test' not found.
~ ❯ task --version
3.1.0
~ ❯ task diag
task 3.1.0
   Platform: Darwin

Compiler
    Version: Apple LLVM 15.0.0 (clang-1500.3.9.4)
       Caps: +stdc +stdc_hosted +LP64 +c8 +i32 +l64 +vp64 +time_t64
 Compliance: C++17

Build Features
      CMake: 3.30.2
    libuuid: libuuid + uuid_unparse_lower
 Build type: Release

Configuration
       File: /Users/.../.taskrc (found), 5192 bytes, mode 100644
       Data: /Users/.../.task (found), dir, mode 40755
         GC: Enabled
    $EDITOR: nvim
Hooks
     System: Disabled
   Location: /Users/.../.task/hooks
             (-none-)

Tests
   Terminal: 416x114
 Broken ref: Scanned 2814 tasks for broken references:
             No broken references found
~ ❯ vim ~/.taskrc
~ ❯ task context list | grep manualtest
manualtest         read  project:personal                                       no
~ ❯ task context delete manualtest
Do you want to delete context 'manualtest'? (yes/no) yes
Context 'manualtest' deleted.
~ ❯ task context list | grep manualtest
~ ❯ 

I don't appear to be able to create contexts in v3.1.0 from the CLI. Some other useful information:

djmitche commented 2 months ago

I don't know much about contexts, but this does work for me. As the vim ~/.taskrc suggests, task context define just adds some lines to .taskrc. Is it not adding them, or are they not being interpreted correctly?

echo-bravo-yahoo commented 2 months ago

They were not being added (despite the command exiting successfully). I can't reproduce on this computer, will try again tonight on the other computer. I did end up making this tiny test harness, though, that might be helpful for some people to generate minimal repros:

mkdir ~/.task-debug && \
echo -e "data.location=~/.task-debug\nnews.version=3.1.0" >> ~/.taskrc-debug && \
TASKRC=~/.taskrc-debug task list
djmitche commented 2 months ago

Is the .taskrc writeable? I see a link to #3613 where .taskrc appears to be read-only, so worth asking.

If the .taskrc modification fails silently, that would be a bug!

I actually can't find any migration docs - what sent me down this rabbit hole in the first place was wanting to migrate my contexts to the newer definition style

I didn't realize there was any migration to do. What is the "older definition style"? As I said, I don't know much about contexts!

djmitche commented 2 months ago
       File: /Users/.../.taskrc (found), 5192 bytes, mode 100644

I can't figure out what that 1 means. It's not in chmod(2) on my system..

echo-bravo-yahoo commented 2 months ago

So, "old" contexts look like:

context.home=project:home

Taskwarrior appears to convert this internally to a "new" context with only its read behavior defined:

context.home.read=project:home
context.home.write=

If I wanted newly-created tasks in this context to have certain properties, I could edit it to be:

context.home.read=project:home
context.home.write=project:home priority:L

This isn't really documented anywhere I could find, so I've sort of sussed this out from interacting with it on several computers with several versions of taskwarrior.

echo-bravo-yahoo commented 2 months ago

Maybe this is a WSL/linux permission intersection issue? The computer that was not behaving well was ubuntu-in-windows; maybe @martiege has a similar setup?

djmitche commented 2 months ago

Oh, intersting --

    Version: Apple LLVM 15.0.0 (clang-1500.3.9.4)

had me assuming this was a mac..

A PR to add documentation for those formats, either to the manpages here, or to https://github.com/GothenburgBitFactory/tw.org, would be great!

echo-bravo-yahoo commented 2 months ago

Ah, sorry - I recently migrated to taskwarrior 3 on a linux computer, a WSL computer, a mac, and an android phone, and the issues I was having were either on the mac or the WSL computer, but neither are reproducible now (I just checked the WSL setup, and it's working fine) and I grabbed the logs from the mac.

This is especially perplexing because I version control my taskrc, and I rolled it backwards/forwards and couldn't get it to repro at any recent commit...

echo-bravo-yahoo commented 2 months ago

I think this issue can probably be closed for now (can't repro, can't fix, and i'm unblocked). I'll take a look at the docs site for contexts and see if I can get a PR up sometime soon. Thanks!

~/w/wildflower/valley main !2 ❯ ls -la ~/.taskrc
-rw-r--r-- 1 foo foo 5192 Aug 30 16:06 /home/foo/.taskrc
~/w/wildflower/valley main !2 ❯ chmod -w ~/.taskrc
~/w/wildflower/valley main !2 ❯ t context define test +test
Are you sure you want to add 'context.test.read' with a value of '+test'? (yes/no) y
Are you sure you want to add 'context.test.write' with a value of '+test'? (yes/no) y
Context 'test' defined (read, write). Use 'task context test' to activate.
~/w/wildflower/valley main !2 ❯ echo $?
0
~/w/wildflower/valley main !2 ❯ t context test
Context 'test' not found.
~/w/wildflower/valley main !2 ❯ chmod +w ~/.taskrc
~/w/wildflower/valley main !2 ❯ t context define test +test
Are you sure you want to add 'context.test.read' with a value of '+test'? (yes/no) y
Are you sure you want to add 'context.test.write' with a value of '+test'? (yes/no) y
Context 'test' defined (read, write). Use 'task context test' to activate.
~/w/wildflower/valley main !2 ❯ t context test
Context 'test' set. Use 'task context none' to remove.

Ok, so there definitely is a "fails silently" bug here. figured since the repro was easy enough i'd test it, and sure enough... :)

djmitche commented 2 months ago

OK, nice! I can repro that too, with the simpler task config:

⸩ chmod -w .taskrc
⸩ echo foo=bar >> .taskrc 
bash: .taskrc: Permission denied
⸩ task config foo bar
Are you sure you want to add 'foo' with a value of 'bar'? (yes/no) yes
TASKRC override: /home/dustin/p/taskwarrior/.taskrc
Config file /home/dustin/p/taskwarrior/.taskrc modified.
⸩ grep foo= .taskrc 
⸩ 

I'll mark this as a bug and add it to the backlog.

martiege commented 2 months ago

@echo-bravo-yahoo it might be related yeah, as I only seem to experience the issue when I include a symlinked and read-only file, though I'm running nixos natively and not through wsl or anything. I'll check what permissions are given, but it still seems strange to me that the behaviour seems so random.

gagankonana commented 1 month ago

I raised a PR to address silent fails on modification of the .taskrc file.

djmitche commented 1 month ago

Thanks @gagankonana.

@martiege or @echo-bravo-yahoo, do you have the capability to compile locally and verify that @gagankonana's fix has addressed the issue?