realm / jazzy

Soulful docs for Swift & Objective-C
https://realm.io
MIT License
7.35k stars 413 forks source link

sourcekitten.rb:657:in `block in expand_extensions': undefined method `include?' for nil:NilClass (NoMethodError) #1325

Closed alkhimey closed 2 years ago

alkhimey commented 2 years ago

jazzy version: 0.14.3 Tried with multiple version of Ruby (2.6.10, 2.7.6, 3.1.2)

% jazzy --sourcekitten-sourcefile swiftDoc.json,objcDoc.json
Traceback (most recent call last):
    8: from /Users/artium/.rbenv/versions/2.7.6/bin/jazzy:23:in `<main>'
    7: from /Users/artium/.rbenv/versions/2.7.6/bin/jazzy:23:in `load'
    6: from /Users/artium/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/jazzy-0.14.3/bin/jazzy:16:in `<top (required)>'
    5: from /Users/artium/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/jazzy-0.14.3/lib/jazzy/doc_builder.rb:86:in `build'
    4: from /Users/artium/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/jazzy-0.14.3/lib/jazzy/doc_builder.rb:155:in `build_docs_for_sourcekitten_output'
    3: from /Users/artium/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/jazzy-0.14.3/lib/jazzy/sourcekitten.rb:1080:in `parse'
    2: from /Users/artium/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/jazzy-0.14.3/lib/jazzy/sourcekitten.rb:656:in `expand_extensions'
    1: from /Users/artium/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/jazzy-0.14.3/lib/jazzy/sourcekitten.rb:656:in `map'
/Users/artium/.rbenv/versions/2.7.6/lib/ruby/gems/2.7.0/gems/jazzy-0.14.3/lib/jazzy/sourcekitten.rb:657:in `block in expand_extensions': undefined method `include?' for nil:NilClass (NoMethodError)
johnfairh commented 2 years ago

Out of interest, what version of Xcode/Swift? I haven't done any testing with Xcode 14.1 yet.

The crash line says, I think, that a decl in the json, probably for a Swift extension is missing name which isn't supposed to happen (must be an extension of some nominal type).

Would be great if you can share the json, but understand if you can't/don't want to. Would be more defensive against weird json from the compiler to check against this property being missing.

alkhimey commented 2 years ago

Hi,

Xcode version 13.4.1 When the JSON was produced with sourcekitten, I missed that it had ton of errors. Indeed the JSON has some weird results inside it.

Anyway, by elimination I was able to reduce it's size so I can just redact everything that is sensitive.

[
  {
    "" : {
      "key.diagnostic_stage" : "Redacted",
      "key.substructure" : [
        {
          "key.always_deprecated" : false,
          "key.always_unavailable" : false,
          "key.deprecation_message" : "",
          "key.doc.column" : 12,
          "key.doc.comment" : "Redacted",
          "key.doc.file" : "Redacted",
          "key.doc.full_as_xml" : "",
          "key.doc.line" : 59,
          "key.filepath" : "Redacted",
          "key.kind" : "sourcekitten.source.lang.objc.decl.category",
          "key.parsed_declaration" : "Redacted",
          "key.parsed_scope.end" : 188,
          "key.parsed_scope.start" : 59,
          "key.substructure" : [
            {
              "key.always_deprecated" : false,
              "key.always_unavailable" : false,
              "key.deprecation_message" : "",
              "key.doc.column" : 53,
              "key.doc.comment" : "Redacted",
              "key.doc.file" : "Redacted",
              "key.doc.full_as_xml" : "",
              "key.doc.line" : 185,
              "key.filepath" : "Redacted",
              "key.kind" : "sourcekitten.source.lang.objc.decl.property",
              "key.name" : "redacted",
              "key.parsed_declaration" : "Redacted",
              "key.parsed_scope.end" : 185,
              "key.parsed_scope.start" : 185,
              "key.unavailable_message" : "",
              "key.usr" : ""
            }
          ],
          "key.unavailable_message" : "",
          "key.usr" : ""
        }
      ]
    }
  }
]
johnfairh commented 2 years ago

Thanks a lot for tracking that down. I see it's a special case to do with Objective-C categories: sourcekitten has to figure out their key.name from their USR, which doesn't exist if the compilation errors out.

So, if you get your ObjC sourcekitten run working cleanly this should go away (some tips here if you need them) otherwise I think you'll have to manually knock out these json entries.

I'll add a fix on the jazzy side to cope with this bad json, but it's not localised to the method that crashed - the name is so important for organising things I think we'll have to just filter them out entirely and log a warning.