[SERVER-19710] shellPrintHelper() and shellPrint() printing conventions not well defined Created: 01/Aug/15 Updated: 06/Dec/22 Resolved: 03/Dec/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Kevin Pulo | Assignee: | Backlog - Server Tooling and Methods (STM) (Inactive) |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | move-stm | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Assigned Teams: |
Server Tooling & Methods
|
||||||||||||
| Operating System: | ALL | ||||||||||||
| Participants: | |||||||||||||
| Description |
|
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:
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 |
| Comments |
| Comment by Brooke Miller [ 03/Dec/21 ] | ||||||
|
We've deprecated the mongo shell in favor of the new[ mongosh|https://docs.mongodb.com/mongodb-shell/]. Unfortunately, we aren't able to pursue improvements to the deprecated shell except in extreme cases, such as critical security fixes. Please start making use of mongosh and let us know if it works for you in this case. | ||||||
| Comment by Kevin Pulo [ 02/Mar/18 ] | ||||||
|
We keep adding shellPrint() methods which return strings instead of printing, most recently in SessionOptions and DriverSession. These don't work when manually passed to the global shellPrint() function (but they would if they printed and returned undefined). The other places I could find which also do this are:
The workaround is usually just to call print(foo.shellPrint()) instead, but it's annoying to have to remember/figure out when this is necessary, and when it isn't or won't work. |