From: "Shawn O. Pearce" <spearce@spearce.org>
To: Jonas Fonseca <fonseca@diku.dk>
Cc: Robin Rosenberg <robin.rosenberg.lists@dewire.com>,
"sverre@rabbelier.nl" <sverre@rabbelier.nl>,
"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [JGIT RFC PATCH] Improve handling of parsing errors in OpenSshConfig
Date: Thu, 25 Sep 2008 08:16:32 -0700 [thread overview]
Message-ID: <20080925151632.GN3669@spearce.org> (raw)
In-Reply-To: <20080925132937.GA16151@diku.dk>
Jonas Fonseca <fonseca@diku.dk> wrote:
> Badly quoted entries are now ignored similar to how bad port number are
> currently ignored. A check for negative port numbers is now performed
> so that they also will be ignored.
>
> Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
>
> ---
> .../spearce/jgit/transport/OpenSshConfigTest.java | 46 +++++++++++++++---
> .../jgit/transport/DefaultSshSessionFactory.java | 10 +++-
> .../org/spearce/jgit/transport/OpenSshConfig.java | 51 ++++++++++++-------
> 3 files changed, 79 insertions(+), 28 deletions(-)
Well, at first glance the new OpenSshConfigException is missing
from the patch. We need that class to compile correctly. ;-)
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
> index 89beab7..123a9b5 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
> @@ -89,7 +90,12 @@
> @Override
> public synchronized Session getSession(String user, String pass,
> String host, int port) throws JSchException {
> - final OpenSshConfig.Host hc = getConfig().lookup(host);
> + final OpenSshConfig.Host hc;
> + try {
> + hc = getConfig().lookup(host);
> + } catch (OpenSshConfigException osce) {
> + throw new JSchException(osce.getMessage());
> + }
I would perfer to chain the OpenSshConfigException as the cause of
the JSchException. That way the caller has a chance to give us a
complete stack trace, including the cause of the OSCE being the
inner NumberFormatException or ParseException.
Robin or I will need to edit the EclipseSshSessionFactory to add
this same sort of try/catch. To keep the tree buildable we'll
want to squash that into your patch. Yea, sorry, this is where
the egit+jgit within one repository is going to bite us.
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java b/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java
> index b08d5c6..95a37f5 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java
> @@ -146,6 +149,10 @@ public Host lookup(final String hostName) {
> } finally {
> in.close();
> }
> + } catch (NumberFormatException nfe) {
> + throw new OpenSshConfigException("Parse error", nfe);
> + } catch (ParseException pe) {
> + throw new OpenSshConfigException("Parse error", pe);
> } catch (FileNotFoundException none) {
> hosts = Collections.emptyMap();
> } catch (IOException err) {
If we are really going to this level of effort, can we please have
the file path and line number of the invalid line in the exception?
We rarely parse the ~/.ssh/config. In general its parsed only once
during startup. Going through a bit more work at parse time to get
more accurate error messages is acceptable.
I think it may be a good idea to have the exception thrown only
when a bad Host block is accessed, or if we try to access an unknown
host and there is an unreadable Host block.
So I'm thinking more like we stuff an OSCE instance into the Host
block if the host has a bad entry, and during get() or lookup()
we test for the exception and rethrow the exception.
E.g. lets say my config file is this:
$ cat ~/.ssh/config
Host work
Hostname internal.google.com"
Port -1
Host orcz
Hostname repo.or.cz
User spearce
Port 22
then:
jgit fetch orcz:foo.git; # works without error
jgit fetch work:foo.git; # throws OSCE due to bad Hostname
jgit fetch kernel.org:foo.git; # works as no Host matched
However if my config was more bogus, e.g.:
$ cat ~/.ssh/config
Host work"
User sop
Host orcz
Hostname repo.or.cz
User spearce
Port 22
then:
jgit fetch orcz:foo.git; # still works without error
jgit fetch work:foo.git; # fails due to bad Host header
jgit fetch kernel.org:foo.git; # fails due to bad Host header
--
Shawn.
next prev parent reply other threads:[~2008-09-25 15:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-20 20:33 [JGIT PATCH] Fixed a bug that caused tabs in ~/.ssh/config to break parsing Gilion Goudsmit
2008-09-20 21:48 ` [JGIT PATCH] Add test for OpenSshConfig separator parsing Jonas Fonseca
2008-09-20 22:33 ` Jonas Fonseca
2008-09-20 22:18 ` [JGIT PATCH] Fixed a bug that caused tabs in ~/.ssh/config to break parsing Robin Rosenberg
2008-09-20 22:29 ` Jonas Fonseca
[not found] ` <bd6139dc0809201819o5d6eb5b1r7bf0e46702c711d7@mail.gmail.com>
2008-09-21 11:25 ` [JGIT PATCH] Test and fix handling of quotes in ~/.ssh/config Jonas Fonseca
2008-09-22 20:42 ` Robin Rosenberg
2008-09-22 21:07 ` Shawn O. Pearce
2008-09-24 23:25 ` Jonas Fonseca
2008-09-24 23:31 ` Shawn O. Pearce
2008-09-25 8:39 ` [JGIT PATCH] Add tests for handling of parsing errors in OpenSshConfig Jonas Fonseca
2008-09-25 11:33 ` Robin Rosenberg
2008-09-25 13:29 ` [JGIT RFC PATCH] Improve " Jonas Fonseca
2008-09-25 14:30 ` Jonas Fonseca
2008-09-25 15:16 ` Shawn O. Pearce [this message]
2008-09-25 6:26 ` [JGIT PATCH] Test and fix handling of quotes in ~/.ssh/config Robin Rosenberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080925151632.GN3669@spearce.org \
--to=spearce@spearce.org \
--cc=fonseca@diku.dk \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg.lists@dewire.com \
--cc=sverre@rabbelier.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).