Let format autodetection fail as an answer, not as an exception
MarCCD::CanRead and SMV::CanRead read the first plausible file of a directory outside their own try, and the CLI made all three CanRead calls outside the try that reports a bad input. "rugnux <dir>" whose alphabetically-first plausible file is unreadable therefore terminated with no message. CanRead now answers false for anything it cannot read, and the CLI asks the question where it can report the answer. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nW6FNRP1bBJJ8pfHiByAT
This commit is contained in:
+9
-4
@@ -222,13 +222,18 @@ std::vector<std::string> CollectSweep(const std::string &path) {
|
||||
return out;
|
||||
}
|
||||
|
||||
// Asked of every input before anything is read, including inputs that are not SMV at all, so it
|
||||
// answers a question and never fails: a file it cannot open or make sense of is simply not one of
|
||||
// ours. The directory arm has to be inside the try as much as the single-file one - it opens the
|
||||
// first plausible file in the folder, which can be unreadable, and the throw came out of a call site
|
||||
// that does not catch it, ending the run with no message at all.
|
||||
bool CanRead(const std::string &path) {
|
||||
std::error_code ec;
|
||||
if (std::filesystem::is_directory(path, ec))
|
||||
return !CollectSweep(path).empty();
|
||||
if (!PlausibleExtension(std::filesystem::path(path)))
|
||||
return false;
|
||||
try {
|
||||
if (std::filesystem::is_directory(path, ec))
|
||||
return !CollectSweep(path).empty();
|
||||
if (!PlausibleExtension(std::filesystem::path(path)))
|
||||
return false;
|
||||
const auto kv = HeaderBlock(path);
|
||||
return kv.has_value() && kv->count("SIZE1") && kv->count("SIZE2");
|
||||
} catch (const JFJochException &) {
|
||||
|
||||
Reference in New Issue
Block a user