iOS JavascriptCore exception detailed stacktrace info - swift

It seems the exception stacktrace in iOS only contains the method name or there is a bug. Below is my code of handling exceptions in JSContext.
context.exceptionHandler = { (ctx: JSContext!, value: JSValue!) in
// type of String
let stacktrace = value.objectForKeyedSubscript("stack").toString()
// type of Number
let lineNumber = value.objectForKeyedSubscript("line")
// type of Number
let column = value.objectForKeyedSubscript("column")
let moreInfo = "in method \(stacktrace)Line number in file: \(lineNumber), column: \(column)"
Logger.error("JS ERROR: \(value) \(moreInfo)")
}
And I got logs like below
ERROR : JSContextRenderer.swift:308 : setupContext : JS ERROR: Error in method clearBackground
Line number in file: 162, column: 12"
Note there is a new line right after the "clearBackground" name, I think there probably more information there.
Can anybody having similar experience confirm? Any help is appreciated. Thanks.

Looks like it does show more information in the stack. Here is one of the log information I got:
JS ERROR: TypeError: undefined is not a function (evaluating 'msg.__assert__()') in method assert
syncShots
updateSync
initSync
setState
onLogicStateChanged
onLogicStateChanged
[native code]
updateMove
sendMove
shoot
onTouchUp
[native code]
_handleEvent
_dispatchEvent
. Line number in file: 183, column: 20

Long ago, #igrek asked where the keys in value come from. They're part of the Error object that was thrown by the JavaScript engine, and that now appears as value in the native error handler callback. What exactly Error includes depends on the implementation, but typically includes message, fileName, and lineNumber. It appears that stack is also supported. More details on the MDN page for Error .

Related

Keep getting 'Unexpected identifier' when running tests

I am trying to copy a tutorial for a Wordle solving bot but its just not going well. whenever I try to run a test on the code it doesn't work at certain points, I'll either get 'Uncaught SyntaxError: Unexpected identifier'. I'm doing this on UIlicious.
Here's what I've got so far:
I.goTo("https://www.powerlanguage.co.uk/wordle/")
I.click("reject")
I.see("Guess the Wordle")
I.click('/html/body', 40, 80)
let guessWord = null
for(Let r=0 ; r<6 ; ++r) {
guessWord = solver.suggestWord(gameState)
I.type(guessWord);
I.pressEnter()
I.wait(2)
}
let rowList = document.querySelector("game-app").shadowRoot. //
querySelector("game-theme-manager"). //
querySelector("#board").querySelectorAll("game-row");
you are probably referring to the article I wrote here : https://uilicious.com/blog/automate-wordle-via-uilicious/
This test script, is designed specifically to use uilicious.com, so you will need to edit and run it through the platform.
You can do so via the snippet here : https://snippet.uilicious.com/test/public/N5qZKraAaBsAgFuSN8wxCL
If you have syntax error there, do let me know with a snippet link - and I will try to help you respectively.
Also the snippet you provided so far, excludes the "solver" class which was initialised much further down.

Manipulate StackTrace in dart

Summary:
I have a stacktrace in dart, where I want to remove frame #0, and then have the whole stacktrace adjust (frame #1 is now frame #0, frame #2 is now frame #1).
Details:
I have written my own assert type function in dart, that if fails, will grab the current stacktrace and send to crashlytics.
static void asrt(bool condition)
{
if (condition)
return;
StackTrace stacktrace = StackTrace.current;
Crashlytics.instance.recordError("assert triggered" , stacktrace);
}
The problem is that crashlytics identifies each error based on the first stackframe. So all of my errors are being identified as that same error, because I am grabbing the stacktrace from the same method. I understand I could pass the stacktrace from the caller, but a preferrable solution to me would be to manipulate the stacktrace so the caller does less work.
Is this doable in dart?
I ended up getting a reliable solution.
I used the stack_trace library and its provided classes Trace and Frame.
In the following example, trace.frames returns an imutable list, so I perform a deep copy. I am ok with this as it only runs on a crash anyways.
StackTrace stacktrace = StackTrace.current;
Trace trace = Trace.from(stacktrace);
List<Frame> frames = trace.frames;
List<Frame> newFrames = List<Frame>();
// start at index 1 to omit frame #0
for (int i = 1; i < frames.length; i++) {
Frame f = frames[i];
newFrames.add(Frame(f.uri , f.line , f.column , f.member));
}
Trace newTrace = Trace(newFrames);
I can't recommend it, but you could use StackTrace.toString(), do text manipulation on it, and then use StackTrace.fromString to get a StackTrace object back.
But really I suggest that you file an issue against firebase_crashlytics and request some mechanism to allow considering more than the first frame.

How do I print a message if a ValueError occurs?

while answers_right < 3:
ran_number_1 = random.randint(10, 99)
ran_number_2 = random.randint(10, 99)
solution = ran_number_1 + ran_number_2
print(f"What is {ran_number_1} + {ran_number_2}?")
user_answer = int(input("Your answer: "))
if user_answer == solution:
answers_right += 1
print(f"Correct. You've gotten {answers_right} correct in a row.")
elif user_answer != solution:
answers_right = 0
print(f"Incorrect. The expected answer is {solution}.")
if answers_right == 3:
print("Congratulations! You've mastered addition.")
I want to add an additional if statement in case someone types string and return a message that says "Invalid Response" instead of the Traceback Error.
Use of Exception handling in python may be solve your Problem and you can also generate your own error class for particular condition.
if x < 3:
raise Exception("Sorry, no numbers below 3")
Use of throw and raise keyword you can generate your own error.
for more referencelink here
The correct way to solve this problem is to look at the error type in your traceback, and use a try/except block. It will say something like TypeError: error stuff here or ValueError: error stuff also here.
The way you do a try/except is to:
try:
some_code()
that_might()
produce_an_error()
except some_error_type:
do_stuff()
except_some_other_error_type:
do_other_stuff()
So, to catch a ValueError and a TypeError, you might do:
try:
buggy_code()
except ValueError:
print("Woah, you did something you shouldn't have")
except TypeError:
print("Woah, you did something ELSE you shouldn't have")
If you then want the traceback, you can add in a lone "raise" statement below the excepts. For example:
try:
buggy_code()
except ValueError:
print("Woah, you did something you shouldn't have")
raise
except TypeError:
print("Woah, you did something ELSE you shouldn't have")
raise
Errors have evolved to be a lot more useful in modern times. They don't break the entire system anymore, and there are ways of handling them. Try/Except blocks like the above give you the tools to have code that only executes when a specific error or set of errors is raised.

Joomla 3.3: Get data from column 'attribs' in the table 'content'

I'm using the Aixeena Easy CCK-plugin in my Joomla 3.3-website. It's a plugin that allows me to add custom fields in my Article Edit-page. The content I fill out there (should) show up on my website. The plugin stores his information in the #_content table in the attribs column.
On their website, Aixeena says that I have to use the following code to make the filled out text visible on my website:
$attrb = json_decode($this->item->attribs);
echo $attrb->fieldname;
This code drops the following error:
Notice: Undefined property: JDocumentHTML::$item in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Fatal error: Call to a member function get() on a non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 124
I think it is written for an older version of Joomla. Then I searched around and found this code:
$params = $this->item->params;
echo $params->get('fieldname');
When I use this code on my site, it gives me the following error's:
Notice: Undefined property: JDocumentHTML::$item in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 123
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/buutpot/templates/buutpot.nl-standaardtemplate/index.php on line 124
That's without a fatal error. I'm not sure why it is without.
Could anybody help me out getting the right code to get my variable out of the table? Thanks in advance!
EDIT 1: Link to the plugin: http://www.aixeena.org/aixeena-lab/aixeena-easy-cck
EDIT 2: Edited my question in reply on the comment of Elin.
So like the notices say, the problem is that $this->item does not exist. You need to figure out what the actual name of the object is and use that rather than $this->item. You will probably do that by looking in the layout of whereever it is that you are trying to display. Can you please check your template to see if it has a layout override for the article view (assuming that is the view you are trying to access the form from)?
I used this code to do a query on the database:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('attribs');
$query->from($db->quoteName('#__content'));
$query->where($db->quoteName('id')." = ".JRequest::getInt('id'));
$db->setQuery($query);
$attribs = $db->loadResult();
$attribs = json_decode($attribs, 'true');
$firstattr = $attribs['firstattr'];
$secondattr = $attribs['secondattr'];
$thirdattr = $attribs['thirdattr'];
$fourthattr = $attribs['fourthattr'];
But I'm sure this can be done simpler.
$attribs = new JRegistry($article->attribs);
echo $fieldname = $attribs['fieldname'];
For example, I use this code in on ContentPrepare like this
function onContentPrepare($context, &$article, &$params, $page) {
$attribs = new JRegistry($article->attribs);
//url is my custom field for the content
$url = $attribs['url'];
......

Errors in my code

Alright, I have a couple error messages and I am stuck. Just seeing if anybody could help me out here, it would be greatly appreciated.
Here is the error message:
bibleajax.cpp: In function Ă¢int main():
bibleajax.cpp:92: error: no matching function for call to Bible::lookup(Verse&, LookupResult&)
Bible.h:32: note: candidates are: const Verse Bible::lookup(Ref, LookupResult&)
make: * [bibleajax.o] Error 1
Here is line 92:
Ref nRef;
Verse nVerse;
for (int t = 0; t < num; t++){
do {
nRef = kjv.lookup(nVerse, result);
nVerse = kjv.lookup(nRef, result);
}
while (result != ch && result != no_chapter);
It would appear that your Verse class does not have a member function called getRef(). You also appear to be trying to call the lookup function by passing it a Verse object instead of a Ref object... but that piece of code doesn't seem to be included in what you've posted here.
Note that the relevant line numbers for the code are posted in the error messages. So check lines 79 and 92 for the issues I mentioned here.