         return AnyIterator {
             guard let pair = a.next() else { return nil }
             let (groupKey, results) = pair
-            guard var bindings = groupBindings[groupKey] else { fatalError("Unexpected missing aggregation group template") }
+            guard var bindings = groupBindings[groupKey] else {
+                Logger.shared.error("Unexpected missing aggregation group template")
+                fatalError("Unexpected missing aggregation group template")
+            }
             for (agg, name) in aggs {
                 switch agg {
                 case .countAll:

            for row in rows {
                var bindings = [String:Term]()
                for (node, term) in zip(names, row) {
                    guard case .variable(let name, _) = node else { fatalError() }
                    if let term = term {
                        bindings[name] = term
                    }

        let termIterator : AnyIterator<TermResult> = AnyIterator {
            guard let pair = b.next() else { return nil }
            let (groupKey, term) = pair
            guard var bindings = groupBindings[groupKey] else {
                Logger.shared.error("Unexpected missing aggregation group template")
                fatalError("Unexpected missing aggregation group template")
            }
            if let error = groupErrors[groupKey] {
                print("*** error binding aggregate to ?\(name): \(error)")
            } else {
