weechat-matrix
weechat-matrix copied to clipboard
Error with command 'matrix_upload'
I have the matrix_upload script set up as instructed, including having it on my path, but if I do "/upload /home/user/test.png" (test.png is a screenshot I took with scrot) in a room, I get the output "Error with command 'matrix_upload'" in the weechat buffer. I am able to use matrix_upload directly from the terminal; it just doesn't work in weechat.
I'm not sure how to get a more detailed error description. Let me know if this is needed.
Sadly you'll have to edit the source. You can add print calls here https://github.com/poljar/weechat-matrix/blob/master/matrix/uploads.py#L373. Print out the out and err variables.
I have added the following lines at that spot:
print("err:")
print(err)
print("out:")
print(out)
If I attempt to upload, I get the following output:
16:20:34 weechat | python: stdout/stderr (matrix): err:
16:20:34 weechat | python: stdout/stderr (matrix): Error with command 'matrix_upload'
16:20:34 weechat | python: stdout/stderr (matrix): out:
16:20:34 weechat | Error with command 'Error with command 'matrix_upload'
16:20:34 weechat | '
16:20:34 weechat | python: stdout/stderr (matrix): err:
16:20:34 weechat | python: stdout/stderr (matrix): out:
This doesn't seem to contain anything more detailed, although I'm not fluent in python so maybe I'm not printing these out right.
The code should be correct. Try to print out the return_code variable as well. That one should indicate an error if the other two don't show anything.
I added a print for return_code, and it looks like it gives me a -1 and a 1:
12:25:38 weechat | python: stdout/stderr (matrix): err: 12:25:38 weechat | python: stdout/stderr (matrix): Error with command 'matrix_upload' 12:25:38 weechat | python: stdout/stderr (matrix): out: 12:25:38 weechat | python: stdout/stderr (matrix): return_code: 12:25:38 weechat | python: stdout/stderr (matrix): -1 12:25:38 weechat | Error with command 'Error with command 'matrix_upload' 12:25:38 weechat | ' 12:25:38 weechat | python: stdout/stderr (matrix): err: 12:25:38 weechat | python: stdout/stderr (matrix): out: 12:25:38 weechat | python: stdout/stderr (matrix): return_code: 12:25:38 weechat | python: stdout/stderr (matrix): 1
Just a thought here, but weechat-matrix seems to be running with python2, and when I run matrix_upload from terminal, it uses python3. Would this difference in version cause any issue?
No, version difference shouldn't be a problem. It's run as a separate process using fork(). It could be written in any language as long as it's an executable.
The return codes indicate that the process successfully starts but it returns an error after that. You can try to add print statements to matrix_upload to try to figure out where and why it fails.
I have added print statements in matrix_upload to print the args passed in the upload_process function, as well as a "hello" at the top of Main. While they get printed when calling it from the terminal, I don't see them in weechat when running it from there. I'm wondering if the way it's called causes the prints to basically get lost
You might need to add flush=True
to the print call like the to_stdout function does. Or you might want to setup something a little bit more elaborate in Weechat and use to_stdout() directly.
It might be that Weechat isn't receiving anything, what OS or distro are you using?
I am on Arch Linux. I took another approach first where rather than doing print(), I wrote the output to a file. Even when this, nothing gets written to the file when run from weechat, only when I run from terminal.
I also just added to_stdout("Hello!")
to the top of the main function, and with both of these in place, still nothing. This suggests to me that weechat isn't even causing it to reach matrix_upload at all
Weird, the return codes suggest something else, but let's check where you put matrix_upload and what is in your PATH variable, maybe it indeed isn't finding it and failing to run it because of that.
I have matrix_upload in my ~/Scripts folder
, and PATH is /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:~/Scripts
I can confirm that I am able to run matrix_upload even when not in my Scripts folder
That seems to be fine, and I assume matrix_upload is marked as executable? Everything seems to be fine if it is. I don't have currently an idea why it may fail to run.
.....lol wtf. After adding more prints in uploads.py now it's.....working. I don't know what the hell I did, but I guess I accidentally fixed it? I suppose I will make copies of my matrix_upload and uploads.py, and CAREFULLY remove my prints to see if it still works after that.
Thanks for having a look!
Heisenbug strikes again? Please let me know if you find something that is obviously wrong, well besides the lackluster error reporting by the uploads code. That should be improved one day.
Still working now, so will just close this out
sigh ....it's happening again. I don't know what I did to cause it to work before, and I don't know why it's all of a sudden not working.
│14:21:31 weechat | python: stdout/stderr (matrix): err:
│14:21:31 weechat | python: stdout/stderr (matrix): Error with command 'matrix_upload'
│14:21:31 weechat | python: stdout/stderr (matrix): out:
│14:21:31 weechat | python: stdout/stderr (matrix): return_code:
│14:21:31 weechat | python: stdout/stderr (matrix): -1
|14:21:31 weechat | python: stdout/stderr (matrix): data:
│14:21:31 weechat | python: stdout/stderr (matrix): 96bbf9dc-7d87-11e9-9840-ec55f96bf47f
│14:21:31 weechat | Error with command 'Error with command 'matrix_upload'
│14:21:31 weechat | '
│14:21:31 weechat | python: stdout/stderr (matrix): err:
│14:21:31 weechat | python: stdout/stderr (matrix): out:
│14:21:31 weechat | python: stdout/stderr (matrix): return_code:
│14:21:31 weechat | python: stdout/stderr (matrix): 1
│14:21:31 weechat | python: stdout/stderr (matrix): data:
│14:21:31 weechat | python: stdout/stderr (matrix): 96bbf9dc-7d87-11e9-9840-ec55f96bf47f
Is this still a problem? There was a change to matrix_upload, the shebang now uses /usr/bin/env.
I found a typo in the matrix_upload script that may or may not be related to this issue: Upload#__iter__()
uses self.filename
(the basename) instead of self.file
(the full path) when attempting to read the file at line 85. This would result in a FlieNotFoundError.
I'll submit a pull request momentarily. But in the meantime, @BurnyBoi, does the above change resolve your issue?
Just tested the newest version of matrix_upload, and unfortunately, I am still getting "error with command matrix_upload" in weechat. It is working still when I run it directly from the terminal though. It's happening for 3 different accounts in weechat too
Okay. I think I found the problem. It seems like python isn't recognizing that ~/Scripts is part of my PATH for some reason. I tried moving matrix_upload to /usr/bin, and that seems to be working. I'm not sure how it was working at all before with this being the case, but keeping the script in /usr/bin is fine for me.
Yeah, that sounds like an environment configuration problem, and it looks like you discovered a similar workaround back in May. I wonder if there might be an issue expanding the tilde home directory notation in your PATH
... Shells can be mysterious things sometimes. Try using $HOME/Scripts
instead of ~/Scripts
in your PATH
.
Uh @BurnyBoi where did you find the instructions to set up matrix_upload and is there a concise guide anywhere at present?
Currently, trying to upload anything gives me this error:
Error with command 'Error with command 'matrix_upload'
From this issue I gather that the command has to be set up somehow? But I couldn't find instructions for it.
Putting it in your PATH
is enough, provided that the dependencies are installed. echo $PATH
can help to get a list of valid directories.
@poljar I'm not sure I follow, do I add ~/.weechat/python/matrix/uploads.py to a folder that's in my path?
No, this thing needs to be in your path. Weechat executes this script as a new process since we can't block or spawn threads and uploads might congest the single socket we have to play with.
Ah ha! now it works! also that's a cool solution, but it should def be in the readme. I'll make a pr for it when I have some time.
Have hit this today. Why isn't matrix_upload and the other files in contrib put in the users path when make install
is run?
No particular reason, expect perhaps that there isn't a sane default location unless you're root. Not sure what's best.
PR figuring this out would be welcome.