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

Fix shortcuts failing #496

Merged
merged 2 commits into from
May 27, 2023
Merged

Fix shortcuts failing #496

merged 2 commits into from
May 27, 2023

Conversation

kdheepak
Copy link
Owner

@kdheepak kdheepak commented May 27, 2023

Fixes #494

@github-actions github-actions bot temporarily deployed to commit May 27, 2023 03:37 Inactive
@github-actions
Copy link
Contributor

github-actions bot commented May 27, 2023

@github-actions github-actions bot temporarily deployed to commit May 27, 2023 03:51 Inactive
@kdheepak kdheepak merged commit 4abb3bd into main May 27, 2023
@kdheepak kdheepak deleted the fix-shortcuts branch May 27, 2023 04:04
@vigilancetech-com
Copy link

vigilancetech-com commented May 27, 2023

@kdheepak still doesn't fix it for me, but changed the error.

Shortcut is definitely there and definitely executable, but for some reason taskwarrior-tui it's still saying "failed."

image

@kdheepak
Copy link
Owner Author

Are you able to run the script from the command line?

@vigilancetech-com
Copy link

yes, no problem

@vigilancetech-com
Copy link

[kevin@topsail shortcut-scripts]$ ls -la
total 8
drwxr-xr-x 1 kevin kevin  52 May 24 15:37 .
drwxr-xr-x 1 kevin kevin  32 May 24 15:10 ..
-rwxr-xr-x 1 kevin kevin 119 May 24 15:10 add-personal-tag.sh
-rwxr-xr-x 1 kevin kevin  45 May 27 15:13 test.sh
[kevin@topsail shortcut-scripts]$ pwd
/home/kevin/.config/taskwarrior-tui/shortcut-scripts
[kevin@topsail shortcut-scripts]$ 

@vigilancetech-com
Copy link

[kevin@topsail shortcut-scripts]$ ./test.sh 
[kevin@topsail shortcut-scripts]$ echo $?
0
[kevin@topsail shortcut-scripts]$ ls -lt /tmp/|head
total 508
-rw-r--r-- 1 kevin kevin     10 May 27 15:33 task.results
-rw-r--r-- 1 kevin kevin 508748 May 27 15:07 Screenshot_2023-05-27_15-07-08.png
drwx------ 3 root  root      60 May 27 14:24 systemd-private-3eab12b2482b42578bbfca91c7b260ec-geoclue.service-iLm3jX
drwx------ 2 kevin kevin     80 May 27 06:33 scoped_dircFvia5
drwx------ 2 kevin kevin     40 May 27 06:07 Temp-9b6ae0b4-a157-40ea-bcd8-c303305f01c6
drwxr-xr-x 2 kevin kevin     40 May 27 06:02 babel-stable-259
drwx------ 2 kevin kevin     40 May 27 06:02 babel-n6ymuX
srw------- 1 kevin kevin      0 May 27 06:02 insync1000.sock
drwx------ 2 kevin kevin     40 May 27 06:02 skype-1831

@vigilancetech-com
Copy link

maybe when it fails, you could make it print the errno rather than the shortcut key number?

that would probably be more valuable information

@kdheepak
Copy link
Owner Author

Weird. Two things to check

  1. the script takes a command line argument that is the UUID of the current task. When you test it from the command line are you passing this argument in?

  2. If you open the app.rs file, you’ll see a task_shortcut function. If you are interested in compiling from source, I can tell you what to add to the file to figure out what is going on.

@kdheepak
Copy link
Owner Author

It is already supposed to print stdout and stderr if it fails:

taskwarrior-tui/src/app.rs

Lines 1892 to 1905 in 1a9dedd

match output {
Ok(o) => {
if o.status.success() {
Ok(())
} else {
Err(format!(
"Unable to run shortcut {}. Status Code: {} - stdout: {} stderr: {}",
s,
o.status.code().unwrap_or_default(),
String::from_utf8_lossy(&o.stdout),
String::from_utf8_lossy(&o.stderr),
))
}
}

I think the path of the file is incorrect for some reason? What do you have in your .taskrc?

@kdheepak
Copy link
Owner Author

It's hitting one of these two error conditions:

taskwarrior-tui/src/app.rs

Lines 1905 to 1910 in 1a9dedd

}
Err(s) => Err(format!("`{}` failed: {}", shell, s)),
}
} else {
Err(format!("`{}` failed: {}", shell, s))
}

( btw I'll have update it to print different errors in the next version. )

I have to go through the rust docs again to see what the error case is for those. I think the first is it is not able to get the output of the script for some reason, which would be very weird. The second is that the script does not exist (which would match with the error code you are seeing, i.e. 2).

@kdheepak
Copy link
Owner Author

kdheepak commented May 27, 2023

You mentioned you tried this:

[kevin@topsail shortcut-scripts]$ ./test.sh 
[kevin@topsail shortcut-scripts]$ echo $?
0

Did you try test.sh f67af9...?

@vigilancetech-com
Copy link

yes, I tried passing gobbledygook to test.sh

uda.taskwarrior-tui.shortcuts.2=~/.config/taskwarrior-tui/shortcut-scripts/test.sh

I'll try to check out your source code above, but I'm not a rust programmer

@vigilancetech-com
Copy link

Also, I have two shortcuts programmed, and the error number it prints is the shortcut number, not the errno (unless it's just a coincidence that it's erroring 1 for sc 1 and 2 for sc 2)

@kdheepak
Copy link
Owner Author

There's two Err:

This one prints something related to the error:

            Err(s) => Err(format!("`{}` failed: {}", shell, s)),

This prints something incorrect I think:

          Err(format!("`{}` failed: {}", shell, s))

I'll have the change the second Err to remove the s from the formatted string.

@kdheepak
Copy link
Owner Author

kdheepak commented May 27, 2023

If you are interested in building from source, you should be able download the repo and just run cargo run to see if it works. I'd also recommend adding export TASKWARRIOR_TUI_LOG_LEVEL=debug in your current shell.

Then you can modify task_shortcut to add a debug!("any string here {}", interpolated_argument) and re-run cargo run. You'll see a debug.log taskwarrior-tui.log file in XDG's data folder.

If you add this environment variable too:

export TASKWARRIOR_TUI_DATA=`pwd`

Then the logs will go in the current working directory.

@kdheepak
Copy link
Owner Author

I'm using this package:

https://github.com/dirs-dev/dirs-rs#features

And it uses this code to get the location to put the log files in:

let data_local_dir = if let Ok(s) = std::env::var("TASKWARRIOR_TUI_DATA") {
PathBuf::from(s)
} else {
dirs::data_local_dir()
.expect("Unable to find data directory for taskwarrior-tui")
.join("taskwarrior-tui")
};

@kdheepak
Copy link
Owner Author

Also, my bad. It is not debug.log it is taskwarrior-tui.log.

@vigilancetech-com
Copy link

cat taskwarrior-tui.log 
2023-05-27 16:29:24 | DEBUG | src/main.rs:180 | getting matches from clap...
2023-05-27 16:29:24 | DEBUG | src/main.rs:181 | report = "next"
2023-05-27 16:29:24 | DEBUG | src/main.rs:182 | config = None
2023-05-27 16:29:25 | INFO | src/app.rs:1724 | Running `"task" "rc.json.array=on" "rc.confirmation=off" "rc.json.depends.array=on" "rc.color=off" "rc._forcecolor=off" "rc.report.next.filter=status:pending -WAITING limit:page" "export" "next"`
2023-05-27 16:29:25 | INFO | src/app.rs:1732 | Imported 18 tasks
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for d0a1b7dc-e5bb-4d2b-9edc-ffde5a9ef708
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for 92c38ff7-7f00-4acf-b98e-075514b1d195
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for d0339d50-71f9-4b91-9f7d-521db18fc32b
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for c818f054-88bb-4c53-8049-5a644fcbe59a
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for f67af9cd-e332-453e-b1a2-8a3eff1d1f1e
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for 4825b592-565e-4d7b-8d14-e370c7cf17b0
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for c105e937-a124-422a-a2df-518fca8ac31a
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for 9395bff4-4a6c-4c2c-803c-f0bfd0ec6f31
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for 7148ae7d-6259-461d-8206-da63faad1552
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for a8dad06b-5fe5-44be-b7fb-e5a4b78311dc
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for 61fb1143-fc23-4699-a436-77fd970369db
2023-05-27 16:29:25 | DEBUG | src/history.rs:45 | Loading history of length 1
2023-05-27 16:29:25 | DEBUG | src/history.rs:45 | Loading history of length 0
2023-05-27 16:29:25 | DEBUG | src/app.rs:422 | Tick event
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for d0a1b7dc-e5bb-4d2b-9edc-ffde5a9ef708
2023-05-27 16:29:25 | DEBUG | src/app.rs:422 | Tick event
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for d0a1b7dc-e5bb-4d2b-9edc-ffde5a9ef708
2023-05-27 16:29:25 | DEBUG | src/app.rs:422 | Tick event
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for d0a1b7dc-e5bb-4d2b-9edc-ffde5a9ef708
2023-05-27 16:29:25 | DEBUG | src/app.rs:418 | Received input = Char('2')
2023-05-27 16:29:25 | INFO | src/app.rs:1724 | Running `"task" "rc.json.array=on" "rc.confirmation=off" "rc.json.depends.array=on" "rc.color=off" "rc._forcecolor=off" "rc.report.next.filter=status:pending -WAITING limit:page" "export" "next"`
2023-05-27 16:29:25 | INFO | src/app.rs:1732 | Imported 18 tasks
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for d0a1b7dc-e5bb-4d2b-9edc-ffde5a9ef708
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for 92c38ff7-7f00-4acf-b98e-075514b1d195
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for d0339d50-71f9-4b91-9f7d-521db18fc32b
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for c818f054-88bb-4c53-8049-5a644fcbe59a
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for f67af9cd-e332-453e-b1a2-8a3eff1d1f1e
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for 4825b592-565e-4d7b-8d14-e370c7cf17b0
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for c105e937-a124-422a-a2df-518fca8ac31a
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for 9395bff4-4a6c-4c2c-803c-f0bfd0ec6f31
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for 7148ae7d-6259-461d-8206-da63faad1552
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for a8dad06b-5fe5-44be-b7fb-e5a4b78311dc
2023-05-27 16:29:25 | DEBUG | src/app.rs:1420 | Running task details for 61fb1143-fc23-4699-a436-77fd970369db
2023-05-27 16:29:26 | DEBUG | src/app.rs:422 | Tick event
2023-05-27 16:29:26 | DEBUG | src/app.rs:1420 | Running task details for d0a1b7dc-e5bb-4d2b-9edc-ffde5a9ef708
2023-05-27 16:29:26 | DEBUG | src/app.rs:422 | Tick event
2023-05-27 16:29:26 | DEBUG | src/app.rs:1420 | Running task details for d0a1b7dc-e5bb-4d2b-9edc-ffde5a9ef708
2023-05-27 16:29:26 | DEBUG | src/app.rs:418 | Received input = Char('q')
2023-05-27 16:29:26 | DEBUG | src/app.rs:422 | Tick event
2023-05-27 16:29:26 | DEBUG | src/app.rs:1420 | Running task details for d0a1b7dc-e5bb-4d2b-9edc-ffde5a9ef708
2023-05-27 16:29:27 | DEBUG | src/app.rs:422 | Tick event
2023-05-27 16:29:27 | DEBUG | src/app.rs:1420 | Running task details for d0a1b7dc-e5bb-4d2b-9edc-ffde5a9ef708
2023-05-27 16:29:27 | DEBUG | src/app.rs:422 | Tick event
2023-05-27 16:29:27 | DEBUG | src/app.rs:1420 | Running task details for d0a1b7dc-e5bb-4d2b-9edc-ffde5a9ef708
2023-05-27 16:29:27 | DEBUG | src/app.rs:422 | Tick event
2023-05-27 16:29:27 | DEBUG | src/app.rs:1420 | Running task details for d0a1b7dc-e5bb-4d2b-9edc-ffde5a9ef708
2023-05-27 16:29:27 | DEBUG | src/app.rs:418 | Received input = Char('q')
[kevin@topsail taskwarrior-tui]$ 

@kdheepak
Copy link
Owner Author

Can you add a debug!(“err 1”) and debug!(“err 2”) before the two errors?

@kdheepak
Copy link
Owner Author

Is this something you were able to look into? Maybe we should open a new issue to track it?

@huguesdevimeux
Copy link

Is this something you were able to look into? Maybe we should open a new issue to track it?

Hi, I also have the exact same issue (same issue in the first place, then shortcut failed with error 1, and same logs), and I can help if necessary.
I don't get where do you want me to place these two lines ? I'm not a rust programmer.

We can open an issue at your convenience

@kdheepak
Copy link
Owner Author

Can you try the latest main branch? No need to add any debug! calls, just show me a screenshot or tell me what error message you get?

@huguesdevimeux
Copy link

huguesdevimeux commented May 30, 2023

On lastest main, this error message now shows :
image
There is nothing new on the logs.

EDIT :
of course,

-rwxrwxrwx 1 hugues hugues 58 mai   28 17:18 /home/hugues/.config/taskwarrior-tui/shortcut-scripts/rm.sh

And

╰─ cat ~/.config/taskwarrior-tui/shortcut-scripts/rm.sh 
echo $(date) > /tmp/todelete.txt

@kdheepak
Copy link
Owner Author

Can you try the latest main again? This should give a better error message and hopefully clue us into what is going on here.

@huguesdevimeux
Copy link

image
Here you go, latest main, same settings/env/config/etc.

@kdheepak
Copy link
Owner Author

Can you try adding a #!/bin/bash to the top of your script?

@huguesdevimeux
Copy link

huguesdevimeux commented May 30, 2023

It's working now ! Interesting

@kdheepak
Copy link
Owner Author

Yay!

@kdheepak kdheepak mentioned this pull request May 30, 2023
@kdheepak
Copy link
Owner Author

I updated the documentation to reflect this. Hopefully this solves it for @vigilancetech-com too.

@huguesdevimeux
Copy link

Lovely. Thanks a lot !

@kdheepak
Copy link
Owner Author

And I made a new release with the fix.

@vigilancetech-com
Copy link

yes, it works for me now as long as it has a shebang line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shortcut keys not working
3 participants