From 75c5218d4ffcd7aabbb8bc62d5e1b4d12332b8aa Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Mon, 3 Jan 2022 10:16:07 -0800
Subject: [PATCH] Don't read sources until in/out format are verified.

Partially addresses #7797.
---
 src/Text/Pandoc/App.hs | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
index 59fd43bac..3ddc4c761 100644
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -116,8 +116,6 @@ convertWithOpts opts = do
     setInputFiles (fromMaybe ["-"] (optInputFiles opts))
     setOutputFile (optOutputFile opts)
 
-    inputs <- readSources sources
-
     -- assign reader and writer based on options and filenames
     readerName <- case optFrom opts of
                        Just f  -> return f
@@ -282,6 +280,9 @@ convertWithOpts opts = do
                          (optCitationAbbreviations opts) $ mempty
 
     let filterEnv = Environment readerOpts writerOptions
+
+    inputs <- readSources sources
+
     doc <- (case reader of
              TextReader r
                | readerNameBase == "json" ->