comparison src/org/tmatesoft/hg/core/HgCatCommand.java @ 396:0ae53c32ecef

Straighten out exceptions thrown when file access failed - three is too much
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 23 Feb 2012 01:06:24 +0100
parents 8107b95f4280
children 9c9c442b5f2e
comparison
equal deleted inserted replaced
395:4732fffff58a 396:0ae53c32ecef
1 /* 1 /*
2 * Copyright (c) 2011 TMate Software Ltd 2 * Copyright (c) 2011-2012 TMate Software Ltd
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License. 6 * the Free Software Foundation; version 2 of the License.
7 * 7 *
18 18
19 import static org.tmatesoft.hg.repo.HgInternals.wrongRevisionIndex; 19 import static org.tmatesoft.hg.repo.HgInternals.wrongRevisionIndex;
20 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; 20 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION;
21 import static org.tmatesoft.hg.repo.HgRepository.TIP; 21 import static org.tmatesoft.hg.repo.HgRepository.TIP;
22 22
23 import java.io.FileNotFoundException;
24 import java.io.IOException; 23 import java.io.IOException;
25 import java.nio.ByteBuffer; 24 import java.nio.ByteBuffer;
26 25
27 import org.tmatesoft.hg.repo.HgDataFile; 26 import org.tmatesoft.hg.repo.HgDataFile;
28 import org.tmatesoft.hg.repo.HgRepository; 27 import org.tmatesoft.hg.repo.HgRepository;
130 129
131 /** 130 /**
132 * Runs the command with current set of parameters and pipes data to provided sink. 131 * Runs the command with current set of parameters and pipes data to provided sink.
133 * 132 *
134 * @param sink output channel to write data to. 133 * @param sink output channel to write data to.
135 * @throws HgDataStreamException 134 *
135 * @throws HgBadArgumentException if no target file node found
136 * @throws HgInvalidControlFileException if access to revlog index/data entry failed
137 * @throws HgInvalidFileException if access to file in working directory failed
138 * @throws HgException in case of some other library issue
139 * @throws CancelledException if execution of the operation was cancelled
140 * @throws HgInvalidRevisionException if supplied argument doesn't represent revision index in this revlog (<em>runtime exception</em>)
136 * @throws IllegalArgumentException when command arguments are incomplete or wrong 141 * @throws IllegalArgumentException when command arguments are incomplete or wrong
137 */ 142 */
138 public void execute(ByteChannel sink) throws HgDataStreamException, HgInvalidControlFileException, CancelledException { 143 public void execute(ByteChannel sink) throws HgException, CancelledException {
144 // XXX perhaps, IAE together with HgBadArgumentException is not the best idea
139 if (revisionIndex == BAD_REVISION && revision == null && cset == null) { 145 if (revisionIndex == BAD_REVISION && revision == null && cset == null) {
140 throw new IllegalArgumentException("File revision, corresponing local number, or a changset nodeid shall be specified"); 146 throw new IllegalArgumentException("File revision, corresponing local number, or a changset nodeid shall be specified");
141 } 147 }
142 if (file == null) { 148 if (file == null) {
143 throw new IllegalArgumentException("Name of the file is missing"); 149 throw new IllegalArgumentException("Name of the file is missing");
145 if (sink == null) { 151 if (sink == null) {
146 throw new IllegalArgumentException("Need an output channel"); 152 throw new IllegalArgumentException("Need an output channel");
147 } 153 }
148 HgDataFile dataFile = repo.getFileNode(file); 154 HgDataFile dataFile = repo.getFileNode(file);
149 if (!dataFile.exists()) { 155 if (!dataFile.exists()) {
150 throw new HgDataStreamException(file, new FileNotFoundException(file.toString())); 156 // TODO may benefit from repo.getStoragePath to print revlog location in addition to human-friendly file path
157 throw new HgBadArgumentException(String.format("File %s not found in the repository", file), null).setFileName(file);
151 } 158 }
152 int revToExtract; 159 int revToExtract;
153 if (cset != null) { 160 if (cset != null) {
154 int csetRev = repo.getChangelog().getRevisionIndex(cset); 161 int csetRev = repo.getChangelog().getRevisionIndex(cset);
155 Nodeid toExtract = null; 162 Nodeid toExtract = null;