immer's original function is returning undefined for a proxy object - immer.js

console.log(state, original(state))
prints:
Proxy {0: {…}} undefined
I'm stuck... if I had more time, I'd go into the source to figure out how to re-write original to not fail, but I'm pressed to fix a bug.
Why would original return undefined, if the object is a proxy object?
Important note, this is in a redux toolkit slice function.

Probably you mean console.log(draft, original(draft))?
In Immer 7 you will get an explicit exception if you pass in an undrafted object, rather than getting undefined back, which should help you to catch such problems earlier.
The symbol issue only occurred when using polyfilled symbols and has been fixed in Immer 7 as well.

Related

PyCharm debugger doesn't show objects' content: "Unable to get repr for <type 'list>"

Debugging with PyCharm (happens on multiple versions) I'm unable to correctly view some lists and dictionaries (other are presented correctly).
In the view window the object's name is presented with the message:
{list} Unable to get repr for <type 'list>
or
{dict} Unable to get repr for <type 'dict'>
An update:
In one of my attempts, I received the following message from the debugger (presented instead of the value of one of the list variable):
Unable to display children:Error resolving variables Traceback (most
recent call last): File "/Applications/PyCharm
CE.app/Contents/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line
1004, in do_it
_typeName, valDict = pydevd_vars.resolve_compound_variable(self.thread_id, self.frame_id,
self.scope, self.attributes) TypeError: 'NoneType' object is not
iterable
I'll appreciate any idea as for what may cause this behavior?
Thanks!
It turned out the problem is due to usage of rpyc.py: The process I was debugging was called through rpyc and while I was debugging it, the calling process received a timeout on the rpyc connection.
I think that this caused variables, passed through rpc to lose integrity so the debugger couldn't present them correctly.
The solution was to downgrade rpyc.py to version 3.3.0 (I was on 3.4.2).
My colleague, Nurit Izraelov, correctly suggested the rpyc.py version may be the blame.
Thanks all!
It happened to me sometimes and what caused the behaviour was that some MyClass triggered an exception on its str method.
In such a case, PyCharm debugger only showed
some_object = {MyClass} Unable to get repr for <class 'my_app.models.MyClass'>
So what I did to confirm the origin was to watch repr(some_object) in the Watches section of the debugger. And there it gave me an explicit error message:
{TypeError}%d format: a number is required, not NoneType
Which helped me trace back to the origin.
I appreciate this is not a generic answer, but just a complement to Fabio's.
Probably some custom class of yours has a bad __repr__ or __str__ in it and the debugger is unable to print it.
You can probably use a shell at that point to know which elements are actually inside such a dict or list (and see which object has the faulty __repr__ or __str__).
Extending the scope of the problem rather than adding an answer - all the other suggestions are what I do normally to get this working.
Could it be a race condition?
For me it appears to be something weird. In the Variables pane I can see correct representation for theObject, repr(theObject) and even [theObject] but if I set a variable in my code thus a = theObject or b = [theObject] then I get the "Unable to get repr for <class 'list'>" message.
theObject in this case is an instance of a subclassed D lang struct wrapped with autowrap.

Ruby .include? method is not accepted as a valid method

I have this Ruby code in a script:
$dev_input=gets.chomp.downcase!
if $dev_input.include? "/"
check_developer_commands()
else
puts ">>Invalid Command<<"
continuing_dev_mode()
end
The problem is, whenever I try and run the script containing this, I get an error spat back at me that says :
dev_continue_main.rb:3:in 'continuing_dev_mode': undefined method 'include?' for nil:NilClass (NoMethodError)
Any idea what this error might be? I'm pretty sure that this is the proper way to use the .include? method. I've done some research, looked at tutorialspoint.com and some other sites, but they agree that this is the proper way to use this method.
I checked the error message and it confirmed that the third line in this script/my example is the source of the problem, so it's not some other instance of this method throwing an error.
Any thoughts? Please Help!
The problem is that $dev_input is nil. That stems from applying downcase! in defining $dev_input. I don't know why you want to possibly assign nil to $dev_input, and at the same time claim that calling include? on it is the right way. I don't get your intention for doing that, but if you instead had $dev_input = gets.chomp.downcase, then it wouldn't cause such error.

VoltRB rspec testing a method can't convert Promise into Array

I am trying to do some rspec unit tests on a method in my model. The method returns a promise, and when resolved, the name of the person. The method is not the problem as I know that it works correctly. Here is my test code:
it 'should return correct name' do
report = Report.new(first_name: 'Testy', last_name: 'Testerson')
report.save!
expect(report.name).to eql('Testy Testerson')
end
When I test it, I get the following error:
Failure/Error: expect(report.name).to eql('Testy Testerson')
TypeError:
can't convert Promise to Array (Promise#to_ary gives Promise)
While debugging, I used the following line to inspect the returned value of the method:
puts report.name.inspect
And I got the following response:
#<Promise(70319926955580): "Testy Testerson">
The error seems to be happening because it tests the promise against the expected value. Why am I getting this error?
Using report.name.value fixes this issue
When running code on the server, calls to store return a promise that is already resolved. But on the client the promise won't be resolved yet. Someone (forget the name atm) is working on adding support to promise directly into opal-rspec, but at the moment a returned promise won't wait for opal-rspec. The plan is once thats ready we'll add more tools to volt to make it easier for developers to test in both MRI and opal (like we do with Volt itself).
You can call .value on a promise to get back its value, but only if the promise has resolved. The safer way to do it is to use a .then block:
report.name.then do |name|
expect(name).to eq('Bob')
end
Hopefully that helps.

Why "Missing return statement" is not handled in languages?

Today I was getting introduced to Dart myself. At a point while playing with it, something was going wrong. Later I found that it was nothing but I forgot to put return statement in a function so null was set to the variable that was supposed to get value from that function.
At that point I was thinking, in Java it would be caught as error in the very first place. Why C/C++ or the new Dart don't add this feature? Does this feature slows the code down at a large scale? Or there are any other technical reasons behind this?
Every method returns a value, and if there is no return it is null.
However it looks like this some enhancements could be done in the future. See issue 73 : Missing return statement does not trigger warning or error and issue 13373 : Can get the editor to warn when there is no explicit return for a function returning a type.

Capybara debug, don't even know where has this error

I am debugging, then the error message pop up like following:
http://127.0.0.1:56121/apps/quicktip/quicktip_model.js|84|=============================checkShownBefore
Started request to "http://127.0.0.1:56121/apps/quicktip/ejs/quicktip.ejs"
Received 200 from "http://127.0.0.1:56121/apps/quicktip/ejs/quicktip.ejs"
http://127.0.0.1:56121/apps/quicktip/quicktip_model.js|31|=============_setTip
http://127.0.0.1:56121/apps/quicktip/quicktip_controller.js|153|======================currentTip
http://127.0.0.1:56121/apps/quicktip/quicktip_controller.js|153|==============finish currentTip
http://127.0.0.1:56121/apps/quicktip/quicktip_model.js|31|=============_setTip
http://127.0.0.1:56121/apps/quicktip/quicktip_controller.js|153|======================currentTip
http://127.0.0.1:56121/apps/quicktip/quicktip_controller.js|153|==============finish currentTip
undefined|0|TypeError: 'undefined' is not a function
It didn't even mention which file is complaining the type error, I tried to use console.log in quicktip_controller.js, to see whether there is anything wrong after this page. But I can get nothing. Any suggestion??
Suggestion is that the undefined is valid in js, but invalid for pure rails environment. So you haveto look into apps/quicktip/ejs/quicktip.ejs or around files for the occurines of undefined keyword in ruby code.

Resources