-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor/try catch #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…leInfo to improve error handling
Refactor getAppsFileInfo to improve error handling and update fallback logic; add test for mdls failure fallback to plutil
…n, appCreatedDate, appIdentifier only not all the properties in the Info.Plist
…l, no changes made for mdls as spawnsync is used by default by the package
SaadBazaz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix these problems, quite unoptimized right now. But promising. No worries about the format change, I see that's a recurring problem in this code.
src/mac.ts
Outdated
| for (const app of appsFile) { | ||
| try { | ||
| const result = await new Promise<any>((resolve) => { | ||
| const runPlutilShell = spawn("plutil", ["-p", `${app}/Contents/Info.plist`]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not actually running in parallel; it's still just calling a for loop and just awaiting each call. Same thing as before.
Try creating separate spawns in parallel.
Here's a prompt which might help you:
You're a senior software engineer experienced in parallel computing and optimization.
Turn this block of code into a parallel call; each spawn should be saved into a list, and use Promise.all to resolve them all together (of course, don't crash upon fail. Just keep going).
src/mac.ts
Outdated
| } catch (error) { | ||
| // Fallback to plutil for all apps if mdls fails | ||
| for (const app of appsFile) { | ||
| try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this try catch in the iteration itself, do it once on the entire loop. If something in the loop fails, throw an error and catch it, then in the catch, try the fallback.
SaadBazaz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your formattings are very verbose. And don't return the full data.
src/mac.ts
Outdated
| } | ||
| } | ||
|
|
||
| resolve({ appName, appVersion, appInstallDate: "", appIdentifier }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also return all the other data...
2) used promised for Asynchronous Flow 3) returning all data for plutil
…ng for plutil data parsing
What was the issue
How you solved it
- Added plutil as a fallback mechanism that:
Problems within it