Monday, September 9, 2019

Debugging Announcement issues in Amber Smalltalk

And while developing, is normal to rename a class.
Today I've was working with a product and I had this announcement class with a typo OrdedProductEditRejected which I've renamed to OrderedProductEditRejected.
None of the current Amber IDE's have a refactoring tool to help you to rename globally and changing the methods that are using the class, so you have to go old school and rename in every place yourself.
So far so good. Until you forget to rename it in one method and your app uses that.
What happens in the method using the old name, is that you get nil there and the announcer will throw an exception (nil does not understand #name).
Trying to find references of the class doesn't work anymore because it already has the new name. And if you forgot the exact previous name, the search for references will not help.
So what do you do!?
In flow based applications, the App class implements on:do: in this way:
App>>on: ann do: aBlock

  self announcer on: ann do: aBlock
So every time your code subscribes to observe an event it will send that message. Knowing that, you can debug this kind of problem by setting a halt so when the announcement class is nil it stops and you know what to fix.
This is how it looks:
App>>on: ann do: aBlock

  ann ifNil: [ self halt ].

  self announcer on: ann do: aBlock
With that, you use your application and when it halts, you'll see in the debugger's stack the sender you forgot to correct.


No comments:

Post a Comment