Repository: common-workflow-language/cwltool

Issue:
improve error message for supplying random file as the input object
when trying out https://github.com/common-workflow-language/workflow-service/blob/master/testdata/md5sum.cwl
```
$ cwl-runner --debug ./md5sum.cwl md5sum.input
../.venv2/bin/cwl-runner 1.0.20180518123035
Resolved './md5sum.cwl' to 'file:///home/gijs/Work/workflow-service/testdata/md5sum.cwl'
Workflow error, try again with --debug for more information:
Invalid job input record:
md5sum.cwl:5:3: Traceback (most recent call last):
                
                  File
                  "/home/gijs/Work/workflow-service/.venv2/local/lib/python2.7/site-packages/cwltool/process.py",
                  line 358, in fillInDefaults
                    if job.get(fieldname) is not None:
                
                AttributeError: 'str' object has no attribute 'get'
Traceback (most recent call last):
  File "/home/gijs/Work/workflow-service/.venv2/local/lib/python2.7/site-packages/cwltool/main.py", line 592, in main
    **vars(args))
  File "/home/gijs/Work/workflow-service/.venv2/local/lib/python2.7/site-packages/cwltool/executors.py", line 31, in __call__
    return self.execute(*args, **kwargs)
  File "/home/gijs/Work/workflow-service/.venv2/local/lib/python2.7/site-packages/cwltool/executors.py", line 71, in execute
    self.run_jobs(t, job_order_object, logger, **kwargs)
  File "/home/gijs/Work/workflow-service/.venv2/local/lib/python2.7/site-packages/cwltool/executors.py", line 100, in run_jobs
    for r in jobiter:
  File "/home/gijs/Work/workflow-service/.venv2/local/lib/python2.7/site-packages/cwltool/workflow.py", line 463, in job
    builder = self._init_job(job_order, **kwargs)
  File "/home/gijs/Work/workflow-service/.venv2/local/lib/python2.7/site-packages/cwltool/process.py", line 592, in _init_job
    raise WorkflowException("Invalid job input record:\n" + Text(e))
WorkflowException: Invalid job input record:
md5sum.cwl:5:3: Traceback (most recent call last):
md5sum.cwl:5:3: 
md5sum.cwl:5:3:   File "/home/gijs/Work/workflow-service/.venv2/local/lib/python2.7/site-packages/cwltool/process.py", line 358, in fillInDefaults
md5sum.cwl:5:3:     if job.get(fieldname) is not None:
md5sum.cwl:5:3: 
md5sum.cwl:5:3: AttributeError: 'str' object has no attribute 'get'
```


Discussion:
Try upgrading cwltool.  I don't know exactly what is going on here but there was an incompatible release of ruamel.yaml a couple months ago that caused a lot of strange errors in cwltool, which has since been addressed.
same issue with `cwltool==1.0.20180923172926` on both python2 and python3.
upgrading `ruamel.yaml` manually breaks cwltool:
```
$ pip install --upgrade ruamel.yaml
Collecting ruamel.yaml
  Downloading https://files.pythonhosted.org/packages/c1/db/338e3468424b96280c1389ac47a67dc352e32eb0dae47565ba255d6cf5ca/ruamel.yaml-0.15.71-cp27-cp27mu-manylinux1_x86_64.whl (607kB)
    100% |████████████████████████████████| 614kB 4.4MB/s 
Requirement already satisfied, skipping upgrade: ruamel.ordereddict; platform_python_implementation == "CPython" and python_version <= "2.7" in /home/gijs/Work/workflow-service/.venv2/lib/python2.7/site-packages (from ruamel.yaml) (0.4.13)
cwltool 1.0.20180923172926 has requirement ruamel.yaml<=0.15.51,>=0.12.4, but you'll have ruamel-yaml 0.15.71 which is incompatible.
wes-service 2.9 has requirement ruamel.yaml<0.15,>=0.12.4, but you'll have ruamel-yaml 0.15.71 which is incompatible.
Installing collected packages: ruamel.yaml
  Found existing installation: ruamel.yaml 0.14.12
    Uninstalling ruamel.yaml-0.14.12:
      Successfully uninstalled ruamel.yaml-0.14.12
Successfully installed ruamel.yaml-0.15.71
$ cwl-runner --debug ./md5sum.cwl md5sum.input
Traceback (most recent call last):
  File "../.venv3/bin/cwl-runner", line 11, in <module>
    sys.exit(main())
  File "/home/gijs/Work/workflow-service/.venv3/lib/python3.6/site-packages/cwltool/main.py", line 509, in main
    _logger.info(versionfunc())
  File "/home/gijs/Work/workflow-service/.venv3/lib/python3.6/site-packages/cwltool/utils.py", line 44, in versionstring
    pkg = pkg_resources.require("cwltool")
  File "/home/gijs/Work/workflow-service/.venv3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 892, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/home/gijs/Work/workflow-service/.venv3/lib/python3.6/site-packages/pkg_resources/__init__.py", line 783, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (ruamel.yaml 0.15.71 (/home/gijs/Work/workflow-service/.venv3/lib/python3.6/site-packages), Requirement.parse('ruamel.yaml<=0.15.51,>=0.12.4'), {'cwltool'}) 
```
`md5sum.input` is not the CWL input object, https://github.com/common-workflow-language/workflow-service/blob/master/testdata/md5sum.cwl.json is 
yep, that is the issue. Sorry, I copy pasted the wrong file from the workflow-service example. Still, I think the error reporting could be better here. Isn't the job file validated against a schema?
@gijzelaerr It is validated against a schema, the inputs sections of the CWL document, hence `Invalid job input record`

But yes, the error message needs to be better in this case

Resolving patch:
diff --git a/cwltool/main.py b/cwltool/main.py
--- a/cwltool/main.py
+++ b/cwltool/main.py
@@ -229,6 +229,7 @@ def load_job_order(args,                 # type: argparse.Namespace
                   ):  # type: (...) -> Tuple[MutableMapping[Text, Any], Text, Loader]
 
     job_order_object = None
+    job_order_file = None
 
     _jobloaderctx = jobloaderctx.copy()
     loader = Loader(_jobloaderctx, fetcher_constructor=fetcher_constructor)  # type: ignore
@@ -249,13 +250,21 @@ def load_job_order(args,                 # type: argparse.Namespace
         job_order_object, _ = loader.resolve_ref(job_order_file, checklinks=False)
 
     if job_order_object and "http://commonwl.org/cwltool#overrides" in job_order_object:
+        ov_uri = file_uri(job_order_file or input_basedir)
         overrides_list.extend(
-            resolve_overrides(job_order_object, file_uri(job_order_file), tool_file_uri))
+            resolve_overrides(job_order_object, ov_uri, tool_file_uri))
         del job_order_object["http://commonwl.org/cwltool#overrides"]
 
     if not job_order_object:
         input_basedir = args.basedir if args.basedir else os.getcwd()
 
+    if job_order_object and not isinstance(job_order_object, MutableMapping):
+        _logger.error(
+            'CWL input object at %s is not formatted correctly, it should be a '
+            'JSON/YAML dictionay, not %s.\n'
+            'Raw input object:\n%s', job_order_file or "stdin",
+            type(job_order_object), job_order_object)
+        sys.exit(1)
     return (job_order_object, input_basedir, loader)
 
 


Test patch: