Skip to content

Better exception logic for get_target_file() #2472

@ryan-pratt

Description

@ryan-pratt

get_target_file currently throws an exception if you request a file that doesn't exist. This is counterintuitive based on the doc comment with @return [File|nil]. This logic should instead return nil if the file doesn't exist, rather than throwing an exception.

Example below. Note that the_file_dne.inspect prints nil only because that value wasn't set because it fell into the rescue block. If you did this in python, you'd get: NameError: name 'the_file_dne' is not defined

Image

Rationale: checking if the returned value is nil is cleaner/easier in the script in case you ask for a file that doesn't exist. Let exceptions be for other catastrophic errors.

Make sure to also update python implementation, and update docs (which currently don't say anything about nil here)

This is an API breaking change, so should be in the 7.0 release

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions