简体   繁体   中英

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. I'm using the AWS Toolkit and Python extensions in Visual Studio Code.

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. 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.

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."

So it sounds like the handling of the \\n should be done by either the AWS SAM extension or the Python Extension? However, I can't find any settings in either to control the \\n behavior in the output or debug console windows. I'm also not even sure whether the issue needs to be addressed within VSCode, AWS Toolkit or the Python extension?

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? 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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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