Skip to content

Commit d471673

Browse files
committed
Fix race condition causing 'No ExifTool available' error on first image (Issue #3)
1 parent cd9af08 commit d471673

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to the "Image Metadata Inspector" extension will be document
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.2] - 2025-11-17
9+
10+
### Fixed
11+
- Fixed race condition causing "No ExifTool available" error on the first image opened after VS Code reload (Issue #3)
12+
- Fixed cached error results preventing the first image from working even after reopening it
13+
- Improved async initialization handling to ensure ExifTool is ready before processing metadata requests
14+
15+
### Changed
16+
- Replaced boolean initialization flag with Promise-based state management for better async control
17+
- Enhanced initialization retry logic to properly clear errors after successful initialization
18+
819
## [0.1.1] - 2025-10-31
920

1021
### Fixed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/Gerkinfeltser/image-metadata-display.git"
88
},
9-
"version": "0.1.1",
9+
"version": "0.1.2",
1010
"publisher": "Gerkinfeltser",
1111
"icon": "images/image_metadata_viewer_icon.png",
1212
"license": "MIT",

src/extension.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,27 @@ async function showMetadata(fileUri: vscode.Uri, viewColumn: vscode.ViewColumn)
9999
class MetadataProvider implements vscode.TextDocumentContentProvider {
100100
private exifTool: any = null;
101101
private useNativeExifTool: boolean = false;
102-
private initializationAttempted: boolean = false;
102+
private initializationPromise: Promise<void> | null = null;
103103
private initializationError: string | null = null;
104104

105105
constructor() {
106-
this.initializeExifTool();
106+
// Start initialization but don't wait for it
107+
this.initializationPromise = this.initializeExifTool();
107108
}
108109

109110
private async initializeExifTool() {
110-
if (this.initializationAttempted) {
111+
if (this.exifTool || this.useNativeExifTool) {
112+
// Already initialized successfully
111113
return;
112114
}
113-
this.initializationAttempted = true;
114115

115116
outputChannel.appendLine('Attempting to initialize ExifTool...');
116117

117118
try {
118119
// Try to initialize with exiftool-vendored first
119120
const ExifTool = await loadExifToolClass();
120121
this.exifTool = new ExifTool();
122+
this.initializationError = null; // Clear any previous errors
121123
outputChannel.appendLine('ExifTool (vendored) initialized successfully');
122124
return;
123125
} catch (error) {
@@ -129,6 +131,7 @@ class MetadataProvider implements vscode.TextDocumentContentProvider {
129131
try {
130132
await execAsync('exiftool -ver');
131133
this.useNativeExifTool = true;
134+
this.initializationError = null; // Clear any previous errors
132135
outputChannel.appendLine('Native ExifTool found and will be used as fallback');
133136
return;
134137
} catch (nativeError) {
@@ -163,9 +166,9 @@ class MetadataProvider implements vscode.TextDocumentContentProvider {
163166
const fileUri = vscode.Uri.file(uri.path.replace('.metadata', ''));
164167
const fileName = fileUri.fsPath.split('\\').pop() || fileUri.fsPath.split('/').pop() || 'Unknown';
165168

166-
// Wait for initialization to complete if it's still ongoing
167-
if (!this.initializationAttempted) {
168-
await this.initializeExifTool();
169+
// Wait for initialization to complete
170+
if (this.initializationPromise) {
171+
await this.initializationPromise;
169172
}
170173

171174
const platformInfo = `Platform: ${os.platform()} ${os.arch()}\nNode.js: ${process.version}\nVS Code: ${vscode.version}`;

0 commit comments

Comments
 (0)