Skip to main content
Glama
ErrorUtils.cs2.02 kB
/* ┌──────────────────────────────────────────────────────────────────┐ │ Author: Ivan Murzak (https://github.com/IvanMurzak) │ │ Repository: GitHub (https://github.com/IvanMurzak/Unity-MCP) │ │ Copyright (c) 2025 Ivan Murzak │ │ Licensed under the Apache License, Version 2.0. │ │ See the LICENSE file in the project root for more information. │ └──────────────────────────────────────────────────────────────────┘ */ using System.Text.RegularExpressions; namespace com.IvanMurzak.Unity.MCP.Runtime.Utils { public static partial class ErrorUtils { /// <summary> /// Extracts a process ID from file lock error messages. /// </summary> /// <param name="error">The error message to parse.</param> /// <param name="processId">The extracted process ID, or -1 if not found.</param> /// <returns>True if a process ID was successfully extracted, false otherwise.</returns> public static bool ExtractProcessId(string error, out int processId) { processId = -1; if (string.IsNullOrWhiteSpace(error)) return false; try { // Define a regex pattern to match the process ID in file lock messages var pattern = @"The file is locked by: ""[^""]+ \((\d+)\)"""; var match = Regex.Match(error, pattern); return match.Success && int.TryParse(match.Groups[1].Value, out processId); } catch (RegexMatchTimeoutException) { // Handle regex timeout gracefully return false; } } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/IvanMurzak/Unity-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server