Skip to content

Commit

Permalink
Allow empty config file in flex output
Browse files Browse the repository at this point in the history
No flex config file, or one that doesn't define any tables is usually
not very useful. But it can be used in slim mode to have the middle
tables only. Or it can be used to do some other processing or instead
if the null output for testing.

We still output a warning, but no error any more if the style file
is missing from the command line or if there are no tables defined.
  • Loading branch information
joto committed Jun 15, 2024
1 parent 864a31a commit be90afc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/osm2pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ static void set_option_defaults(options_t *options)

if (options->style.empty()) {
if (options->output_backend == "flex") {
throw std::runtime_error{"You have to set the config file "
"with the -S|--style option."};
log_warn("No config file set with -S|--style option. Running with "
"empty config!");
}
if (options->output_backend == "pgsql") {
options->style = DEFAULT_STYLE;
Expand Down
5 changes: 2 additions & 3 deletions src/output-flex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,8 +1172,7 @@ output_flex_t::output_flex_t(std::shared_ptr<middle_query_t> const &mid,
}

if (m_tables->empty()) {
throw std::runtime_error{
"No tables defined in Lua config. Nothing to do!"};
log_warn("No output tables defined!");
}

// For backwards compatibility we add a "default" expire output to all
Expand Down Expand Up @@ -1335,7 +1334,7 @@ void output_flex_t::init_lua(std::string const &filename)

// Load user config file
luaX_set_context(lua_state(), this);
if (luaL_dofile(lua_state(), filename.c_str())) {
if (!filename.empty() && luaL_dofile(lua_state(), filename.c_str())) {
throw fmt_error("Error loading lua config: {}.",
lua_tostring(lua_state(), -1));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/bdd/flex/lua-basics.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Feature: Flex output uses a Lua config file
print("stage=" .. osm2pgsql.stage)
print("Table=" .. type(osm2pgsql.Table))
"""
Then running osm2pgsql flex fails
And the error output contains
When running osm2pgsql flex
Then the error output contains
"""
No tables defined in Lua config. Nothing to do!
No output tables defined
"""
And the standard output contains
"""
Expand Down

0 comments on commit be90afc

Please sign in to comment.