如何在nodejs调试控制台中更改对象实例的字符串表示形式.有没有一种方法(比如toString()在.NET中)我可以覆盖?
请考虑以下代码:
class SomeObject{
constructor(){
this._varA = "some text";
this._varB = 12345;
this._varC = "some more text";
this._varD = true;
this._varE = 0.45;
}
toString(){
return "custom textual rapresentation of my object";
}
}
var array = [];
array.push(new SomeObject());
array.push(new SomeObject());
array.push(new SomeObject());
console.log(array);
Run Code Online (Sandbox Code Playgroud)
但是在我工作的其他环境和编程语言中,覆盖该toString()方法将显示toString()(在上面的示例中"custom textual representation of my object")的结果,而不是调试器创建的动态文本表示(在上面的示例代码中是SomeObject {_varA: "some text", _varB: 12345, _varC: "some more text", …}:) - 我不知道如果没有定义自定义替代方案,那么在一分钟内它是非常有用的.
我也意识到这console.log(array.toString());甚至console.log(array.map(t=>t.toString()));会产生类似于我所追求的东西,但是这会阻止我使用调试导航来浏览对象,即.钻入对象图.
如果这是不可能的,其他人会从中受益吗?如果有足够的兴趣,我可以考虑定义和实现它作为一个功能.
javascript debugging node.js visual-studio-code vscode-debugger
在检查 API 端点(确定连接状态)的相对简单的代码块中,我依靠 atry..catch作为机制来验证应用程序是否可以与服务器通信。
我遇到的问题是,在调试时,调试器总是在连接线上停止(当应用程序离线时),即使我在内部处理错误。
Future<bool> isOnline() async {
try {
// VSCode debugger always stops on this line when no connection
await http
.get('${consts.apiBaseUrl}/api/ping')
.timeout(Duration(seconds: normalTimeoutLength))
.catchError(
(_) {
// Trying catchError on the Future
_isOnline = false;
return false;
},
);
_isOnline = true;
return true;
} on HttpException catch (_) {
// Trying to catch HTTP Exceptions
_isOnline = false;
return false;
} on SocketException catch (_) {
// Trying to catch Socket Exceptions
_isOnline …Run Code Online (Sandbox Code Playgroud) (操作系统和版本:Ubuntu 18.4,VS Code 版本:Vscode 1.4,C/C++ 扩展版本:0.26)
你好,我已经阅读了所有关于“raise.c”的文章,但没有一篇能解决我的问题,我只是写了一个简单的 OpenCV 代码来捕捉网络摄像头的帧。每次我运行我的代码时,它经常显示一个错误。错误信息是:
无法打开“raise.c”:无法读取文件(错误:找不到文件(/build/glibc-OTsEL5/glibc-2.27/sysdeps/unix/sysv/linux/raise.c))。
launch.json 是:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": …Run Code Online (Sandbox Code Playgroud) package.json visual-studio-code npm-scripts vscode-settings vscode-debugger
我主要使用 gdb 在 vscode 中调试 c++ 单个文件,但现在想尝试 lldb,但我在为 vscode 设置它时遇到问题。
我首先创建默认的 launch.json 表单调试选项卡,cpp gdb/lldb然后clang++选择进行配置。
当调试开始时..它显示以下错误:
然后在 launch.json 中我将miDebuggerPath路径形式 更改/usr/bin/lldb-mi为/usr/bin/lldb.
然后,当我启动调试器时,它什么也不做,只是调试终端中顶部和以下几行的控件:
warning: ignoring unknown option: --interpreter=mi
warning: ignoring unknown option: --tty=/dev/pts/1
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么吗?
我的整体launch.json是:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file", …Run Code Online (Sandbox Code Playgroud) 这应该是一个很容易回答的问题。我是 Visual Studio Code 的新手,我正在努力弄清楚如何让“命中计数”条件断点功能发挥作用。我有一个简单的 for 循环设置如下:
for (int i = 0; i < 10; i++)
{
cout << i << endl;
}
Run Code Online (Sandbox Code Playgroud)
我在 cout 行上放置了一个断点,右键单击它并单击“编辑断点...”并将下拉框更改为“命中计数”。我只想在 for 循环的第五次迭代时触发断点,但我不知道如何编写表达式。无论我写什么,程序都会在第一次循环时中断。我尝试过“5”、“== 5”和“Hit Count == 5”,但没有任何效果。
如果有人能告诉我我做错了什么,我将不胜感激!我在网上能找到的所有内容都是关于 Visual Studio 而不是 VSCode。
我正在开发一个项目,其结构如下
Parent Directory
----+ MyPackage
----__init__.py
----file1.py
----+ Tests
----test.py
Run Code Online (Sandbox Code Playgroud)
当我从终端运行测试时,我使用
PYTHONATH=./ python ./Tests/test.py
Run Code Online (Sandbox Code Playgroud)
现在,当我在安装“Python Extension”后尝试调试选项时,会出现错误
Exception has occurred: ModuleNotFoundError
No module names 'MyPackage'
Run Code Online (Sandbox Code Playgroud)
如何将 PYTHONPATH 放入调试配置中以使其得到处理?
我正在按照VS code 网站的说明进行操作,但似乎我尝试的任何方法都不起作用。
我根据需要创建了一个新配置,但是每当我放置路径时,它都拒绝在 VS 代码中工作,尽管当我手动调用它时,VS 代码在集成终端窗口中抱怨的路径工作正常。
调试器抛出的错误如下:
(automl-meta-learning) brandomiranda~/automl-meta-learning/automl/experiments ? env PTVSD_LAUNCHER_PORT=59729 /Users/brandomiranda/miniconda3/envs/automl-meta-learning/bin/python /Users/brandomiranda/.vscode/extensions/ms-python.python-2020.2.63072/pythonFiles/lib/python/new_ptvsd/wheels/ptvsd/launcher -m /Users/brandomiranda/automl-meta-learning/automl/experiments/experiments_model_optimization.py
E+00000.025: Error determining module path for sys.argv
Traceback (most recent call last):
File "/Users/brandomiranda/.vscode/extensions/ms-python.python-2020.2.63072/pythonFiles/lib/python/new_ptvsd/wheels/ptvsd/../ptvsd/server/cli.py", line 220, in run_module
spec = find_spec(options.target)
File "/Users/brandomiranda/miniconda3/envs/automl-meta-learning/lib/python3.7/importlib/util.py", line 94, in find_spec
parent = __import__(parent_name, fromlist=['__path__'])
ModuleNotFoundError: No module named '/Users/brandomiranda/automl-meta-learning/automl/experiments/experiments_model_optimization'
Stack where logged:
File "/Users/brandomiranda/miniconda3/envs/automl-meta-learning/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Users/brandomiranda/miniconda3/envs/automl-meta-learning/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/brandomiranda/.vscode/extensions/ms-python.python-2020.2.63072/pythonFiles/lib/python/new_ptvsd/wheels/ptvsd/__main__.py", line 45, …Run Code Online (Sandbox Code Playgroud) 我有一个 Angular 应用程序(.Net Core 后端)。我可以在 launch.json 文件中创建配置并使用 Firefox、Chrome、Edge 等进行调试。但我没有看到 Safari 的任何选项!
问题- 如何创建配置供 Safari 在启动调试器时使用而不是 Chrome?当我在 launch.json 中单击“添加配置”时,我应该为 Safari 选择哪个选项?我需要单独的扩展吗?
vscode-debugger ×10
c++ ×2
python ×2
cython ×1
dart ×1
debugging ×1
exception ×1
flutter ×1
javascript ×1
node.js ×1
npm-scripts ×1
opencv ×1
package.json ×1
pdb ×1
safari ×1
ubuntu ×1