Skip to content

Commit

Permalink
Fix error type naming consistency and punctuation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkl1337 committed Mar 6, 2024
1 parent 0f3e0db commit fdd18c7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
12 changes: 6 additions & 6 deletions ckiwi/ckiwi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ static const constexpr KiwiErr kKiwiErrUnhandledCxxException {

static const constexpr KiwiErr kKiwiErrNullObjectArg0 {
KiwiErrNullObject,
"null object passed as argument #0 (self)"
"null object passed as argument #0 (self)."
};

static const constexpr KiwiErr kKiwiErrNullObjectArg1 {
KiwiErrNullObject,
"null object passed as argument #1"
"null object passed as argument #1."
};

template<typename F>
Expand Down Expand Up @@ -76,14 +76,14 @@ const KiwiErr* wrap_err(F&& f) {

} catch (const UnknownEditVariable& ex) {
static const constexpr KiwiErr err {
KiwiErrUnknownEditVariable,
KiwiErrUnknownEditVar,
"The edit variable has not been added to the solver."
};
return &err;

} catch (const DuplicateEditVariable& ex) {
static const constexpr KiwiErr err {
KiwiErrDuplicateEditVariable,
KiwiErrDuplicateEditVar,
"The edit variable has already been added to the solver."
};
return &err;
Expand Down Expand Up @@ -161,9 +161,9 @@ void kiwi_str_release(char* str) {
std::free(str);
}

void kiwi_err_release(const KiwiErr* err) {
void kiwi_err_release(KiwiErr* err) {
if (lk_likely(err && err->must_release))
std::free(const_cast<KiwiErr*>(err));
std::free(err);
}

KiwiVar* kiwi_var_new(const char* name) {
Expand Down
6 changes: 3 additions & 3 deletions ckiwi/ckiwi.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ enum KiwiErrKind {
KiwiErrUnsatisfiableConstraint = 1,
KiwiErrUnknownConstraint,
KiwiErrDuplicateConstraint,
KiwiErrUnknownEditVariable,
KiwiErrDuplicateEditVariable,
KiwiErrUnknownEditVar,
KiwiErrDuplicateEditVar,
KiwiErrBadRequiredStrength,
KiwiErrInternalSolverError,
KiwiErrAlloc,
Expand Down Expand Up @@ -78,7 +78,7 @@ struct KiwiSolver;
LJKIWI_EXP void kiwi_solver_type_info(unsigned sz_align[2]);

LJKIWI_EXP void kiwi_str_release(char* str);
LJKIWI_EXP void kiwi_err_release(const KiwiErr* err);
LJKIWI_EXP void kiwi_err_release(KiwiErr* err);

LJKIWI_EXP KiwiVar* kiwi_var_new(const char* name);
LJKIWI_EXP void kiwi_var_release(KiwiVar* var);
Expand Down
22 changes: 11 additions & 11 deletions kiwi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ enum KiwiErrKind {
KiwiErrUnsatisfiableConstraint = 1,
KiwiErrUnknownConstraint,
KiwiErrDuplicateConstraint,
KiwiErrUnknownEditVariable,
KiwiErrDuplicateEditVariable,
KiwiErrUnknownEditVar,
KiwiErrDuplicateEditVar,
KiwiErrBadRequiredStrength,
KiwiErrInternalSolverError,
KiwiErrAlloc,
Expand Down Expand Up @@ -110,7 +110,7 @@ typedef struct KiwiErr {
struct KiwiSolver;
void kiwi_str_release(char *);
void kiwi_err_release(const KiwiErr *);
void kiwi_err_release(KiwiErr *);
KiwiVar* kiwi_var_new(const char* name);
void kiwi_var_release(KiwiVar* var);
Expand Down Expand Up @@ -173,8 +173,8 @@ end
---| '"KiwiErrUnsatisfiableConstraint"' # The given constraint is required and cannot be satisfied.
---| '"KiwiErrUnknownConstraint"' # The given constraint has not been added to the solver.
---| '"KiwiErrDuplicateConstraint"' # The given constraint has already been added to the solver.
---| '"KiwiErrUnknownEditVariable"' # The given edit variable has not been added to the solver.
---| '"KiwiErrDuplicateEditVariable"' # The given edit variable has already been added to the solver.
---| '"KiwiErrUnknownEditVar"' # The given edit variable has not been added to the solver.
---| '"KiwiErrDuplicateEditVar"' # The given edit variable has already been added to the solver.
---| '"KiwiErrBadRequiredStrength"' # The given strength is >= required.
---| '"KiwiErrInternalSolverError"' # An internal solver error occurred.
---| '"KiwiErrAlloc"' # A memory allocation error occurred.
Expand Down Expand Up @@ -1139,7 +1139,7 @@ do
--- This method should be called before the `suggestValue` method is
--- used to supply a suggested value for the given edit variable.
--- Errors:
--- KiwiErrDuplicateEditVariable
--- KiwiErrDuplicateEditVar
--- KiwiErrBadRequiredStrength: The given strength is >= required.
---@param var kiwi.Var the variable to add as an edit variable
---@param strength number the strength of the edit variable (must be less than `Strength.REQUIRED`)
Expand All @@ -1153,7 +1153,7 @@ do
--- This method should be called before the `suggestValue` method is
--- used to supply a suggested value for the given edit variable.
--- Errors:
--- KiwiErrDuplicateEditVariable
--- KiwiErrDuplicateEditVar
--- KiwiErrBadRequiredStrength: The given strength is >= required.
---@param vars kiwi.Var[] the variables to add as an edit variable
---@param strength number the strength of the edit variables (must be less than `Strength.REQUIRED`)
Expand All @@ -1164,7 +1164,7 @@ do

--- Remove an edit variable from the solver.
--- Raises:
--- KiwiErrUnknownEditVariable
--- KiwiErrUnknownEditVar
---@param var kiwi.Var the edit variable to remove
---@return kiwi.Var var, kiwi.Error?
function Solver_cls:remove_edit_var(var)
Expand All @@ -1173,7 +1173,7 @@ do

--- Removes edit variables from the solver.
--- Raises:
--- KiwiErrUnknownEditVariable
--- KiwiErrUnknownEditVar
---@param vars kiwi.Var[] the edit variables to remove
---@return kiwi.Var[] vars, kiwi.Error?
function Solver_cls:remove_edit_vars(vars)
Expand All @@ -1185,7 +1185,7 @@ do
--- to suggest the value for that variable. After all suggestions have been made,
--- the `update_vars` methods can be used to update the values of the external solver variables.
--- Raises:
--- KiwiErrUnknownEditVariable
--- KiwiErrUnknownEditVar
---@param var kiwi.Var the edit variable to suggest a value for
---@param value number the suggested value
---@return kiwi.Var var, kiwi.Error?
Expand All @@ -1196,7 +1196,7 @@ do
--- Suggest values for the given edit variables.
--- Convenience wrapper of `suggest_value` that takes tables of `kiwi.Var` and number pairs.
--- Raises:
--- KiwiErrUnknownEditVariable: The given edit variable has not been added to the solver.
--- KiwiErrUnknownEditVar: The given edit variable has not been added to the solver.
---@param vars kiwi.Var[] edit variables to suggest
---@param values number[] suggested values
---@return kiwi.Var[] vars, number[] values, kiwi.Error?
Expand Down
28 changes: 14 additions & 14 deletions spec/solver_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("solver", function()
assert.True(kiwi.is_error(err))
assert.True(kiwi.is_solver(err.solver))
assert.equal(v1, err.item)
assert.equal("KiwiErrDuplicateEditVariable", err.kind)
assert.equal("KiwiErrDuplicateEditVar", err.kind)
assert.equal("The edit variable has already been added to the solver.", err.message)
end)

Expand All @@ -73,7 +73,7 @@ describe("solver", function()
end)

it("should return errors for duplicate variables", function()
solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrBadRequiredStrength" })
solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrBadRequiredStrength" })
local ret, err = solver:add_edit_var(v1, kiwi.strength.STRONG)
assert.Nil(err)

Expand All @@ -84,13 +84,13 @@ describe("solver", function()
---@diagnostic disable: need-check-nil
assert.True(kiwi.is_solver(err.solver))
assert.equal(v1, err.item)
assert.equal("KiwiErrDuplicateEditVariable", err.kind)
assert.equal("KiwiErrDuplicateEditVar", err.kind)
assert.equal("The edit variable has already been added to the solver.", err.message)
---@diagnostic enable: need-check-nil
end)

it("should return errors for invalid strength", function()
solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrBadRequiredStrength" })
solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrBadRequiredStrength" })

---@diagnostic disable: need-check-nil
local ret, err = solver:add_edit_var(v2, kiwi.strength.REQUIRED)
Expand Down Expand Up @@ -154,7 +154,7 @@ describe("solver", function()
assert.True(kiwi.is_error(err))
assert.True(kiwi.is_solver(err.solver))
assert.equal(v2, err.item)
assert.equal("KiwiErrDuplicateEditVariable", err.kind)
assert.equal("KiwiErrDuplicateEditVar", err.kind)
assert.equal("The edit variable has already been added to the solver.", err.message)
end)

Expand All @@ -170,7 +170,7 @@ describe("solver", function()
end)

it("should return errors for duplicate variables", function()
solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrBadRequiredStrength" })
solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrBadRequiredStrength" })
local ret, err = solver:add_edit_vars({ v1, v2, v3 }, kiwi.strength.STRONG)
assert.Nil(err)

Expand All @@ -181,13 +181,13 @@ describe("solver", function()
---@diagnostic disable: need-check-nil
assert.True(kiwi.is_solver(err.solver))
assert.equal(v1, err.item)
assert.equal("KiwiErrDuplicateEditVariable", err.kind)
assert.equal("KiwiErrDuplicateEditVar", err.kind)
assert.equal("The edit variable has already been added to the solver.", err.message)
---@diagnostic enable: need-check-nil
end)

it("should return errors for invalid strength", function()
solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrBadRequiredStrength" })
solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrBadRequiredStrength" })
arg = { v2, v3 }
local ret, err = solver:add_edit_vars(arg, kiwi.strength.REQUIRED)
assert.equal(arg, ret)
Expand Down Expand Up @@ -239,12 +239,12 @@ describe("solver", function()
assert.True(kiwi.is_error(err))
assert.True(kiwi.is_solver(err.solver))
assert.equal(v2, err.item)
assert.equal("KiwiErrUnknownEditVariable", err.kind)
assert.equal("KiwiErrUnknownEditVar", err.kind)
assert.equal("The edit variable has not been added to the solver.", err.message)
end)

it("should return errors if requested", function()
solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrUnknownEditVariable" })
solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrUnknownEditVar" })

local ret, err = solver:remove_edit_var(v1)

Expand All @@ -253,7 +253,7 @@ describe("solver", function()
---@diagnostic disable: need-check-nil
assert.True(kiwi.is_solver(err.solver))
assert.equal(v1, err.item)
assert.equal("KiwiErrUnknownEditVariable", err.kind)
assert.equal("KiwiErrUnknownEditVar", err.kind)
assert.equal("The edit variable has not been added to the solver.", err.message)
---@diagnostic enable: need-check-nil
end)
Expand Down Expand Up @@ -304,12 +304,12 @@ describe("solver", function()
assert.True(kiwi.is_error(err))
assert.True(kiwi.is_solver(err.solver))
assert.equal(v2, err.item)
assert.equal("KiwiErrUnknownEditVariable", err.kind)
assert.equal("KiwiErrUnknownEditVar", err.kind)
assert.equal("The edit variable has not been added to the solver.", err.message)
end)

it("should return errors for unknown variables", function()
solver:set_error_mask({ "KiwiErrDuplicateEditVariable", "KiwiErrUnknownEditVariable" })
solver:set_error_mask({ "KiwiErrDuplicateEditVar", "KiwiErrUnknownEditVar" })
local ret, err = solver:add_edit_vars({ v1, v2 }, kiwi.strength.STRONG)
assert.Nil(err)

Expand All @@ -320,7 +320,7 @@ describe("solver", function()
---@diagnostic disable: need-check-nil
assert.True(kiwi.is_solver(err.solver))
assert.equal(v3, err.item)
assert.equal("KiwiErrUnknownEditVariable", err.kind)
assert.equal("KiwiErrUnknownEditVar", err.kind)
assert.equal("The edit variable has not been added to the solver.", err.message)
---@diagnostic enable: need-check-nil
end)
Expand Down

0 comments on commit fdd18c7

Please sign in to comment.