diff options
| author | a14m <[email protected]> | 2020-12-06 16:16:35 +0100 |
|---|---|---|
| committer | a14m <[email protected]> | 2020-12-06 16:16:35 +0100 |
| commit | c7a80df29dac0cb5a7b5bd78a750c15fd6146908 (patch) | |
| tree | f17b19ee2917bddd4d2a1104632c644d98c70ab6 /CLI/ruby/lib | |
| parent | 90eb66f7e34cf6f5a0468e21d3542b20cc668e78 (diff) | |
Add the error handling for missing/invalid file/URL input
Diffstat (limited to 'CLI/ruby/lib')
| -rw-r--r-- | CLI/ruby/lib/game_of_life/generators/input.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/CLI/ruby/lib/game_of_life/generators/input.rb b/CLI/ruby/lib/game_of_life/generators/input.rb index c0d96c1..3082e70 100644 --- a/CLI/ruby/lib/game_of_life/generators/input.rb +++ b/CLI/ruby/lib/game_of_life/generators/input.rb @@ -22,6 +22,11 @@ module GameOfLife # where any alpha numeric character is considered a living cell (true) raw.map! { |row| row.chars.map { |char| char.match?(/[[:alnum:]]/) } } populate(parsed_input: raw, width: options["width"].to_i, height: options["height"].to_i) + rescue OpenURI::HTTPError, SocketError + raise GameOfLife::Error, "URL isn't avaialable, please check it again and make sure the URL is correct" + rescue Errno::ENOENT + raise GameOfLife::Error, + "File isn't avaialable, please check it again and make sure the path to the input file is correct" end # Populate the {GameOfLife::Universe} with reference to the parsed input 2D array (True/False) |
