Skip to content

Commit e11a799

Browse files
committed
refactor: made functions to ensure debug_filepath exists and is accessible
1 parent fdf5298 commit e11a799

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

fortls/__init__.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,7 @@ def locate_config(root: str) -> str | None:
472472
config_path = os.path.join(root, f)
473473
return config_path
474474

475-
if args.debug_filepath is None:
476-
error_exit("'debug_filepath' not specified for parsing test")
477-
file_exists = os.path.isfile(args.debug_filepath)
478-
if file_exists is False:
479-
error_exit("Specified 'debug_filepath' does not exist")
475+
ensure_file_accessible(args.debug_filepath)
480476
# Get preprocessor definitions from config file
481477
pp_suffixes = None
482478
pp_defs = {}
@@ -520,13 +516,15 @@ def locate_config(root: str) -> str | None:
520516
print("{}: {}".format(obj.get_type(), obj.FQSN))
521517

522518

519+
def ensure_file_accessible(filepath: str):
520+
"""Ensure the file exists and is accessible, raising an error if not."""
521+
if not os.path.isfile(filepath):
522+
error_exit(f"File '{filepath}' does not exist or is not accessible")
523+
print(f' File = "{filepath}"')
524+
525+
523526
def check_request_params(args, loc_needed=True):
524-
if args.debug_filepath is None:
525-
error_exit("'debug_filepath' not specified for debug request")
526-
file_exists = os.path.isfile(args.debug_filepath)
527-
if file_exists is False:
528-
error_exit("Specified 'debug_filepath' does not exist")
529-
print(f' File = "{args.debug_filepath}"')
527+
ensure_file_accessible(args.debug_filepath)
530528
if loc_needed:
531529
if args.debug_line is None:
532530
error_exit("'debug_line' not specified for debug request")

0 commit comments

Comments
 (0)