Skip to content

Conversation

@dhthwy
Copy link
Contributor

@dhthwy dhthwy commented Nov 11, 2025

let try_autocomplete() do the printing.

Also may be worthwhile to use using for the result type or return a struct instead. Like a Result struct.

}

void get_commands(color_ostream &con, std::vector<std::string> &commands) {
std::optional<std::string> get_commands(color_ostream &con, std::vector<std::string> &commands) {
Copy link
Member

@ab9rf ab9rf Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function currently uses an out parameter - i would argue that this is a use case for returning a std::expected<std::vector<std::string>>, std::string> instead of having an out parameter

oh, nevermind, std::expected is c++23, so let's notate this for review when we move to c++23 -- which won't be prior to 2029 unless we decide to change our Linux support policy - while MSVC already supports std::expected, gcc doesn't until gcc 14, and we don't get gcc 14 until Ubuntu LTS 24.04 goes EOL in April 2029

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking a bit more about this, i think this is a candidate for using an exception. the condition is exceptional and should rarely occur, so using an exception for the exceptional case is pretty much what exceptions are for

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DFHack]# o
o is not recognized. Possible completions: once-per-save on-new-fortress open-legends orders overlay
[DFHack]# o
Cannot acquire core lock in helpdb.get_commands
o is not a recognized command.
[DFHack]# o

that's dfhack posix console. There's contention when fps is low.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing is one possible way, but they should be caught. It wouldn't be nice to crash just because the simulation thread has a big workload that's dropped fps to 10 or happened to hold the lock for too long for some reason or another. If it happens at 10 fps (and often), it's sure to happen at higher fps (just less likely).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not big on the std::optional approach for returning an error message.

std::expected would be cleaner, but as you said, it's not c++20.

Exception makes sense to handle it as well. I just wouldn't let it crash over a lag condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants