Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Provide proper error messages when using a bad token or when curl isn…

…'t found.

Fixes issue #16
  • Loading branch information...
commit 08441ab7a46959529ba5f4810ebba37b511fc4ff 1 parent 88765d9
@bgreenlee authored
View
12 commandline.py
@@ -7,14 +7,6 @@ class BinaryNotFoundError(Exception):
pass
-class NonCleanExitError(Exception):
- def __init__(self, returncode):
- self.returncode = returncode
-
- def __str__(self):
- return repr(self.returncode)
-
-
def find_binary(name):
dirs = ['/usr/local/sbin', '/usr/local/bin', '/usr/sbin', '/usr/bin',
'/sbin', '/bin']
@@ -32,7 +24,5 @@ def execute(args):
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = proc.stdout.read()
- returncode = proc.wait()
- if returncode != 0:
- raise NonCleanExitError(returncode)
+ proc.wait()
return output
View
4 packages.json
@@ -6,11 +6,11 @@
"description": "Create and browse GitHub Gists",
"author": "Brad Greenlee",
"homepage": "http://github.com/bgreenlee/sublime-github",
- "last_modified": "2012-03-12 16:00:00",
+ "last_modified": "2012-03-14 10:09:00",
"platforms": {
"*": [
{
- "version": "2.1.3",
+ "version": "2.1.4",
"url": "https://nodeload.github.com/bgreenlee/sublime-github/zipball/master"
}
]
View
8 sublime_github.py
@@ -26,6 +26,8 @@ class BaseGitHubCommand(sublime_plugin.TextCommand):
"be stored; they are only used to generate an access token)."
ERR_UNAUTHORIZED = "Your Github username or password appears to be incorrect. "\
"Please try again."
+ ERR_UNAUTHORIZED_TOKEN = "Your Github token appears to be incorrect. Please re-enter your "\
+ "username and password to generate a new token."
def run(self, edit):
self.settings = sublime.load_settings("GitHub.sublime-settings")
@@ -105,7 +107,7 @@ def get_gists(self):
args.append(sublime.MONOSPACE_FONT)
self.view.window().show_quick_panel(*args)
except GitHubApi.UnauthorizedException:
- sublime.error_message(self.ERR_UNAUTHORIZED)
+ sublime.error_message(self.ERR_UNAUTHORIZED_TOKEN)
sublime.set_timeout(self.get_username, 50)
except GitHubApi.UnknownException, e:
sublime.error_message(e.message)
@@ -255,7 +257,7 @@ def on_done_filename(self, value):
# clear out the bad token so we can reset it
self.settings.set("github_token", "")
sublime.save_settings("GitHub.sublime-settings")
- sublime.error_message(self.ERR_UNAUTHORIZED)
+ sublime.error_message(self.ERR_UNAUTHORIZED_TOKEN)
sublime.set_timeout(self.get_username, 50)
except GitHubApi.UnknownException, e:
sublime.error_message(e.message)
@@ -301,7 +303,7 @@ def update(self):
# clear out the bad token so we can reset it
self.settings.set("github_token", "")
sublime.save_settings("GitHub.sublime-settings")
- sublime.error_message(self.ERR_UNAUTHORIZED)
+ sublime.error_message(self.ERR_UNAUTHORIZED_TOKEN)
sublime.set_timeout(self.get_username, 50)
except GitHubApi.UnknownException, e:
sublime.error_message(e.message)
View
32 sublime_requests.py
@@ -6,15 +6,13 @@
from requests.status_codes import codes
import httplib
import commandline
+import sublime
from StringIO import StringIO
from httplib import HTTPResponse
class CurlSession(object):
- class CurlException(Exception):
- pass
-
class FakeSocket(StringIO):
def makefile(self, *args, **kw):
return self
@@ -45,8 +43,13 @@ def _build_response(self, text):
return response
def request(self, method, url, headers=None, params=None, data=None, auth=None, allow_redirects=False, config=None):
- curl = commandline.find_binary('curl')
- curl_options = ['-i', '-L', '-f', '--user-agent', 'Sublime Github', '-s']
+ try:
+ curl = commandline.find_binary('curl')
+ except commandline.BinaryNotFoundError:
+ sublime.error_message("I couldn't find \"curl\" on your system. Curl is required on Linux. Please install it and try again.")
+ return
+
+ curl_options = ['-i', '-L', '--user-agent', 'Sublime Github', '-s']
if auth:
curl_options.extend(['--user', "%s:%s" % auth])
if self.verify:
@@ -63,22 +66,9 @@ def request(self, method, url, headers=None, params=None, data=None, auth=None,
command = [curl] + curl_options + [url]
- try:
- response = self._build_response(commandline.execute(command))
- response.url = url
- return response
- except commandline.NonCleanExitError, e:
- error_string = ''
- if e.returncode == 22:
- error_string = 'HTTP error 404'
- elif e.returncode == 6:
- error_string = 'URL error host not found'
- else:
- print "%s: Downloading %s timed out, trying again" % (__name__, url)
-
- raise self.CurlException("%s: %s %s %s %s" % (__name__, e, error_string, method, url))
-
- return False
+ response = self._build_response(commandline.execute(command))
+ response.url = url
+ return response
def post(self, *args, **kwargs):
return self.request("post", *args, **kwargs)
Please sign in to comment.
Something went wrong with that request. Please try again.