简体   繁体   English

"输出和调试控制台中的 Visual Studio 代码\\n"

[英]Visual Studio Code \n in Output & Debug Console

I'm using Visual Studio Code to create a AWS Lambda SAM applications with Python 3.9.7 on a Windows 10 machine.我正在使用 Visual Studio Code 在 Windows 10 机器上使用 Python 3.9.7 创建 AWS Lambda SAM 应用程序。 I'm using the AWS Toolkit and Python extensions in Visual Studio Code.我在 Visual Studio Code 中使用 AWS Toolkit 和 Python 扩展。

When running/debugging Lambda SAM applications, the Visual Studio Code Output window and Debug Console both show Error Messages and Stack Traces as an unformatted dictionary with the \\n character instead of an actual new line being added to the output.在运行/调试 Lambda SAM 应用程序时,Visual Studio 代码输出窗口和调试控制台都将错误消息和堆栈跟踪显示为带有 \\n 字符的未格式化字典,而不是在输出中添加实际的新行。 A typical error/stack trace is pretty unreadable and looks like the following, but word wrapped depending upon the window width:典型的错误/堆栈跟踪非常不可读,如下所示,但根据窗口宽度自动换行:

{"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"]}

I have tried toggling the CRLF and LF in the bottom right of the Visual Studio Code to no avail.我尝试在 Visual Studio Code 的右下角切换 CRLF 和 LF 无济于事。

The closest related issue I could find is https://github.com/microsoft/vscode/issues/73845 , which appears to conclude that "The VS Code frontend should not escape newlines. It is up to the debug extension to decide how the data should be presented and the debug extension can decide if a newline should be escaped or not."我能找到的最接近的相关问题是https://github.com/microsoft/vscode/issues/73845 ,它似乎得出的结论是“VS Code 前端不应转义换行符。由调试扩展决定如何应该显示数据,调试扩展可以决定是否应该转义换行符。"

So it sounds like the handling of the \\n should be done by either the AWS SAM extension or the Python Extension?所以听起来 \\n 的处理应该由 AWS SAM 扩展或 Python 扩展来完成? However, I can't find any settings in either to control the \\n behavior in the output or debug console windows.但是,我找不到任何设置来控制输出或调试控制台窗口中的 \\n 行为。 I'm also not even sure whether the issue needs to be addressed within VSCode, AWS Toolkit or the Python extension?我什至不确定是否需要在 VSCode、AWS Toolkit 或 Python 扩展中解决这个问题?

How can I get Visual Studio Code, AWS SAM extension or the Python extension make the error message and stack traces be more readable and useable by replacing the \\n characters with a newline so the output window and/or debug console window looks more like the following?如何获得 Visual Studio Code、AWS SAM 扩展或 Python 扩展,通过用换行符替换 \\n 字符,使错误消息和堆栈跟踪更具可读性和可用性,因此输出窗口和/或调试控制台窗口看起来更像下列的? Is there some setting I'm missing or some other extension that would format the output?是否有一些我缺少的设置或其他一些会格式化输出的扩展?

{"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"]}

One option is to use perl to replace \\n<\/code> characters with real new lines:一种选择是使用 perl 用真正的换行符替换\\n<\/code>字符:

This is how you would then invoke your local lambda:这就是你调用本地 lambda 的方式:

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

Here are some other formatting options: link<\/a>以下是一些其他格式选项:链接<\/a>

"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM