Repository: opendatacube/datacube-core

Issue:
Ask why a dataset fails to match a specific product
### Expected behaviour
Some time when indexing a dataset, some omission or discrepancy in the metadata results in no matching product being found. Often there is a specific product in mind. If I could ask 
```bash
$ datacube dataset add FILE --intended-product=SOME_PRODUCT
```

or something like that, datacube could actually report what was missing.

### Actual behaviour
Datacube splits out the dataset information back at me.

```
Indexing datasets  [####################################]  100%
2018-05-03 10:38:23,108 28698 datacube-dataset ERROR Unable to create Dataset for file:///g/data1a/u46/users/ia1511/Work/data/test-suite/output/LS8_PQ_COUNT_TIFF/LS8_PQ_COUNT_RAW_3577_20160101_20160401.yaml: No matching Product found for {
    "creation_dt": "2018-05-03T00:37:33.396168",
[... snipped some 2500 lines ...]
    "product_type": "pq_count_modified",
    "statistics": {
        "period": "3m",
        "step": "3m"
    }
}
```

### Environment information
* Which ``datacube --version`` are you using?
Open Data Cube core, version 1.6rc1
* What datacube deployment/environment are you running against?
DEA



Discussion:
Honestly `datacube dataset add` has a whole bunch of confusing options and bad names, `--source-policy` is particularly bad in my opinion, `--auto-match` and `--match-rules` aren't well understood. There is already `--dtype` (another bad name) which I think is exactly what your `--intended-product` is supposed to be.
After reading the code it seems that `--dtype` is really just "Auto-match using a subset of products" (you can supply several `--dtype`), while help message:

```
  -t, --dtype TEXT                Product to be associated with the datasets
```

communicates something very different, at least to me.



Resolving patch:
diff --git a/datacube/scripts/dataset.py b/datacube/scripts/dataset.py
--- a/datacube/scripts/dataset.py
+++ b/datacube/scripts/dataset.py
@@ -46,7 +46,19 @@ def find_matching_product(rules, doc):
     """:rtype: datacube.model.DatasetType"""
     matched = [rule for rule in rules if changes.contains(doc, rule['metadata'])]
     if not matched:
-        raise BadMatch('No matching Product found for %s' % json.dumps(doc, indent=4))
+        # provide user with information about the failure
+        if len(rules) == 0:
+            raise BadMatch('No rules provided.')
+        elif len(rules) == 1:
+            metadata = rules[0]['metadata']
+            relevant_doc = {k: v for k, v in doc.items() if k in metadata}
+            raise BadMatch('Dataset metadata did not match product rules.'
+                           '\nDataset metadata:\n %s\n'
+                           '\nProduct metadata:\n %s\n'
+                           % (json.dumps(metadata, indent=4),
+                              json.dumps(relevant_doc, indent=4)))
+        else:
+            raise BadMatch('No matching Product found for %s' % json.dumps(doc, indent=4))
     if len(matched) > 1:
         raise BadMatch('Too many matching Products found for %s. Matched %s.' % (
             doc.get('id', 'unidentified'), matched))


Test patch: