Visual Studio Code中的输出和调试控制台

3
我正在使用Visual Studio Code在Windows 10机器上创建AWS Lambda SAM应用程序,使用Python 3.9.7。 我在Visual Studio Code中使用AWS Toolkit和Python扩展。
运行/调试Lambda SAM应用程序时,Visual Studio Code的输出窗口和调试控制台都显示错误消息和堆栈跟踪作为未格式化的字典,其中\n字符代替实际的换行符添加到输出中。 典型的错误/堆栈跟踪看起来相当难以阅读,类似于以下内容,但根据窗口宽度进行了换行:
{"errorMessage": "\"['Date'] not in index\"", "errorType": "KeyError", "requestId": "b77183d6-140c-418f-a94d-3f3e2a091b91", "stackTrace": ["  File \"/var/task/app.py\", line 44, in lambda_handler\n    modelreturn, modeltopN = neuralnet.np_neuralnet_trainfirereturn ( df, payload )\n", "  File \"/var/task/neuralnet.py\", line 175, in np_neuralnet_trainfirereturn\n    np_dfdateindexes, np_dates = dates.np_getdates(df[[datecolumnname, \"Ticker\"]].sort_values(by=[datecolumnname, \"Ticker\"]).reset_index(drop=True))\n", "  File \"/var/task/pandas/core/frame.py\", line 3464, in __getitem__\n    indexer = self.loc._get_listlike_indexer(key, axis=1)[1]\n", "  File \"/var/task/pandas/core/indexing.py\", line 1314, in _get_listlike_indexer\n    self._validate_read_indexer(keyarr, indexer, axis)\n", "  File \"/var/task/pandas/core/indexing.py\", line 1377, in _validate_read_indexer\n    raise KeyError(f\"{not_found} not in index\")\n"]}

我已经尝试在Visual Studio Code右下角切换CRLF和LF,但没有效果。
最相关的问题是https://github.com/microsoft/vscode/issues/73845,其中似乎得出结论:“VS Code前端不应该转义换行符。如何呈现数据取决于调试扩展,调试扩展可以决定是否需要转义换行符。”
因此,处理\n应该由AWS SAM扩展或Python扩展完成?然而,在输出或调试控制台窗口中控制\n行为的设置在两个扩展中都找不到。我甚至不确定这个问题是否需要在VSCode、AWS Toolkit或Python扩展中解决?
如何让Visual Studio Code、AWS SAM扩展或Python扩展将错误消息和堆栈跟踪更易读并且可用,通过替换\n字符为换行符,使输出窗口和/或调试控制台窗口看起来更像以下内容?我是否遗漏了一些设置或其他扩展可以格式化输出?
{"errorMessage": "\"['Date'] not in index\"", "errorType": "KeyError", "requestId": "b77183d6-140c-418f-a94d-3f3e2a091b91", "stackTrace": ["  File \"/var/task/app.py\", line 44, in lambda_handler
modelreturn, modeltopN = net.np_net_return ( df, payload )
  File \"/var/task/net.py\", line 175, in np_net_return
    np_dfdateindexes, np_dates = dates.np_getdates(df[[datecolumnname, \"Ticker\"]].sort_values(by=[datecolumnname, \"Ticker\"]).reset_index(drop=True))
  File \"/var/task/pandas/core/frame.py\", line 3464, in __getitem__
    indexer = self.loc._get_listlike_indexer(key, axis=1)[1]
  File \"/var/task/pandas/core/indexing.py\", line 1314, in _get_listlike_indexer
    self._validate_read_indexer(keyarr, indexer, axis)
  File \"/var/task/pandas/core/indexing.py\", line 1377, in _validate_read_indexer
    raise KeyError(f\"{not_found} not in index\")\n"]}
1个回答

0

一种选择是使用 Perl 将 \n 字符替换为实际的新行:

这是如何调用本地 lambda 的方法:

sam local invoke | perl -pe 's/\\n/\n/g'

以下是其他格式选项:link


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接