-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cli) prefix Cassandra connector errors in new DAO #3648
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ function DB.new(kong_config, strategy) | |
error("strategy must be a string", 2) | ||
end | ||
|
||
strategy = strategy or kong_config.database | ||
|
||
-- load errors | ||
|
||
local errors = Errors.new(strategy) | ||
|
@@ -81,6 +83,7 @@ function DB.new(kong_config, strategy) | |
daos = daos, -- each of those has the connector singleton | ||
strategies = strategies, | ||
connector = connector, | ||
strategy = strategy, | ||
} | ||
|
||
do | ||
|
@@ -103,6 +106,11 @@ function DB.new(kong_config, strategy) | |
end | ||
|
||
|
||
local function prefix_err(self, err) | ||
return "[" .. self.strategy .. " error] " .. err | ||
end | ||
|
||
|
||
function DB:init_connector() | ||
-- I/O with the DB connector singleton | ||
-- Implementation up to the strategy's connector. A place for: | ||
|
@@ -111,27 +119,52 @@ function DB:init_connector() | |
-- - prepare statements | ||
-- - nop (default) | ||
|
||
return self.connector:init() | ||
local ok, err = self.connector:init() | ||
if not ok then | ||
return nil, prefix_err(self, err) | ||
end | ||
|
||
return ok | ||
end | ||
|
||
|
||
function DB:connect() | ||
return self.connector:connect() | ||
local ok, err = self.connector:connect() | ||
if not ok then | ||
return nil, prefix_err(self, err) | ||
end | ||
|
||
return ok | ||
end | ||
|
||
|
||
function DB:setkeepalive() | ||
return self.connector:setkeepalive() | ||
local ok, err = self.connector:setkeepalive() | ||
if not ok then | ||
return nil, prefix_err(self, err) | ||
end | ||
|
||
return ok | ||
end | ||
|
||
|
||
function DB:reset() | ||
return self.connector:reset() | ||
local ok, err = self.connector:reset() | ||
if not ok then | ||
return nil, prefix_err(self, err) | ||
end | ||
|
||
return ok | ||
end | ||
|
||
|
||
function DB:truncate() | ||
return self.connector:truncate() | ||
local ok, err = self.connector:truncate() | ||
if not ok then | ||
return nil, prefix_err(self, err) | ||
end | ||
|
||
return ok | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. considering the repetitive nature of this error checking, could we do something like: local function prefix_err(self, ok, err, ...)
if not ok then
return ok, "[" .. self.strategy .. " error] " .. err
end
return ok, err, ...
end
-- and calling it here (and in other places) as:
return prefix_err(self, self.connector:truncate()) can probably be cleaner if exporting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considered it, but I don't want to introduce the extra cost of calling a variadic function on every call of the connector's functions. Five occurrences, and it is unlikely that we add more methods to the connector, is not that repetitive is what I told myself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought so 😄 |
||
end | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the exact same change done in my codebase here as I work on the Plugins entity. :) We really need to start making smaller PRs with this little "minor tweaks" as we work through major changes!