-1

I'm trying to write a simple problem matcher for the output of ts-node-dev, but for some reason VSCode never detects problems in the output.

Here's the terminal output I would like to match; it contains an error message and a stack trace. I've copied it from the task output in VSCode's terminal pane:

Please migrate your code to use AWS SDK for JavaScript (v3).
For more information, check the migration guide at https://a.co/7PzMCcy
(Use `node --trace-warnings ...` to show where the warning was created)
[INFO] 15:58:00 Restarting: /Users/myname/dev/workspaces/ts_workspace/code/api/src/graphql/schemas/dataDiagnostic.ts has been modified
trying to use docker executor...but configured as cannot.
Error: Unknown type "DataDiagnosticSverity". Did you mean "DataDiagnosticSeverity", "DataDiagnosticEdge", "DataDiagnostic", or "DataDiagnosticConnection"?
    at assertValidSDL (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/graphql/validation/validate.js:135:11)
    at buildASTSchema (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/graphql/utilities/buildASTSchema.js:44:34)
    at makeExecutableSchema (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/@graphql-tools/schema/cjs/makeExecutableSchema.js:73:47)
    at Object.<anonymous> (/Users/myname/dev/workspaces/ts_workspace/code/api/src/apolloServer.ts:12:36)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Module._compile (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/source-map-support/source-map-support.js:568:25)
    at Module.m._compile (/private/var/folders/fr/gxs3qpcs2zxby__p9lm9h_rm0000gn/T/ts-node-dev-hook-6064780755344261.js:69:33)
    at Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at require.extensions..jsx.require.extensions..js (/private/var/folders/fr/gxs3qpcs2zxby__p9lm9h_rm0000gn/T/ts-node-dev-hook-6064780755344261.js:114:20)
    at require.extensions.<computed> (/private/var/folders/fr/gxs3qpcs2zxby__p9lm9h_rm0000gn/T/ts-node-dev-hook-6064780755344261.js:71:20)
[ERROR] 15:58:01 Error: Unknown type "DataDiagnosticSverity". Did you mean "DataDiagnosticSeverity", "DataDiagnosticEdge", "DataDiagnostic", or "DataDiagnosticConnection"?
(node:54671) NOTE: We are formalizing our plans to enter AWS SDK for JavaScript (v2) into maintenance mode in 2023.

And here's my problemMatcher for the task that gives the above output:

"problemMatcher": [
  {
    "fileLocation": "absolute",
    "pattern": {
      "regexp": "^(Error|Warning):\\s*(.*)[\\n\\r]+\\s+at\\s+(.*)\\s+\\((.*):(\\d+):(\\d+)\\)",
      "severity": 1,
      "message": 2,
      "file": 4,
      "line": 5,
      "column": 6
    }
  }
]

I designed the regex on regex101.com and then passed it through a JSON escaper to get the extra slashes needed. You can see the regex working correctly with all of its captures here. I've also pasted the output into VSCode and run the regex manually to ensure that it matches there.

Despite all of that, when I start the task in VSCode, the problem is not detected. I don't see any options for debugging or testing the problemMatcher beyond what I've already done.

How can I change my problemMatcher so that it correctly detects the problem in the output shown above?

Nate Glenn
  • 6,455
  • 8
  • 52
  • 95
  • I wonder if it's issues with the `.*` greediness? What if you use `[^\n\r]*` and `[^:]*`? "_I don't see any options for debugging or testing the problemMatcher beyond what I've already done._" You could try matching just a little bit from the start of your regex, seeing how much you can match, and then slowly adding back more of your regex to see which part fails. – starball Apr 12 '23 at 21:15

1 Answers1

0

In the end I did have to change my pattern to work correctly; I wasn't able to get a multi-line regex working, and instead wrote a separate pattern for each line to be matched:

"problemMatcher": {
  "owner": "node-builder",
  "fileLocation": "absolute",
  "pattern": [
    {
      "regexp": "^(Error|Warning):\\s*(.*)",
      "severity": 1,
      "message": 2,
    },
    {
      "regexp": "^\\s*at\\s+(.*)\\s+\\((.*):(\\d+):(\\d+)\\)",
      "file": 2,
      "line": 3,
      "column": 4
    },
  ]
},

The real issue that I had with developing this was a practical one while using VSCode. The task is defined as a dependency of another task, which combines many build steps together. I had run all of the tasks using the combined build task, and then was killing just the sub-task whose patternMatcher I was editing and restarting by running the combined task again, which runs dependent tasks that aren't running already. Doing this results in tasks.json not being reloaded, and thus nothing I did had any effect. The task has to be run by itself in order for tasks.json to be reloaded.

Nate Glenn
  • 6,455
  • 8
  • 52
  • 95