influxdb-ruby icon indicating copy to clipboard operation
influxdb-ruby copied to clipboard

add non-raising methods to Client

Open tisba opened this issue 11 years ago • 1 comments

It would be nice to have non-raising methods on Client, like delete_database or create_database_user. In my project I'm automating this (creating databases and users on the fly) and the management code get's quite noise with all those exception handling. One issue is that there are no specific Exceptions: Both examples raise InfluxDB::Error and you have to match the message in order to figure out what the problem was (I'm happy to provide a PR for that too).

Take this real world code e.g.:

def drop_database(database_name, options={})
  influxdb = influx_client(database_name, options)

  begin
    influxdb.delete_database(database_name)
  rescue InfluxDB::Error => e
    raise e unless e.message == "Database #{database_name} doesn't exist"
    false
  end

  true
end

IMO these methods should only return true (or something else) on success and false otherwise. A bang variant could raise on e.g. "not found" errors. They should raise InfluxDB::AuthenticationError though.

def drop_database(database_name, options={})
  influx_client(database_name, options).delete_database(database_name)
end

If accepted, I'm happy to provide a PR.

tisba avatar Mar 31 '14 19:03 tisba

@tisba This seems like a reasonable request. Let me take a look at how this would affect the existing interface and we'll see if we can get something in place soon. Thanks!

toddboom avatar Mar 31 '14 19:03 toddboom