Page MenuHomePhorge

Fix "Undefined offset: 1" exception in Diviner when @task value in PHPDoc is a single word
ClosedPublic

Authored by aklapper on Jun 11 2024, 09:40.

Details

Summary

The PHPDoc in https://we.phorge.it/source/phorge/browse/master/src/infrastructure/storage/lisk/LiskMigrationIterator.php$14 defines * @task storage.
That means the value of $task in the DivinerAtomController class is the single string storage and there is no whitespace to explode on and there is no second key in the array to set as $title.
Thus only call explode when $task contains a whitespace.

EXCEPTION: (RuntimeException) Undefined array key 1 at [<arcanist>/src/error/PhutilErrorHandler.php:273]
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<phorge>/src/applications/diviner/controller/DivinerAtomController.php:450]

Closes T15854

Test Plan

Diff Detail

Repository
rP Phorge
Branch
divinerUndefArrayKey (branched from master)
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 1342
Build 1342: arc lint + arc unit

Event Timeline

speck added inline comments.
src/applications/diviner/controller/DivinerAtomController.php
449

I can’t recall for php… I’d the double equals used to prevent coercion, in which case this would always be true if strpos doesn’t find anything?

src/applications/diviner/controller/DivinerAtomController.php
449

@speck: Hmm, not sure I can fully parse your comment, sorry. :)
Looking at "Return Values" in https://www.php.net/manual/en/function.strpos.php it says "Returns false if the needle was not found. [...] Use the === operator for testing the return value of this function." and in Example 2 "The !== operator can also be used." So I think this change works as expected to only call explode if a whitespace was found?

Not having a title seems j like a bug elsewhere

src/applications/diviner/controller/DivinerAtomController.php
449

Oof - you answered my question. I didn’t look it up but thought strpos returned and index and not boolean

This revision is now accepted and ready to land.Jun 22 2024, 03:00