diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index 264d6663e..4e73641f4 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -255,16 +255,19 @@ module VagrantPlugins result.match?(/\"#{network}\"/) end + # Returns true or false if network is in use or not. + # Nil if Vagrant fails to receive proper JSON from `docker network inspect` + # # @param [String] network - name of network to look for - # @return [Bool] + # @return [Bool,nil] def network_used?(network) result = inspect_network(network) begin result = JSON.parse(result) return result.first["Containers"].size > 0 rescue JSON::ParserError => e - # Could not parse result of network inspection - # Handle this some how, maybe log error but not raise? + @logger.warn("Could not properly parse response from `docker network inspect #{network}`") + return nil end end