GothenburgBitFactory / GothenburgBitFactory/taskwarrior

simple on-modify hook blocks undoing add task / task cannot understand itself's `{}`

Open
#2,832 7 comments 1 reaction 0 assignees View on GitHub
topic:hooks
Dominant language
C++
Stars
6.1k
Forks
423
Avg merge
1d 19h
Merged PRs (30d)
11

Description

# The problem

I've recently created a hook for adding tags if the task's description is modified. In every other case, It just returns the task as it was.

All is fine except when I try to undo a previous `add` command. In such case, `on-modify` will receive two JSONs:
- the previous task: `{"description":"...", ... }`
- the new task: `{}` (an empty JSON because we are undoing add, thus removing the task)

Anyway, when the script prints the new task back to taskwarrior, the software shows me the following error and does not conclude the removal:

```
Hook Error: Expected 1 JSON task(s), found 0, in hook script: on-modify
```

## Expected behaviour

Task should understand a task JSON that it has itself written (`{}`) when the `on-modify` script gives it back to it.

## How to reproduce

Add this hook to `~/.task/hooks`:

```sh
#!/usr/bin/env sh

read old_task
read new_task

echo "$new_task"
```

Then add a task:

```sh
task add my task
```

Finally, try to undo the addition:

```sh
task undo
```

## Debugging

When using debug option (`task rc.debug.hooks=2 undo`), it shows me:

```
The last modification was made 2022-05-31

Prior Values Current Values
description my task
entry 20220531
modified 20220531
status pending
uuid 5073c990-9cbd-46bf-963b-157d42b6fcb0

The undo command is not reversible. Are you sure you want to revert to the previous state? (yes/no) yes
Timer Config::load (/home/marcosrdac/.config/task/taskrc) 0.000308 sec
Found hook script /home/marcosrdac/.config/task/hooks/on-modify
Hook: Calling /home/marcosrdac/.config/task/hooks/on-modify
Hook: input
{"description":"my task","entry":"20220601T005720Z","modified":"20220601T005720Z","status":"pending","uuid":"5073c990-9cbd-46bf-963b-157d42b6fcb0"}
{}
Hooks: args
api:2
args:task rc.debug.hooks=2 undo
command:undo
rc:/home/marcosrdac/.config/task/taskrc
data:/home/marcosrdac/dox/.h/taskwarrior
version:2.6.1
Timer Hooks::execute (/home/marcosrdac/.config/task/hooks/on-modify) 0.004553 sec
Hook: output
{}
Hook: Completed with status 0

Hook Error: Expected 1 JSON task(s), found 0, in hook script: on-modify
```

And exits with error code = 4.

## My `task diag`

```
task 2.6.1
Platform: Linux

Compiler
Version: 10.3.0
Caps: +stdc +stdc_hosted +LP64 +c8 +i32 +l64 +vp64 +time_t64
Compliance: C++17

Build Features
CMake: 3.21.2
libuuid: libuuid + uuid_unparse_lower
libgnutls: 3.7.2
Build type: Release

Configuration
File: /home/marcosrdac/.config/task/taskrc (found), 1950 bytes, mode 100644
Data: /home/marcosrdac/dox/.h/taskwarrior (found), dir, mode 40755
TASKRC: /home/marcosrdac/.config/task/taskrc
TASKDATA: /home/marcosrdac/dox/.h/taskwarrior
Locking: Enabled
GC: Enabled
$VISUAL: nvim
Server:
CA: -
Certificate: -
Key: -
Trust: strict
Ciphers: NORMAL
Creds:

Hooks
System: Enabled
Location: /home/marcosrdac/.config/task/hooks
Active: on-modify (executable)
Inactive:

Tests
Terminal: 63x44
Dups: Scanned 280 tasks for duplicate UUIDs:
No duplicates found
Broken ref: Scanned 280 tasks for broken references:
No broken references found
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.