iandol Posted May 20, 2020 Posted May 20, 2020 I have a problem with ruby net:http library conditionally failing depending on whether the macOS system proxy is enabled or not. Currently my script just silently fails and Alfred shows the default searches. To know there was an error, one needs to go into the workflow editor debug mode. Does anyone have any tips how to handle script errors so they trigger a notification or some other method. My idea is to set an environment variable at the end of the script, and if that isn't set then Alfred's args and vars can do something conditional -- does that make sense?
Terminal Posted May 20, 2020 Posted May 20, 2020 39 minutes ago, iandol said: I have a problem with ruby net:http library conditionally failing depending on whether the macOS system proxy is enabled or not. Currently my script just silently fails and Alfred shows the default searches. To know there was an error, one needs to go into the workflow editor debug mode. Does anyone have any tips how to handle script errors so they trigger a notification or some other method. My idea is to set an environment variable at the end of the script, and if that isn't set then Alfred's args and vars can do something conditional -- does that make sense? yes it’s makes sense to hold the error in a Variable then Display it with a notification iandol 1
iandol Posted May 21, 2020 Author Posted May 21, 2020 (edited) Actually, when Ruby errors, then the workflow halts and the other Alfred options blocks do not run. I have the line that errors wrapped in an exception block: begin response = Net::HTTP.get(uri) rescue Net::ReadTimeout => e response = '' end But I see this in the debug: [07:39:35.463] ERROR: Bookends Tools[Script Filter] Code 1: /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/uri/rfc3986_parser.rb:67:in `split': bad URI(is not URI?): "127.0.0.1:16005" (URI::InvalidURIError) from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/uri/rfc3986_parser.rb:73:in `parse' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/uri/common.rb:234:in `parse' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/uri/generic.rb:1542:in `find_proxy' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:1109:in `proxy_uri' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:1096:in `proxy?' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:936:in `connect' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:930:in `do_start' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:919:in `start' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:605:in `start' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:481:in `get_response' ... And then nothing gets printed from my debug block: ALSO, I realise that I cannot change the environment variables from within Ruby, as it is a child process so it only works on copies of the ENV sent to it from Alfred. I suppose I must modify the stdout to something that can be parsed to determine an error... Edited May 21, 2020 by iandol
vitor Posted May 21, 2020 Posted May 21, 2020 Make a script filter JSON output with a single option that tells the user the option failed, and output that on the rescue. That way, instead of the Script Filter failing and the user getting the default searches, they’ll get the message in Alfred itself. In your latest example, you’re rescuing the wrong thing. You’re catching Net::ReadTimeout but the error was URI::InvalidURIError. iandol 1
iandol Posted May 21, 2020 Author Posted May 21, 2020 Hi Vitor, yes, I just realised I had a misspecification problem in my rescue block. Spitting out JSON for the error message also makes a lot more sense. Thank you!!!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now