How to attach VSCode Debugger to a Hardhat Task's callback in setAction() so that breakpoints work? - ethereum

I'd like my code execution to pause on some expressions inside of the actions callback inside setActions. When i run the below config and breakpoint the debugger runs and exits immediately without stopping at the breakpoint.
// Filename : DoSomething.js
task("DoSomething", "DoesSomething")
.addParam("account", "The account's address")
.setAction(async () => {
// breakpoint somewhere here!
});
My launch.json configuration looks like this:
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Do Something",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/tasks/admin/DoSomething.js",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/hardhat",
"runtimeArgs":["--network", "goerli", "--account", "0xMyAddress1234555....."]
}
]
Im guessing that the action gets registered in hardhat's internals and is passed as a copy so maybe that line is not directly executed? Really keen to understand what's going on here!

Related

How to executeScript for webRequest event onBeforeRequest in Google Chrome Extension

Following Chrome Extension Manifest V3 rule I want to create an extension, that listens to particular network request and, for startes, just log them to the console of the currently opened tab (later I want to add custom script and styles to the page in the current tab).
For this I try to utilize chrome.scripting.executeScript.
When I implement the sample from https://github.com/GoogleChrome/chrome-extensions-samples/blob/main/examples/page-redder/manifest.json it works like expected for the chrome.action.onClicked listener.
As soon as I try to execute a script within the chrome.webRequest.onBeforeRequest listener, this error pops up:
Error in event handler: TypeError: Error in invocation of
scripting.executeScript(scripting.ScriptInjection injection, optional
function callback): Error at parameter 'injection': Error at property
'target': Missing required property 'tabId'.
at chrome.webRequest.onBeforeRequest.addListener.urls ()
Missing required property tabId? I assume it has to do with the lifecycle, but I cannot figure out what to do. This is my manifest:
{
"name": "Getting Started Example",
"description": "Build an Extension!",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js",
"matches": [ "<all_urls>"]
},
"host_permissions": [
"<all_urls>"
],
"permissions": [
"activeTab",
"tabs",
"webRequest",
"webNavigation",
"management",
"scripting"
]
}
And this is my script, I just slightly modified the "redden"-example:
function reddenPage(url) {
console.log(url);
}
chrome.webRequest.onBeforeRequest.addListener((tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: reddenPage,
args: [tab.url],
});
},
{urls: ["*://*.google.com/*"]},
[]);
I don't know exactly why, but the script from Github seems not work. This is how it works:
It's not only a couple of changed brackets, look at tab instead of (tab), but also tab.tabId instead of tab.id:
chrome.webRequest.onBeforeRequest.addListener(tab => {
chrome.scripting.executeScript(
{
target: { tabId: tab.tabId },
function: reddenPage,
args: [details.url],
},
() => { console.log('ZZZ') });
}, {
urls: ['<all_urls>']
});

VSCode: "No debug adapter, can not send 'evaluate'"

I am trying to run lua 5.4 code in VSCODE but I am getting this error:No debug adapter, can not send 'evaluate'. My debugger is "Local Lua Debugger" and the launch.json is
{
"version": "0.2.0",
"configurations": [
{
"type": "lua-local",
"request": "launch",
"name": "Launch",
"program": {
"lua": "lua54",
"file": "bot.lua"
}
}
]
}
And the lua file itself is
print("Y/N?")
local input = io.input()
if input == "no" then
print("yes")
end
The error shows up every time I want to input something.
io.input() is for you to read external files, in it you pass the path of a file you want to read.
If you want to write something and store it in the variable, try using io.read()

How to fix "/bin/bash: [command] command not found" after setting up tasks.json and c_cpp_properties.json for C++ on Windows 10 VS Code?

I have configured my task.json and c_cpp_properties.json so that I may compile my main.cpp program. In order to proceed, I must press
Ctrl + Shift + B
As soon as I do a terminal pops up and alters me of an error:
Executing task in folder C++: C:\MinGW\bin\g++.exe -g main.cpp -o c:\Users\Me\Desktop\C++\.vscode\tasks.exe <
/bin/bash: C:MinGWbing++.exe: command not found
The terminal process terminated with exit code: 127
Terminal will be reused by tasks, press any key to close it.
I don't why this is happening since I've already checked that MinGW is installed in my computer with the correct PATH. To ensure that I do I typed the following in the terminal:
g++ --version
g++ (MinGW.org GCC-8.2.0-3) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
I also checked the path according to this figure
The only closest problem related to mine is in this Github link. I've also already tried changing the file directory shown in the code below using this thread but I still encounter this error.
Here are my JSON files which are inside my .vscode file:
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"main.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17134.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\\MinGW\\lib\\gcc\\mingw32\\8.2.0\\include\\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
I should expect to see a ".exe" after compiling but I can't due to the error.
After spending two days messing around with this I've finally able to correct setup C++ on VS Code and resolved the error.
According to the png image from above, I've included "C:\MinGW\bin" within the user variable "Path" under the dialogue box "User variables for Me". After a simple restart on my computer, I was able to build my project (Shift + Ctrl + B) with no problems.

VS Code: Error while applying breakpoint, "Breakpoint ignored because target path not found"

I am using chrome debugger extension in Visual Studio code to debug my backbone application. The launch.json file is like this;
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "https://localhost:3000/authenticate/app/110020",
"webRoot": "D:/Apps/app",
"sourceMaps": false,
"trace": "verbose"
}
]
}
When i am trying to put a breakpoint in the app.js file which is present in "D:/Apps/app" directory, the following error is displayed,
"Breakpoint ignored because target path not found". The file app.js is not minified or combined.
The answer for the original question was found here by the looks of things: https://github.com/Microsoft/vscode-chrome-debug/issues/462
In summary the issue was related to the poster requesting JS files with a querystring with no key eg
https://localhost:3000/dd/2000/app/js/pp?112/src/js/build.js
This caused an error is VS code. As of now the issue is still open.

In vscode errors generated by a task with isWatching are not always cleared after they have been fixed

I'm using a gulp task in vscode (0.9) to try to get errors from both typescript and tslint.
The gulp task is watching for changes on my ts files and run both the gulp-tslint and gulp-typescript on changes.
I also defined a task in vscode tasks.json and problem matchers to parse the results.
The errors are parsed and reported correctly into vscode.
However they are sometimes kept even when code is fixed and saved.
Is there some additional config to provide to vscode problem matcher so that it clear errors properly or is it a vscode bug?
As a workaround is there a way to manually clear all errors? The only way I found to clear them is to restart vscode which is not great.
Note that this works fine if the task is not a watch task but a simple execution.
My vscode tasks.json
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"tasks": [
{
"taskName": "watch",
// Make this the default build command.
"isBuildCommand": true,
// Watching
"isWatching": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
// Use the standard less compilation problem matcher.
"problemMatcher": [
{
"owner": "gulp-tslint",
"fileLocation": [
"relative",
"${workspaceRoot}/app"
],
"pattern": {
"regexp": ".*\\[gulp-tslint\\] (error|warning) (.*)\\[(\\d*), (\\d*)\\]: (.*)",
"severity": 1,
"file": 2,
"line": 3,
"column": 4,
"message": 5
}
},
{
"owner": "gulp-typescript",
"fileLocation": "absolute",
"pattern": {
"regexp": "\\[gulp-typescript\\] (.*)\\((\\d*),(\\d*)\\): (error|warning) (.*)",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
]
}
]
}
My gulp task definition:
const tslint = require('gulp-tslint');
const typescript = require('gulp-typescript');
gulp.task('watch', function () {
gulp.watch(srcTsFiles, ['tslint', 'compile']);
});
gulp.task('tslint', function () {
return gulp.src(srcTsFiles)
.pipe(tslint())
.pipe(tslint.report('prose', {
emitError: false,
summarizeFailureOutput: true
}));
});
var tsProject = typescript.createProject('tsconfig.json');
gulp.task('compile', function () {
tsProject.src()
.pipe(typescript(tsProject, undefined, typescript.reporter.longReporter()))
.pipe(gulp.dest('dist'));
});
This is a bug in VSCode. Somehow, it doesn't apply any updates to open files. If the files are closed, any obsolete errors are removed.
So, the workaround is to click the little "close all files" icon in the "Working Files" header.
If you want to figure out yourself what the problem is, look into the JS files in the VSCode resources; in OSX, those reside in the application package. Look for workbench.main.js. You will find the tsc-watch problem matcher in there, and it will have applyTo:c.ApplyToKind.closedDocuments set. I tried to change that to allDocuments, but to no avail.
This is fixed in the latest insider build (I tested it) and will likely go into production next week.
https://github.com/Microsoft/vscode/issues/909