 if let op = args.next() {
     try setup(database, startTime: startSecond)
     if op == "load" {
-        var graph: Term? = nil
-        if let next = args.peek(), next == "-g" {
-            _ = args.next()
-            guard let iri = args.next() else { fatalError("No IRI value given after -g") }
-            graph = Term(value: iri, type: .iri)
-        }
-
-        count = try parse(database, files: args.elements(), startTime: startSecond, graph: graph)
+        do {
+            var graph: Term? = nil
+            if let next = args.peek(), next == "-g" {
+                _ = args.next()
+                guard let iri = args.next() else { fatalError("No IRI value given after -g") }
+                graph = Term(value: iri, type: .iri)
+            }
+            
+            count = try parse(database, files: args.elements(), startTime: startSecond, graph: graph)
+        } catch let e {
+            warn("*** Failed to load data: \(e)")
+        }
     } else if op == "sort" {
-        var graph: Term? = nil
-        if let next = args.peek(), next == "-g" {
-            _ = args.next()
-            guard let iri = args.next() else { fatalError("No IRI value given after -g") }
-            graph = Term(value: iri, type: .iri)
-        }
-        
-        let (c, terms) = try sortParse(files: args.elements(), graph: graph)
-        for i in terms.keys.sorted() {
-            if let term = terms[i] {
-                print("\(i)\t\(term)")
-            }
-        }
-        count = c
+        do {
+            var graph: Term? = nil
+            if let next = args.peek(), next == "-g" {
+                _ = args.next()
+                guard let iri = args.next() else { fatalError("No IRI value given after -g") }
+                graph = Term(value: iri, type: .iri)
+            }
+            
+            let (c, terms) = try sortParse(files: args.elements(), graph: graph)
+            for i in terms.keys.sorted() {
+                if let term = terms[i] {
+                    print("\(i)\t\(term)")
+                }
+            }
+            count = c
+        } catch let e {
+            warn("*** Failed to sort data: \(e)")
+        }
     } else if op == "terms" {
         count = try printTerms(from: database)
     } else if op == "graphs" {

            graph = Term(value: iri, type: .iri)
        }
        guard let qfile = args.next() else { fatalError("No query file given") }
        let url = URL(fileURLWithPath: qfile)
        let sparql = try Data(contentsOf: url)
        guard var p = SPARQLParser(data: sparql) else { fatalError("Failed to construct SPARQL parser") }
        do {
            let q = try p.parseQuery()

        let type_padded = type.padding(toLength: 24, withPad: " ", startingAt: 0)
        print("  \(page)\t\(date)\t\(name_padded)\t\(type_padded)\t\t\(prev)")
    }
}

func data(fromFileOrString qfile: String) throws -> Data {
    let url = URL(fileURLWithPath: qfile)
    let data: Data
    if case .some(true) = try? url.checkResourceIsReachable() {
        data = try Data(contentsOf: url)
    } else {
        guard let s = qfile.data(using: .utf8) else {
            fatalError("Could not interpret SPARQL query string as UTF-8")
        }
        data = s
    }
    return data
}

var verbose = true
