Skip to content

Conversation

@ZoteTheMighty
Copy link
Contributor

@ZoteTheMighty ZoteTheMighty commented Mar 25, 2021

We were a bit hasty with the changes that were made to v2.0.0! It seems prudent to circle back and make a few improvements:

  • Reverts the default behavior to throwing the error instead of printing it (this aligns better with expectations from Rodux 1.x)
  • Don't inherit the deferred and immediate abstraction from external codebases. Instead, categorize errors into ones that occur when processing actions with reportReducerError (running reducers on dispatched actions) and ones that occur when updating listeners with reportUpdateError (flushing new state)
  • For the error reporter interface, provide a set of data relevant to each situation. This includes recent actions, store state, and the thrown error
  • Removes error reporting from signal, to try to keep it simple and generic; most usage of rodux is through helper libraries that manage the signal connections, anyway.
  • Updates tests to account for new expected behavior
  • Carves out some overzealous printing logic; users of the error reporter API can opt into it isntead

Remaining work:

  • Documentation of error reporting logic
  • Thunk error logic (wasn't tested previously, so it needs new tests in addition to fixes)
  • Any missing test coverage

error("Actions may not have an undefined 'type' property. " ..
"Have you misspelled a constant? \n" ..
inspect(action), 2)
tostring(action), 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

is tostring() going to give actiomable information when it’s a table with the wrong format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe not! But this is the kind of error that we're much more likely to catch in dev (it was an error in 1.x before). It didn't seem like it justified all of the inspect logic, some of which actually had to be adjusted to work in non-Luau contexts for the sake of this repo's CI

Choose a reason for hiding this comment

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

Is it possible for us to safely get action.name here? That would be more useful than the pointer/id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I follow; action.name doesn't have any particular meaning. The only required structure for an action is that it's a table with a type field (maybe that's what you're thinking of?). This error will only be thrown in the event that an action without a type is dispatched.

I think the way this error happens in practice is if you accidentally dispatch something other than a proper action in your mapDispatchToProps, which would make whatever you were trying to do fail altogether. Hence why I suggested that this is likely an error that folks find and resolve during development.

Choose a reason for hiding this comment

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

Sorry, action.type is the correct nomenclature. In the Lua App codebase we have a "name" argument (ultimately Script.name) that gets assigned to "type" in Action.lua. Makes things a little confusing.

I'm just thinking that it will provide a nicer error message and doesn't require you to go through the expense of visiting the whole table. Not a big deal.

message = "Caught error in reducer with init",
thrownValue = result,
})
self._state = initialState

Choose a reason for hiding this comment

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

I know this is from previous code, but is this state update logic ok? If "not ok then self._state and self._lastState both equal initialState"? If we're resetting, should lastState be the previous lastState?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't be an issue; technically, both things are true. Your last state was the initial state passed into Store.new; your current state is also that, because your reducer threw an error.

error("Actions may not have an undefined 'type' property. " ..
"Have you misspelled a constant? \n" ..
inspect(action), 2)
tostring(action), 2)

Choose a reason for hiding this comment

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

Is it possible for us to safely get action.name here? That would be more useful than the pointer/id.

@ZoteTheMighty ZoteTheMighty requested a review from oltrep March 25, 2021 03:59
Copy link
Contributor

@matthargett matthargett left a comment

Choose a reason for hiding this comment

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

great job on the test coverage!

src/Store.lua Outdated
end
}

local tracebackReporter = function(message)
Copy link

Choose a reason for hiding this comment

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

Suggested change
local tracebackReporter = function(message)
local function tracebackReporter(message)


errorReporter:reportErrorImmediately(message, traceback)
local function tracebackReporter(message)
return debug.traceback(message)
Copy link

Choose a reason for hiding this comment

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

In case an non-string error gets thrown, should we tostring it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm that's a good idea, yeah

it("should throw errors if dispatching while a dispatch is already happening", function()
local store
store = Store.new(function(state, action)
if action.type ~= "@@INIT" then
Copy link

Choose a reason for hiding this comment

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

Little detail but I think it'd be a little clearer if the action type matched the dispatched one

Suggested change
if action.type ~= "@@INIT" then
if action.type == "SomeAction" then

@ZoteTheMighty ZoteTheMighty merged commit d0c21a7 into master Mar 25, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Mar 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants