-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Fix to lastLoadedProject
being null
#830
Conversation
Important Auto Review SkippedReview was skipped due to path filters Files ignored due to path filters (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
apps/server/src/setup/index.ts
Outdated
if (!appState.lastLoadedProject) { | ||
throw new Error('No last loaded project'); | ||
} |
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.
if we are throwing inside a try-catch, it seems like we could just be checking for it instead?
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.
that's because we want to execute the code that is inside the catch
block when it happens, I mean I could extract it to a function and call it here
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.
if (!appState.lastLoadedProject) { | |
throw new Error('No last loaded project'); | |
} | |
async function ensureAppState() { | |
try { | |
await fs.access(appStatePath); | |
} catch { | |
if (!isTest) { | |
await ensureDirectory(getAppDataPath()); | |
await fs.writeFile(appStatePath, JSON.stringify({ lastLoadedProject: 'db.json' })); | |
} | |
if (!appState.lastLoadedProject) { | |
throw new Error('No last loaded project'); | |
} | |
} | |
} | |
async function getLastLoadedProject() { | |
await ensureAppState(); | |
const appState = JSON.parse(await fs.readFile(appStatePath, 'utf8')); | |
return appState.lastLoadedProject || 'db.json'; | |
} |
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.
should we not keep things synchronous here? otherwise when we use getLastLoadedProject
here:
const lastLoadedProject = isTest ? 'db.json' : getLastLoadedProject();
well I think node now supports top level await
? If so then its fine
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.
I didnt really test the code, was just a quick proposal
does getLastLoadedProject
happen in runtime or just start up, the answer to whether it should async is there
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.
it's on startup, so I extracted the functionality into a function and we call it if it doesnt exist
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.
👍
by throwing an exception there we ensure the code inside the
catch
block runs, which will then create and assign alastLoadedProject