opensafely-core / opensafely-core/sqlrunner
Friendlier error message than `FileNotFoundError`
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1
- Forks
- 0
- Avg merge
- 4d 23h
- Merged PRs (30d)
- 3
Description
If the input file doesn't exist, then SQL Runner prints a stack trace. A friendlier error message than FileNotFoundError would be nice.
Running actions: query
jobrunner.run loop started
query: Copying in code from /Users/iaindillingham/Code/opensafely/tpp-database-schema
query: Preparing
query: Executing
query: Logs written to: /Users/iaindillingham/Code/opensafely/tpp-database-schema/metadata/query.log
query: Finalizing
query: Job exited with error code 1
query: Cleaning up container and volume
=> query
Job exited with error code 1
log file: metadata/query.log
outputs:
(no outputs)
logs:
Traceback (most recent call last):
File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/app/sqlrunner/__main__.py", line 8, in <module>
sql_query = main.read_text(args.input)
File "/app/sqlrunner/main.py", line 37, in read_text
return f_path.read_text(encoding="utf-8")
File "/usr/lib/python3.10/pathlib.py", line 1134, in read_text
with self.open(mode='r', encoding=encoding, errors=errors) as f:
File "/usr/lib/python3.10/pathlib.py", line 1119, in open
return self._accessor.open(self, mode, buffering, encoding, errors,
FileNotFoundError: [Errno 2] No such file or directory: 'analysis/query.sql'
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in sqlrunner/main.py, where the input is passed to main.read_text, then inspect read_text in sqlrunner/main.py. Run SQL Runner with a missing input path and verify that it reports a friendly error identifying the missing file without printing the FileNotFoundError stack trace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100