OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

python, Typer: disable printing of elements such as the traceback and locals

  • Thread starter Thread starter ntg
  • Start date Start date
N

ntg

Guest
I am using Typer and it looks pretty cool.

However in a particular case, I want to hide some details for being print. In particular consider a case like

Code:
import typer
app = typer.Typer()

@app.command()
def connect_to_super_secret_server():
  host = os.env.get(HOST,'foohost')
  port = ...
  password = ...
  username = ...
  ....
  assert error_foobar_did_not_happen, "FooBar must be set."
  ...
  return connection

When the assertion triggers an exception, I am getting something like:

Code:
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ ..............
│ ..............
│ ..Huge traceback.
│ ..............
│ ..............
│ ..............
│ ..............
│ ..............
│ ..............
│ ..............
│ ..............
│                                                                                                  │
│ ╭──────── locals ────────╮                                                                       │
│ │    host  = 'localhost' │                                                                       │
│ │ password = sensitive   │                                                                       │
│ │     port = 9200        │                                                                       │
│ │ username = 'admin'     │                                                                       │
│ ╰────────────────────────╯                                                                       │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AssertionError: FooBar must be set

The traceback is really cool when developing, but would it be possible to disable in production?

Also, most importantly, would there be a way to hide the value of the sensitive password variable so as not to print it in plaintext?
<p>I am using <a href="https://typer.tiangolo.com/" rel="nofollow noreferrer">Typer</a> and it looks pretty cool.</p>
<p>However in a particular case, I want to hide some details for being print. In particular consider a case like</p>
<pre class="lang-py prettyprint-override"><code>import typer
app = typer.Typer()

@app.command()
def connect_to_super_secret_server():
host = os.env.get(HOST,'foohost')
port = ...
password = ...
username = ...
....
assert error_foobar_did_not_happen, "FooBar must be set."
...
return connection
</code></pre>
<p>When the assertion triggers an exception, I am getting something like:</p>
<pre><code>╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ ..............
│ ..............
│ ..Huge traceback.
│ ..............
│ ..............
│ ..............
│ ..............
│ ..............
│ ..............
│ ..............
│ ..............
│ │
│ ╭──────── locals ────────╮ │
│ │ host = 'localhost' │ │
│ │ password = sensitive │ │
│ │ port = 9200 │ │
│ │ username = 'admin' │ │
│ ╰────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AssertionError: FooBar must be set
</code></pre>
<p>The traceback is really cool when developing, but would it be possible to disable in production?</p>
<p>Also, most importantly, would there be a way to hide the value of the sensitive password variable so as not to print it in plaintext?</p>
 
Top