shellPrintHelper() usually calls print(), but in the case of an object with a shellPrint() function it instead returns the result of calling shellPrint().
Sometimes (often?) shellPrint() calls print() (eg. DBQuery), but sometimes it returns a string (eg. WriteResult). In this latter case, the printing happens via printResult = true being passed to ImplScope::exec() when shellPrintHelper() is run.
This is all a bit confusing and inconsistent. We should settle on print()ing conventions for shellPrint() and shellPrintHelper(), and then audit all uses to make them compliant. The possible options are:
- shellPrint() and shellPrintHelper() always call print() in their dynamic scope, and never return any value.
- shellPrint() and shellPrintHelper() never call print() in their dynamic scope, and always return the string to be printed. This is then actually printed via scope->exec()/printResult (as above).
I'm in favour of the latter, since it allows the exact shell output to be determined programmatically (and potentially tested in jstests) by the expression "shellPrintHelper(foo)", rather than having to mess around capturing print() calls ala SERVER-19368.
- is related to
-
SERVER-19683 Shell inserts no longer display returned WriteResult under SpiderMonkey
- Closed
-
SERVER-19791 Save mongo shell session into a file (gdb style)
- Closed