-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathPostFuncDebugExecuteStep.ts
More file actions
70 lines (62 loc) · 3 KB
/
PostFuncDebugExecuteStep.ts
File metadata and controls
70 lines (62 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ActivityChildItem, ActivityChildType, activityInfoContext, AzureWizardExecuteStep, createContextValue, randomUtils, type ExecuteActivityContext, type ExecuteActivityOutput, type IActionContext } from "@microsoft/vscode-azext-utils";
import { stripVTControlCharacters } from "node:util";
import { ThemeIcon } from "vscode";
export class PostFuncDebugExecuteStep<T extends IActionContext & ExecuteActivityContext> extends AzureWizardExecuteStep<T> {
public priority: number = 999;
public stepName: string = 'PostFuncDebugExecuteStep';
// public options: AzureWizardExecuteStepOptions = {
// continueOnFail: true
// }
public constructor(readonly logs: string[]) {
super();
}
public async execute(context: T): Promise<void> {
const errorLogs: string[] = [];
// eslint-disable-next-line no-control-regex
const redAnsiRegex = /\x1b\[(?:[0-9;]*31m|[0-9;]*91m|38;5;(9|1)m)/;
const functionErrors = [
/No job functions found/i,
/Worker was unable to load entry point/i,
/SyntaxError:/i,
/Cannot find module/i,
/Failed to start Worker Channel/i,
/Serialization and deserialization.*not supported/i
];
for (const log of this.logs) {
if (redAnsiRegex.test(log) || functionErrors.some(err => err.test(log))) {
errorLogs.push(log);
}
}
if (errorLogs.length > 0) {
context.activityAttributes = context.activityAttributes || {};
context.activityAttributes.logs = errorLogs.map(log => { return { content: stripVTControlCharacters(log) }; });
context.activityChildren = [];
throw new Error('This is from the error in execute');
}
return;
}
public shouldExecute(_context: T): boolean {
return true;
}
public createFailOutput(_context: T): ExecuteActivityOutput {
return {
item: new ActivityChildItem({
label: 'Click to have Copilot help diagnose the issue.',
id: `${randomUtils.getRandomHexString(8)}-terminateDebugSession-fail`,
activityType: ActivityChildType.Fail,
contextValue: createContextValue([activityInfoContext, 'terminateDebugSessionFail']),
iconPath: new ThemeIcon('sparkle'),
// a little trick to remove the description timer on activity children
description: ' ',
command: {
"command": "azureResourceGroups.askAgentAboutActivityLogItem",
"title": "Ask Copilot",
}
})
};
}
}