GJS gnome-shell exception error, how to overcome this error - gnome-shell

I would like to learn what this error message is.
imports.ui.dateMenu.DateMenuButton.prototype.hide()
When I run above in lookingGlass, I get below error
<exception Error: Can't convert to pointer on .Gjs_ui_dateMenu_DateMenuButton.prototype; only on instances>
Can any one explain in detail.
Thanks.

JavaScript has prototypal inheritance — meaning that DateMenuButton.prototype is an object that contains DateMenuButton's methods, but it is not a DateMenuButton itself. So when you call DateMenuButton.prototype.hide(), you are calling DateMenuButton's hide() method on an object that is not a DateMenuButton. This will give you an error. The error message is not particularly clear but "can't ___ on prototype, only on instances" is a hint about what's going on.
To call this method, you will need an actual DateMenuButton object.
Here is some further reading material on prototypal inheritance: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain

Related

Barbecue Barcode PDF417

I need to generate a PDF417 barcode with error correction level of 5 using Barbecue api.
I generate a PDF417 by calling createPDF417(data) on the BarcodeFactory and this returns a barcode object which is passed to my print formatting class as a ByteArrayOutputStream, but I'm struggling to see how/if it implements any error correction level and if i can set this anywhere. I can see methods in the PDF417Module class (createCodeWords and generateEC) that look like what i'm expecting. I just cant see how the draw method in the PDF417Module class is actually called.
I apologise, I'm a relative novice.
I've had a weekend off and done some drinking and some sleeping and now I see the PDF417Module is instantiated and the method called. I now feel embarrassed for asking.

Ruby test failure with exception

I have some tests in ruby which call some framework methods and classes. The problem I'm facing, is that some methods can throw exceptions, since they contact services not in my control. I want in the teardown method of the test to actually have the result of the test (success, failed with XXX), so I can do some stuff based on that. Is there a way I can do that (different from wrapping the whole test in a begin/rescue block) ?
A code example of what you're trying to test might help. But depending on the framework API you're working with you can stub out the method that tries to contact the service, that would raise the exception. If you are calling one method that you are trying to test, and it also raises an exception (not very DRY/SRP code) then it makes it tricky. If that's the case, can either do a begin/rescue around that method call, or stub out the call to that larger method. The problem with doing the latter is it can obscure the value of your test more.

Is it possible to catch an "object not initialized" exception in Dynamics AX?

Problem:
I have some code that is failing because an object has not been initialized. The solution for this bug is easy to fix, when detected. However, what surprised me is that my elaborate exception handling didn't catch this exception. That meant the exception wasn't logged or handled, and code following the try catch block was never executed. The try...catch block was outside of the transaction, so there was no issue there.
In this particular case, the exception was inside a batch (RunBaseBatch) job. The job handled several unrelated processing tasks. Once the exception conditions were met, the job terminated, so the other unrelated processing tasks were never called.
Does anyone know if it is possible to catch an "object not initialized" exception in Dynamics AX 2009? I read one post that said it may not be possible to catch certain exceptions in AX, however, I hope that is not the case (reference: https://community.dynamics.com/product/ax/f/33/p/16352/23700.aspx#23700).
Code example:
Here is some simplistic code that recreates the issue:
server static void main(Args args)
{
Array arr;
;
info ("debug: before try...catch");
try
{
// ttsbegin; // enable/disable to test with transactions
// arr = new Array(Types::String); // Enabling this line will prevent the exception
arr.exists(3);
// ttscommit; // enable/disable to test with transactions
}
catch (Exception::Internal) // This exception handler was the Magic Sauce!!
{
info ("debug: catch (Exception::Internal)");
}
catch (Exception::Error)
{
info ("debug: catch (Exception::Error)");
}
catch
{
info ("debug: catch");
}
info ("debug: after try...catch");
}
UPDATE 2013-01-29
I am waiting to accept an answer until this question has been viewed more. Thank you for the answers so far.
I know the example I gave was simplistic. This type of bug is easily fixable when it is known. And defensive programming is always a good idea.
However, in the real world, the code where the bug occurred was very complex. The error occurred several levels deep in an overloaded method of a subclass. It occurred in a specific scenario, when an overloaded method corrupted the protected value of a member variable from the super class. That is where the bug occurred in the code, however, it didn't manifest itself until the super class tried to use the member variable again. The bug was summarily fixed when it was detected and tracked down.
Defensively, yes you could check every protected member variable, every time you use it, but that does start to impact performance, code readability, practicality, etc., which is why languages offer exception handling.
The question here, is how can these type of bugs be caught to make code more robust and bullet-proof? In most development environments (C, C++, C#, or Java for example), a try...catch at a top level could be used to catch, log, and clean up ALL unexpected exceptions. So the code would be able to continue processing with the other unrelated tasks. AX is continuing at some level, because the whole system doesn't come to a grinding halt when this bug occurs. However, the code after the catch in this job is not executing because of what appears to be a deficiency in AX/X++.
I am looking for an innovative solution or work-around, if it exists, to catch the "object not initialized" exception (really ALL exceptions) and to continue processing.
You cannot "catch" it in the traditional sense, but you can avoid it happening. Simply test if the object exists before running anything from it:
if(object)
{
// Exists; Execute statements with object here
}
else
{
// Doesn't exist
}
This works because object will be translated as null if it is not initialized.
(Null == 0) == false
If the object is initialized it will have some value other than null.
(!Null != 0) == true
Hope that helps!
You can, but you shouldn't. A behavior like this is almost certainly a bad design of your code, that will inevitably end in more problems in the future.
You need to make your code defensive to this case, making sure the object is instanciated before using it. Otherwise, you're using the catch code to an expected behavior, wich makes no sense.
EDIT 2013/02/18
In complex scenarios like what you're describing, it's usually very hard to get a solution fully controlled. In AX, try..catch statement is quite simplified and in a very large range of situations is not really needed (unlike Java, C#, ... where is always recommended).
This simplification is nice in almost all situations of AX development, as you don't need to waste time on exception handling. Just let them raise, and the InfoLog will handle them on a simple and reliable way.
The big problem comes where you really need this control... when there is not really a way of force it. I'm not sure if this is really an standard issue or it's espected by the product team to work that way, but this cases are always giving troubles in AX. When you need to catch some specific issue you have to be very creative and deffensive to prevent the exception as catching it will become even more creative...
Hope this helps :)
To elaborate a little, as stated in the post you linked to you cannot catch an Object Not Initialized error. However, you can "fix" the code by adding a simple check before attempting to run functions against a variable that you do not control (for example, if you are requesting an Array type as an argument for a function and you expect the function to be called from outside the class).
try
{
if (arr)
arr.exists(3);
}
The if(arr) statement is enough to skip the processing if the object has not yet been instantiated, effectively bypassing the error. However, this will obviously not throw the error further up the chain. If you really wanted, you could make it throw a different error that can be caught, but obviously that is less than ideal.
In this case, since the RunBaseBatch class may not be something you want to modify it would probably be better to make sure the object that is causing the issue is correctly defined before calling the problem method, and finding these errors in testing.

Out parameters of user defined types in Oracle with BLToolkit

I have been trying to use BLToolkit to activate an Oracle stored procedure which takes a User Defined Type as an argument as an output parameter and changes it.
I have managed to do this on a primitive type, and and also by manually calling SetSpCommamd however I would like to use the abstract class generation method but can't seem to get it to work.
I'm pretty sure the code I wrote is correct (works for the primitive). When debugging I found the SetSpCommamd called by the generated code gets wierd parameters instead of the ones I provided as opposed to when I call the method manually (the it gets the exact parameters I'd like). I wish I could see the code generated by the reflection emit to see what's wrong there.
Can anyone please help me figure out why this is not working?
Found the problem (Potentially a bug in BLToolkit).
BLToolkit does not pass the UDT Class as is to the procedure (instead it tries to flatten it or something and pass the insides of the object). I Changed the object to a Struct instead of a Class and that fixed it.
Later on I also changed it back to class and made a patch in the 'IsScaler()' method in BLToolkits code.
I will report this as a Bug I hope they fix it.

Indentify the error: Object reference not set to an instance of an object

Given this stack
net4/IIS7.x
MVC3
nHibernate
Unity
But short of starting from scratch and producing a perfectly unit tested project, is there a strategy (or app/module) to eliminating the generic msg Object reference not set to an instance of an object. and throwing something more specific? Something akin to what ELMAH can do with exceptions?
thx
Looking at the exception stack trace and identifying the exact line where the exception is thrown is the best indication to pinpoint the problem. When you have identified the line of code on which this exception is thrown you will already have a strong indication of its origin. Narrowing it down to a simple project always help if you are not able to understand why it might occur. Given the stack you have shown there is close to ∞ possibilities of why this might be happening.
Don't expect to get anything more specific than this exception and the line on which it occurs.

Resources