Charcoal-SE / metasmoke

Web dashboard for SmokeDetector.
https://metasmoke.erwaysoftware.com
Creative Commons Zero v1.0 Universal
43 stars 34 forks source link

Backtrace from API query; post 81600 has no username #277

Closed tripleee closed 6 years ago

tripleee commented 6 years ago

I have a code path from Halflife which crashes every time.

The traceback is a humongous pile of HTML which I am attaching here.

The request is

/api/posts/91435;91109;84856;83871;83119;83038;81600;81461;80727;79419

The beef of the error message seems to be in

Showing /var/railsapps/metasmoke/releases/20171031015321/app/views/posts/_post.json.jbuilder where line #7 raised:
    undefined method `username' for nil:NilClass
tripleee commented 6 years ago

I managed to pare it down to a simpler test case which triggers on post 81600.

#!/usr/bin/env python

import json
import halflife

with open('halflife.conf') as conffile:
    conf = json.loads(conffile.read())
h = halflife.Halflife(conf['metasmoke-key'])
for idx in [91435, 91109, 84856, 83871, 83119, 83038, 81600, 81461, 80727, 79419]:
    try:
        print('# trying {0}'.format(idx))
        post = {'id': str(idx)}
        h.get_post_metainformation(post)
    except KeyboardInterrupt:
        break

I was speculating that the API filter expression in Halflife was causing this, but I get the traceback even without the filter.

j-f1 commented 6 years ago

Seems like MS is complaining about nil.username' not working (&#39 is ').

Line 7 of _post.json.jbuilder is:

names: post.flag_logs.select { |f| f.success && f.is_auto }.map { |f| f.user.username },

So it looks like f.user is nil. I took a look at the flag logs page for this report, and sure enough, the first flag log doesn’t have a username in it.

ArtOfCode- commented 6 years ago

bug buggity bug. Dunno why that doesn't have a user attached.

tripleee commented 6 years ago

Another instance with the same symptom.

halflife:2017-11-01 05:49:18,598:Query posts/91541;89083;62604;62600;62596;62587;62571;62559;62543;62501 did not return valid JSON: '\n\n\n \n \n \n\n \n\n\n\n
\n
\n NoMethodError in\n API#posts\n
\n
\n\n
\n

\n Showing /var/railsapps/metasmoke/releases/20171031015321/app/views/posts/_post.json.jbuilder where line #7 raised:\n
\n

undefined method `username' for nil:NilClass
tripleee commented 6 years ago

Using the repro script above, I isolated the offending sample: 62559

I don't really care about the user names so I suppose I could perhaps tweak the API query filter to not request this information as a workaround.

tripleee commented 6 years ago

E.g. /flagging/users/2/logs returns a backtrace, too; I guess there are user IDs which used to exist but which are now deleted?

ArtOfCode- commented 6 years ago

There certainly are some of those. Depending on what traceback you're getting, it may just be a 404.