Horizon: `hz init .` generates a config which sets `project_name` to `.`, which isn't a legal database name.

Created on 17 May 2016  ·  12Comments  ·  Source: rethinkdb/horizon

Probably we should make this work and set the project_name to the current directory.

In general we should probably either be validating or escaping project names.

bug cli tool

Most helpful comment

Similar problem:
I'm following the tutorial instructions and create an app via hz init. If I use an app name that's illegal for a rethinkdb database then the subsequent hz serve fails. Example would be: hz init hz-app

All 12 comments

@mlucy does this happen on the permissions branch?

@deontologician -- yes, it happens as of 3aefc03 as well.

Similar problem:
I'm following the tutorial instructions and create an app via hz init. If I use an app name that's illegal for a rethinkdb database then the subsequent hz serve fails. Example would be: hz init hz-app

The Getting Started guide itself recommends using hz init example-app, which fails on the hz serve step for this same reason.

$ hz init example-app
$ cd example-app/
$ hz serve --dev
App available at http://127.0.0.1:8181
RethinkDB
   ├── Admin interface: http://localhost:53716
   └── Drivers can connect to port 53715
Starting Horizon...
error: Connection to RethinkDB terminated: ReqlQueryLogicError: Database name `example-app` invalid (Use A-Za-z0-9_ only) in:
r(["example-app", "example-app_internal"]).forEach(function(var_0) { return r.branch(r.dbList().contains(var_0), [], r.dbCreate(var_0)); }).do(function() { return r(["collections", "users_auth", "users", "groups"]).forEach(function(var_1) { return r.branch(r.db("example-app_internal").tableList().contains(var_1), [], r.db("example-app_internal").tableCreate(var_1)); }); })

hz init should run a regex and replace anything that doesn't match A-Za-z0-9_ with _

Yeah, this is definitely a wart

Might pay to update the getting started docs to recommend example_app until this can be fixed.

Glad this has been reported. I just installed the repo for the first time tonight and thought I had some kind of funky RethinkDB config issue.

Getting started docs have been updated to example_app.

I think the best behavior for hz init would be to:

  • Replace - by _ in the project name before writing it to the config file
  • If the path contains any characters other than [A-Za-z0-9_-], print and error and abort creating the project. This handles the case where you do hz init ., so you don't end up with a project called _. It also helps if for example you're trying to use let's say Chinese characters with hz init. Simply rewriting the project name to ________ would be bad.

Additionally, we should add an explicit check to the configuration parsing in the CLI that verifies the project name and rejects it with a good error message if it doesn't match the mentioned expression (so it would catch the issue in both hz serve and hz set-schema). Maybe we should also verify it in the server module itself?

I think it would be really really nice if hz init . worked. I'm used to that working from other tools like git. I think the behavior should be that it just reads the name of the current working directory to get the project name.

Going to implement @danielmewes suggestion today, except that if the name is ., the cwd basename will be used. Any objections?

Sounds good to me!

A slightly more generalized option is that whenever you pass a path that already exists, you use the last component of the full path it resolves to (i.e. resolving any . and .. that might be in it). Starting out by handling . as a special case sounds ok to me though. We can generalize it at any point in the future.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deontologician picture deontologician  ·  3Comments

marshall007 picture marshall007  ·  8Comments

ChrisCates picture ChrisCates  ·  3Comments

josephg picture josephg  ·  6Comments

lirbank picture lirbank  ·  8Comments