# HG changeset patch # User Artem Tikhomirov # Date 1317260159 -7200 # Node ID c3d2233ba842f5a3ab801f3a4b8d9707001137df # Parent 09628675bcee92fb1dfe9ad3b33a2a432283ee99 Shall propagate errors to clients, not work around them silently diff -r 09628675bcee -r c3d2233ba842 src/org/tmatesoft/hg/core/HgInvalidControlFileException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/tmatesoft/hg/core/HgInvalidControlFileException.java Thu Sep 29 03:35:59 2011 +0200 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2011 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 + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For information on how to redistribute this software under + * the terms of a license other than GNU General Public License + * contact TMate Software at support@hg4j.com + */ +package org.tmatesoft.hg.core; + +import java.io.File; + +import org.tmatesoft.hg.internal.Experimental; + +/** + * WORK IN PROGRESS + * + * Subclass of {@link HgInvalidFileException} to indicate failure to deal with one of Mercurial control files (those under .hg/) + * @author Artem Tikhomirov + * @author TMate Software Ltd. + */ +@SuppressWarnings("serial") +@Experimental(reason="WORK IN PROGRESS. Name is likely to change. Path argument to be added?") +public class HgInvalidControlFileException extends HgInvalidFileException { + + public HgInvalidControlFileException(String message, Throwable th, File file) { + super(message, th, file); + } + +} diff -r 09628675bcee -r c3d2233ba842 src/org/tmatesoft/hg/repo/HgRepository.java --- a/src/org/tmatesoft/hg/repo/HgRepository.java Thu Sep 29 03:20:28 2011 +0200 +++ b/src/org/tmatesoft/hg/repo/HgRepository.java Thu Sep 29 03:35:59 2011 +0200 @@ -26,6 +26,7 @@ import java.util.List; import org.tmatesoft.hg.core.HgDataStreamException; +import org.tmatesoft.hg.core.HgInvalidControlFileException; import org.tmatesoft.hg.core.Nodeid; import org.tmatesoft.hg.core.SessionContext; import org.tmatesoft.hg.internal.ByteArrayChannel; @@ -166,37 +167,42 @@ return this.manifest; } - public HgTags getTags() { + public HgTags getTags() throws HgInvalidControlFileException { if (tags == null) { tags = new HgTags(this); - try { - HgDataFile hgTags = getFileNode(".hgtags"); - if (hgTags.exists()) { - for (int i = 0; i <= hgTags.getLastRevision(); i++) { // FIXME in fact, would be handy to have walk(start,end) - // method for data files as well, though it looks odd. - try { - ByteArrayChannel sink = new ByteArrayChannel(); - hgTags.content(i, sink); - final String content = new String(sink.toArray(), "UTF8"); - tags.readGlobal(new StringReader(content)); - } catch (CancelledException ex) { - // IGNORE, can't happen, we did not configure cancellation - getContext().getLog().debug(getClass(), ex, null); - } catch (HgDataStreamException ex) { - getContext().getLog().error(getClass(), ex, null); - // FIXME need to react - } catch (IOException ex) { - // UnsupportedEncodingException can't happen (UTF8) - // only from readGlobal. Need to reconsider exceptions thrown from there - getContext().getLog().error(getClass(), ex, null); - // XXX need to decide what to do this. failure to read single revision shall not break complete cycle - } + HgDataFile hgTags = getFileNode(".hgtags"); + if (hgTags.exists()) { + for (int i = 0; i <= hgTags.getLastRevision(); i++) { // FIXME in fact, would be handy to have walk(start,end) + // method for data files as well, though it looks odd. + try { + ByteArrayChannel sink = new ByteArrayChannel(); + hgTags.content(i, sink); + final String content = new String(sink.toArray(), "UTF8"); + tags.readGlobal(new StringReader(content)); + } catch (CancelledException ex) { + // IGNORE, can't happen, we did not configure cancellation + getContext().getLog().debug(getClass(), ex, null); + } catch (HgDataStreamException ex) { + getContext().getLog().error(getClass(), ex, null); + // FIXME need to react + } catch (IOException ex) { + // UnsupportedEncodingException can't happen (UTF8) + // only from readGlobal. Need to reconsider exceptions thrown from there: + // BufferedReader wraps String and unlikely to throw IOException, perhaps, log is enough? + getContext().getLog().error(getClass(), ex, null); + // XXX need to decide what to do this. failure to read single revision shall not break complete cycle } } - tags.readGlobal(new File(getWorkingDir(), ".hgtags")); // XXX replace with HgDataFile.workingCopy - tags.readLocal(new File(repoDir, "localtags")); + } + File file2read = null; + try { + file2read = new File(getWorkingDir(), ".hgtags"); + tags.readGlobal(file2read); // XXX replace with HgDataFile.workingCopy + file2read = new File(repoDir, "localtags"); + tags.readLocal(file2read); } catch (IOException ex) { getContext().getLog().error(getClass(), ex, null); + throw new HgInvalidControlFileException("Failed to read tags", ex, file2read); } } return tags;