@smartnet360/svelte-components 0.0.123 → 0.0.124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -174,55 +174,125 @@ export async function parseMSIFile(file) {
174
174
  * @param directoryHandle - File system directory handle
175
175
  * @param recursive - Whether to process subdirectories
176
176
  * @param onProgress - Optional callback for progress updates
177
- * @returns Array of parsed antennas
177
+ * @returns Array of parsed antennas (for backward compatibility)
178
178
  */
179
179
  export async function parseFolder(directoryHandle, recursive = true, onProgress) {
180
+ const result = await parseFolderWithErrors(directoryHandle, recursive, onProgress);
181
+ return result.antennas;
182
+ }
183
+ /**
184
+ * Parse a folder of MSI files recursively with detailed error reporting
185
+ * @param directoryHandle - File system directory handle
186
+ * @param recursive - Whether to process subdirectories
187
+ * @param onProgress - Optional callback for progress updates
188
+ * @returns Object containing parsed antennas and any errors encountered
189
+ */
190
+ export async function parseFolderWithErrors(directoryHandle, recursive = true, onProgress) {
180
191
  const antennas = [];
192
+ const errors = [];
181
193
  let filesProcessed = 0;
182
194
  let directoriesScanned = 0;
195
+ let failedFiles = 0;
183
196
  // Process directory recursively
184
197
  async function processDirectory(dirHandle, path = '') {
185
198
  directoriesScanned++;
186
- const iterator = dirHandle.values();
187
- for await (const entry of iterator) {
188
- if (entry.kind === 'file') {
189
- try {
190
- // Type assertion to access getFile method
191
- const fileHandle = entry;
192
- const file = await fileHandle.getFile();
193
- const ext = file.name.split('.').pop()?.toLowerCase();
194
- if (ext === 'msi' || ext === 'pnt') {
195
- filesProcessed++;
196
- const currentPath = path ? `${path}/${file.name}` : file.name;
197
- // Report progress
198
- onProgress?.({
199
- currentFile: currentPath,
200
- filesProcessed,
201
- directoriesScanned,
202
- antennaFilesFound: antennas.length
203
- });
204
- try {
205
- const antenna = await parseMSIFile(file);
206
- // Add the path info to help identify where the file was found
207
- antenna.sourcePath = currentPath;
208
- antennas.push(antenna);
209
- }
210
- catch (error) {
211
- console.error(`Error parsing file ${currentPath}:`, error);
199
+ let iterator;
200
+ try {
201
+ iterator = dirHandle.values();
202
+ }
203
+ catch (error) {
204
+ const dirPath = path || dirHandle.name;
205
+ errors.push({
206
+ path: dirPath,
207
+ message: error instanceof Error ? error.message : 'Failed to read directory',
208
+ type: 'folder'
209
+ });
210
+ console.error(`Error reading directory ${dirPath}:`, error);
211
+ return; // Skip this directory but continue with others
212
+ }
213
+ try {
214
+ for await (const entry of iterator) {
215
+ if (entry.kind === 'file') {
216
+ try {
217
+ // Type assertion to access getFile method
218
+ const fileHandle = entry;
219
+ const file = await fileHandle.getFile();
220
+ const ext = file.name.split('.').pop()?.toLowerCase();
221
+ if (ext === 'msi' || ext === 'pnt') {
222
+ filesProcessed++;
223
+ const currentPath = path ? `${path}/${file.name}` : file.name;
224
+ // Report progress
225
+ onProgress?.({
226
+ currentFile: currentPath,
227
+ filesProcessed,
228
+ directoriesScanned,
229
+ antennaFilesFound: antennas.length,
230
+ failedFiles
231
+ });
232
+ try {
233
+ const antenna = await parseMSIFile(file);
234
+ // Add the path info to help identify where the file was found
235
+ antenna.sourcePath = currentPath;
236
+ antennas.push(antenna);
237
+ }
238
+ catch (parseError) {
239
+ failedFiles++;
240
+ errors.push({
241
+ path: currentPath,
242
+ message: parseError instanceof Error ? parseError.message : 'Failed to parse file',
243
+ type: 'file'
244
+ });
245
+ console.error(`Error parsing file ${currentPath}:`, parseError);
246
+ // Continue with next file
247
+ }
212
248
  }
213
249
  }
250
+ catch (fileError) {
251
+ const filePath = path ? `${path}/${entry.name}` : entry.name;
252
+ failedFiles++;
253
+ errors.push({
254
+ path: filePath,
255
+ message: fileError instanceof Error ? fileError.message : 'Failed to access file',
256
+ type: 'file'
257
+ });
258
+ console.error(`Error accessing file ${filePath}:`, fileError);
259
+ // Continue with next file
260
+ }
214
261
  }
215
- catch (error) {
216
- console.error('Error accessing file:', error);
262
+ else if (entry.kind === 'directory' && recursive) {
263
+ // Process subdirectory if recursive flag is true
264
+ const subDirPath = path ? `${path}/${entry.name}` : entry.name;
265
+ try {
266
+ await processDirectory(entry, subDirPath);
267
+ }
268
+ catch (subDirError) {
269
+ errors.push({
270
+ path: subDirPath,
271
+ message: subDirError instanceof Error ? subDirError.message : 'Failed to process subdirectory',
272
+ type: 'folder'
273
+ });
274
+ console.error(`Error processing subdirectory ${subDirPath}:`, subDirError);
275
+ // Continue with next entry
276
+ }
217
277
  }
218
278
  }
219
- else if (entry.kind === 'directory' && recursive) {
220
- // Process subdirectory if recursive flag is true
221
- const subDirPath = path ? `${path}/${entry.name}` : entry.name;
222
- await processDirectory(entry, subDirPath);
223
- }
279
+ }
280
+ catch (iterError) {
281
+ const dirPath = path || dirHandle.name;
282
+ errors.push({
283
+ path: dirPath,
284
+ message: iterError instanceof Error ? iterError.message : 'Error iterating directory contents',
285
+ type: 'folder'
286
+ });
287
+ console.error(`Error iterating directory ${dirPath}:`, iterError);
288
+ // Continue - the directory iteration failed but we can still return what we have
224
289
  }
225
290
  }
226
291
  await processDirectory(directoryHandle);
227
- return antennas;
292
+ return {
293
+ antennas,
294
+ errors,
295
+ totalFilesAttempted: filesProcessed,
296
+ totalDirectoriesScanned: directoriesScanned
297
+ };
228
298
  }