Repository: opendatacube/datacube-core

Issue:
Error message for missing file is confusing
### Expected behaviour

```bash
> datacube dataset add /no/such/file.yaml
ERROR: no such file "/no/such/file.yaml"
```

### Actual behaviour

```
ERROR No supported metadata docs found for dataset /no/such/file.yaml
```

### Steps to reproduce the behaviour

```
datacube dataset add  /no/such/file.yaml
```
observe confusing message.


### Environment information

code in `develop` branch.


### Remediation Suggestions

Error message originates from here:
https://github.com/opendatacube/datacube-core/blob/80d466a2635ab37fbe33bb283b77df305e3c9236/datacube/ui/common.py#L91

There is some pretty involved logic in "locating actual metadata file", code accepts all sorts of inputs:

- directory
- some file in directory with a sibling file named `{base}.{agdc-md,agdc-metadata}.{yaml,yml,json}{,.tar.gz, .tgz}`.

Hence the error message, but really, if input is a "file path" and it is not a path that exists on the filesystem the error message should say just that: `"Supplied path '/no/such/file.yml' does not exist"`. And the current message should only be used when supplied path is an existing file/directory but is not a metadata file, say it is a `.tiff` image, but there is no metadata file next to it, or it's a directory and there are no metadata file in it.


Error message for missing file is confusing
### Expected behaviour

```bash
> datacube dataset add /no/such/file.yaml
ERROR: no such file "/no/such/file.yaml"
```

### Actual behaviour

```
ERROR No supported metadata docs found for dataset /no/such/file.yaml
```

### Steps to reproduce the behaviour

```
datacube dataset add  /no/such/file.yaml
```
observe confusing message.


### Environment information

code in `develop` branch.


### Remediation Suggestions

Error message originates from here:
https://github.com/opendatacube/datacube-core/blob/80d466a2635ab37fbe33bb283b77df305e3c9236/datacube/ui/common.py#L91

There is some pretty involved logic in "locating actual metadata file", code accepts all sorts of inputs:

- directory
- some file in directory with a sibling file named `{base}.{agdc-md,agdc-metadata}.{yaml,yml,json}{,.tar.gz, .tgz}`.

Hence the error message, but really, if input is a "file path" and it is not a path that exists on the filesystem the error message should say just that: `"Supplied path '/no/such/file.yml' does not exist"`. And the current message should only be used when supplied path is an existing file/directory but is not a metadata file, say it is a `.tiff` image, but there is no metadata file next to it, or it's a directory and there are no metadata file in it.




Discussion:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.


Resolving patch:
diff --git a/datacube/ui/common.py b/datacube/ui/common.py
--- a/datacube/ui/common.py
+++ b/datacube/ui/common.py
@@ -42,7 +42,10 @@ def get_metadata_path(possible_path: Union[str, Path]) -> str:
         if found:
             return str(found)
 
-    raise ValueError('No metadata found for input %r' % dataset_path)
+    if is_supported_document_type(dataset_path):
+        raise ValueError(f'No such file {dataset_path}')
+    else:
+        raise ValueError(f'No supported metadata docs found for dataset {dataset_path}')
 
 
 def _find_any_metadata_suffix(path: Path) -> Optional[Path]:
@@ -88,7 +91,7 @@ def ui_path_doc_stream(paths, logger=None, uri=True, raw=False):
 
     def on_error1(p, e):
         if logger is not None:
-            logger.error('No supported metadata docs found for dataset %s', str(p))
+            logger.error(str(e))
 
     def on_error2(p, e):
         if logger is not None:


Test patch: