Mercurial > jhg
changeset 394:f52ca9530774 v0.8.0
Resolve FIXMEs: more consistent exceptions
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 22 Feb 2012 03:10:55 +0100 |
parents | 728708de3597 |
children | 4732fffff58a |
files | src/org/tmatesoft/hg/core/HgCallbackTargetException.java src/org/tmatesoft/hg/core/HgException.java src/org/tmatesoft/hg/core/HgInvalidControlFileException.java src/org/tmatesoft/hg/core/HgInvalidFileException.java src/org/tmatesoft/hg/internal/RevlogDump.java src/org/tmatesoft/hg/repo/Revlog.java |
diffstat | 6 files changed, 56 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/HgCallbackTargetException.java Tue Feb 21 19:18:40 2012 +0100 +++ b/src/org/tmatesoft/hg/core/HgCallbackTargetException.java Wed Feb 22 03:10:55 2012 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 TMate Software Ltd + * Copyright (c) 2011-2012 TMate Software Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ * {@link RuntimeException} subclass, {@link Wrap}. Then, unwrap and re-throw with checked {@link HgCallbackTargetException}. * * FIXME REVISIT perhaps, shall just throw HgCallbackTargetException from any handler, and do not catch anything in commands at all? + * FIXME decide whether shall root at HgException ("throws HgException, HgCallbackTargetException" looks a bit odd now) * * @author Artem Tikhomirov * @author TMate Software Ltd.
--- a/src/org/tmatesoft/hg/core/HgException.java Tue Feb 21 19:18:40 2012 +0100 +++ b/src/org/tmatesoft/hg/core/HgException.java Wed Feb 22 03:10:55 2012 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 TMate Software Ltd + * Copyright (c) 2011-2012 TMate Software Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -101,7 +101,7 @@ protected void appendDetails(StringBuilder sb) { if (filename != null) { - sb.append("file:'"); + sb.append("path:'"); sb.append(filename); sb.append('\''); sb.append(';');
--- a/src/org/tmatesoft/hg/core/HgInvalidControlFileException.java Tue Feb 21 19:18:40 2012 +0100 +++ b/src/org/tmatesoft/hg/core/HgInvalidControlFileException.java Wed Feb 22 03:10:55 2012 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 TMate Software Ltd + * Copyright (c) 2011-2012 TMate Software Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ * @author TMate Software Ltd. */ @SuppressWarnings("serial") -@Experimental(reason="WORK IN PROGRESS. Name is likely to change. Path argument to be added?") +@Experimental(reason="WORK IN PROGRESS. Name is likely to change") public class HgInvalidControlFileException extends HgInvalidFileException { public HgInvalidControlFileException(String message, Throwable th, File file) { @@ -47,4 +47,10 @@ super.setRevision(r); return this; } + + @Override + public HgException setRevisionIndex(int rev) { + super.setRevisionIndex(rev); + return this; + } }
--- a/src/org/tmatesoft/hg/core/HgInvalidFileException.java Tue Feb 21 19:18:40 2012 +0100 +++ b/src/org/tmatesoft/hg/core/HgInvalidFileException.java Wed Feb 22 03:10:55 2012 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 TMate Software Ltd + * Copyright (c) 2011-2012 TMate Software Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -44,11 +44,11 @@ public HgInvalidFileException(String message, Throwable th, File file) { super(message, th); - localFile = file; + localFile = file; // allows null } public HgInvalidFileException setFile(File file) { - assert file != null; + assert file != null; // doesn't allow null not to clear file accidentally localFile = file; return this; }
--- a/src/org/tmatesoft/hg/internal/RevlogDump.java Tue Feb 21 19:18:40 2012 +0100 +++ b/src/org/tmatesoft/hg/internal/RevlogDump.java Wed Feb 22 03:10:55 2012 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2011 TMate Software Ltd + * Copyright (c) 2010-2012 TMate Software Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
--- a/src/org/tmatesoft/hg/repo/Revlog.java Tue Feb 21 19:18:40 2012 +0100 +++ b/src/org/tmatesoft/hg/repo/Revlog.java Wed Feb 22 03:10:55 2012 +0100 @@ -177,25 +177,54 @@ } /** - * Access to revision data as is (decompressed, but otherwise unprocessed, i.e. not parsed for e.g. changeset or manifest entries) - * @param nodeid + * Access to revision data as is, equivalent to <code>rawContent(getRevisionIndex(nodeid), sink)</code> + * + * @param nodeid revision to retrieve + * @param sink data destination + * + * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog + * @throws HgInvalidControlFileException if access to revlog index/data entry failed + * @throws CancelledException if content retrieval operation was cancelled + * + * @see #rawContent(int, ByteChannel) */ - protected void rawContent(Nodeid nodeid, ByteChannel sink) throws HgException, IOException, CancelledException, HgInvalidRevisionException { + protected void rawContent(Nodeid nodeid, ByteChannel sink) throws HgInvalidControlFileException, CancelledException, HgInvalidRevisionException { rawContent(getRevisionIndex(nodeid), sink); } /** - * @param fileRevisionIndex - index of this file change (not a changelog revision index), non-negative. From predefined constants, only {@link HgRepository#TIP} makes sense. - * FIXME is it necessary to have IOException along with HgException here? + * Access to revision data as is (decompressed, but otherwise unprocessed, i.e. not parsed for e.g. changeset or manifest entries). + * + * @param fileRevisionIndex index of this revlog change (not a changelog revision index), non-negative. From predefined constants, only {@link HgRepository#TIP} makes sense. + * @param sink data destination + * + * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog + * @throws HgInvalidControlFileException if access to revlog index/data entry failed + * @throws CancelledException if content retrieval operation was cancelled */ - protected void rawContent(int fileRevisionIndex, ByteChannel sink) throws HgException, IOException, CancelledException, HgInvalidRevisionException { + protected void rawContent(int fileRevisionIndex, ByteChannel sink) throws HgInvalidControlFileException, CancelledException, HgInvalidRevisionException { if (sink == null) { throw new IllegalArgumentException(); } - ContentPipe insp = new ContentPipe(sink, 0, repo.getContext().getLog()); - insp.checkCancelled(); - content.iterate(fileRevisionIndex, fileRevisionIndex, true, insp); - insp.checkFailed(); + try { + ContentPipe insp = new ContentPipe(sink, 0, repo.getContext().getLog()); + insp.checkCancelled(); + content.iterate(fileRevisionIndex, fileRevisionIndex, true, insp); + insp.checkFailed(); + } catch (IOException ex) { + HgInvalidControlFileException e = new HgInvalidControlFileException(String.format("Access to revision %d content failed", fileRevisionIndex), ex, null); + e.setRevisionIndex(fileRevisionIndex); + // FIXME e.setFileName(content.getIndexFile() or this.getHumanFriendlyPath()) - shall decide whether + // protected abstract getPath() with impl in HgDataFile, HgManifest and HgChangelog or path is data of either Revlog or RevlogStream + // Do the same (add file name) below + throw e; + } catch (HgInvalidControlFileException ex) { + throw ex; + } catch (HgException ex) { + HgInvalidControlFileException e = new HgInvalidControlFileException(ex.getClass().getSimpleName(), ex, null); + e.setRevisionIndex(fileRevisionIndex); + throw e; + } } /** @@ -585,6 +614,7 @@ failure = ex; } + // TODO consider if IOException in addition to HgException is of any real utility public void checkFailed() throws HgException, IOException, CancelledException { if (failure == null) { return;