Page MenuHomePhorge

Commit hook is sometime broken: InvalidArgumentException
Closed, ResolvedPublic

Description

One of my coworker (thank you Goran) reported an issue while trying a svn commit on a repository.

This was the related exception:

+---------------------------------------------------------------+
|      * * * PUSH REJECTED BY EVIL DRAGON BUREAUCRATS * * *     |
+---------------------------------------------------------------+
             \
              \                    ^    /^
               \                  / \  // \
                \   |\___/|      /   \//  .\
                 \  /V  V  \__  /    //  | \ \           *----*
                   /     /  \/_/    //   |  \  \          \   |
                   @___@`    \/_   //    |   \   \         \/\ \
                  0/0/|       \/_ //     |    \    \         \  \
              0/0/0/0/|        \///      |     \     \       |  |
           0/0/0/0/0/_|_ /   (  //       |      \     _\     |  /
        0/0/0/0/0/0/`/,_ _ _/  ) ; -.    |    _ _\.-~       /   /
                    ,-}        _      *-.|.-~-.           .~    ~
  *     \__/         `/\      /                 ~-. _ .-~      /
   \____(Oo)            *.   }            {                   /
   (    (..)           .----~-.\        \-`                 .~
   //___\\\\  \ DENIED!  ///.----..<        \             _ -~
  //     \\\\                ///-._ _ _ _ _ _ _{^ - - - - ~

svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by pre-commit hook (exit code 255) with output:
...
EXCEPTION: (InvalidArgumentException) Call to phutil_nonempty_string() expected null or a string, got: bool. at [<arcanist>/src/utils/utils.php:2124
...
#0 phutil_nonempty_string(boolean) called at [<phorge>/scripts/repository/commit_hook.php:189]

That is surely caused by this fix for PHP 8.1:

https://we.phorge.it/rP96ae4ba13acbf0e2f8932e950a92af0495f034d7

https://we.phorge.it/rP96ae4ba13acbf0e2f8932e950a92af0495f034d7#inline-40

In short it seems the PHP function getenv() can return FALSE. But, that value is absolutely not allowed by our phutil_nonempty_string().

It's funny because, if we use strlen() be essentially break PHP 8.1, but, if we use phutil_nonempty_string(), probably we risk to break every single use in the world.

(Dear Evan... please explain to me why a function that should just say "yes/no" to the question "Is this a non-empty string?" explodes instead if it is not a string. It would be OK to log that error, but an exception is really nonsense and too much.)

Anyway the fix is here:

D25122: Fix InvalidArgumentException on commit hook