( registryPath: string, expectedWorkspaceKey?: string, )
| 115 | | { status: 'valid'; entry: DaemonRegistryEntry }; |
| 116 | |
| 117 | function readRegistryEntryAtPath( |
| 118 | registryPath: string, |
| 119 | expectedWorkspaceKey?: string, |
| 120 | ): RegistryReadResult { |
| 121 | let content: string; |
| 122 | try { |
| 123 | content = readFileSync(registryPath, 'utf8'); |
| 124 | } catch (error) { |
| 125 | if ((error as NodeJS.ErrnoException).code === 'ENOENT') { |
| 126 | return { status: 'missing' }; |
| 127 | } |
| 128 | return { status: 'invalid' }; |
| 129 | } |
| 130 | |
| 131 | try { |
| 132 | const parsed = JSON.parse(content) as unknown; |
| 133 | if (!isDaemonRegistryEntry(parsed)) { |
| 134 | return { status: 'invalid' }; |
| 135 | } |
| 136 | if (expectedWorkspaceKey !== undefined && parsed.workspaceKey !== expectedWorkspaceKey) { |
| 137 | return { status: 'invalid' }; |
| 138 | } |
| 139 | return { status: 'valid', entry: parsed }; |
| 140 | } catch { |
| 141 | return { status: 'invalid' }; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | function readValidRegistryEntryAtPath( |
| 146 | registryPath: string, |
no test coverage detected