Skip to content

Commit

Permalink
Handle edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
emeryberger committed Apr 10, 2023
1 parent 31820e6 commit ad5e90e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions sqlwrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <string>

#include <fmt/core.h>
#include <fmt/format.h>

#include "openai.hpp"
#include "sqlite3ext.h"
Expand Down Expand Up @@ -94,9 +95,13 @@ static void real_ask_command(sqlite3_context *ctx, int argc, sqlite3_value **arg
query += "\n\nExisting indexes:\n";
printed_index_header = true;
}
const char *tbl_name = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2));
const char *sql = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3));
query += fmt::format("Index for {}: {}\n", tbl_name, sql);
try {
const char *tbl_name = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 2));
const char *sql = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 3));
query += fmt::format("Index for {}: {}\n", tbl_name, sql);
} catch (fmt::v9::format_error& fe) {
// Ignore indices where the query response is null, which could get us here.
}
}

nlohmann::json prompt;
Expand Down Expand Up @@ -160,12 +165,15 @@ static void real_ask_command(sqlite3_context *ctx, int argc, sqlite3_value **arg
}
}
break;
} catch (std::runtime_error re) {
} catch (std::runtime_error& re) {
std::cout << fmt::format("Runtime error: {}\n", re.what());
} catch (nlohmann::json_abi_v3_11_2::detail::parse_error pe) {
} catch (nlohmann::json_abi_v3_11_2::detail::parse_error& pe) {
// Retry if there were JSON parse errors.
} catch (nlohmann::json_abi_v3_11_2::detail::type_error te) {
} catch (nlohmann::json_abi_v3_11_2::detail::type_error& te) {
// Retry if there were JSON parse errors.
} catch (fmt::v9::format_error& fe) {
std::cerr << "error: " << fe.what() << std::endl;
// Retry if there is a format error.
}
}
sqlite3_finalize(stmt);
Expand Down

0 comments on commit ad5e90e

Please sign in to comment.