Page MenuHomePhabricator

Make PhutilDocblockParser always return arrays when parsing "@doc-tags"
Open, LowPublic

Description

I discovered this by just updating my sources to master and trying to add a new class to phabricator via arc liberate src. You can fairly easily reproduce this by cloning everything at the latest masters on a fresh machine and then running arc liberate src on any of the libraries.

If you revert libphutil back to before rPHU237549280f08feb8852857b1d109dfb0aba345f0 this behavior goes away. It looks like phutil_symbols.php never had its PhutilDocblockParser related code updated to match the new format.

Event Timeline

I'm not sure how this wasn't reported earlier, I guess the module cache prevented everyone from encountering it?

Yeah, I think this didn't crop up sooner through a combination of the cache and there being relatively few files with multiple @phutil-external-symbol tags.

(I caught something similar in Diviner that I'll take a look at, although possibly D16484 covers it.)

We should probably change this API to always return array(), the "sometimes array, sometimes scalar" return value is pretty unintuitive. And any code which fixed this by adding (array) will just work.

The other fix I applied in the wake of D16431 was D16433.

To test all currently-known code depending on this stuff:

  • arc liberate --all
  • bin/celerity map
  • bin/diviner generate --clean

I'm going to retarget this to make the API more consistent.

epriestley renamed this task from phutil_symbols.php fails when parsing docblocks specifying external symbols to Make PhutilDocblockParser always return arrays when parsing "@doc-tags".Sep 2 2016, 12:20 PM
epriestley triaged this task as Low priority.

We have a parser for comment docblocks, used to generate documentation and extract metadata from source code. This is a docblock:

/**
 * @key value
 */

Source code is text files containing stories that computers can read.

D16431 improved this parser by providing a more structured way to extract multiple repeats of a given @key. However, it left us with a return value that is sometimes a scalar (if there was only one @key) and sometimes a list (if there was more than one @key).

This is surprising and caused a few issues at parser callsites:

I think we should just always return an array instead, so consumers don't need to know that they have to test. Currently, it's possible to write a consumer which works fine until someone writes @key twice, then explodes.

To test all the stuff that hit issues:

phabricator/ $ arc liberate --all
phabricator/ $ ./bin/celerity map
phabricator/ $ ./bin/diviner generate --clean
This comment was removed by epriestley.
This comment was removed by epriestley.

I think there's another one of these in DivinerAtomController->composeTasks(). The other getDocblockMetaValue() calls anywhere in the codebase are also suspicious.