MCPcopy Create free account
hub / github.com/microsoft/vscode-cpptools / reportMacCrashes

Function reportMacCrashes

Extension/src/LanguageServer/extension.ts:1060–1104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1058}
1059
1060function reportMacCrashes(): void {
1061 if (process.platform === "darwin") {
1062 prevMacCrashFile = "";
1063 const home: string = os.homedir();
1064 const crashFolder: string = path.resolve(home, "Library/Logs/DiagnosticReports");
1065 fs.stat(crashFolder, (err) => {
1066 const crashObject: Record<string, string> = {};
1067 if (err?.code) {
1068 // If the directory isn't there, we have a problem...
1069 crashObject["errCode"] = err.code;
1070 telemetry.logLanguageServerEvent("MacCrash", crashObject);
1071 return;
1072 }
1073
1074 // vscode.workspace.createFileSystemWatcher only works in workspace folders.
1075 try {
1076 fs.watch(crashFolder, (event, filename) => {
1077 if (event !== "rename") {
1078 return;
1079 }
1080 if (!filename || filename === prevMacCrashFile) {
1081 return;
1082 }
1083 prevMacCrashFile = filename;
1084 if (!filename.startsWith("cpptools")) {
1085 return;
1086 }
1087 // Wait 5 seconds to allow time for the crash log to finish being written.
1088 setTimeout(() => {
1089 fs.readFile(path.resolve(crashFolder, filename), 'utf8', (err, data) => {
1090 if (err) {
1091 // Try again?
1092 fs.readFile(path.resolve(crashFolder, filename), 'utf8', handleMacCrashFileRead);
1093 return;
1094 }
1095 handleMacCrashFileRead(err, data);
1096 });
1097 }, 5000);
1098 });
1099 } catch {
1100 // The file watcher limit is hit (may not be possible on Mac, but just in case).
1101 }
1102 });
1103 }
1104}
1105
1106export function usesCrashHandler(): boolean {
1107 if (os.platform() === "darwin") {

Callers 1

activateFunction · 0.85

Calls 2

handleMacCrashFileReadFunction · 0.85
resolveMethod · 0.65

Tested by

no test coverage detected