Skip to content

Commit e1d923d

Browse files
fix: local workspaces fetch (#150)
1 parent d292f71 commit e1d923d

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

src/renderer/actions/local-sync/fs-utils.ts

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -500,44 +500,55 @@ export async function migrateGlobalConfig(oldConfig: any) {
500500
export async function getAllWorkspaces(): Promise<
501501
FileSystemResult<Static<typeof GlobalConfig>["workspaces"]>
502502
> {
503-
const globalConfigFileResource = createFsResource({
504-
rootPath: GLOBAL_CONFIG_FOLDER_PATH,
505-
path: appendPath(GLOBAL_CONFIG_FOLDER_PATH, GLOBAL_CONFIG_FILE_NAME),
506-
type: "file",
507-
});
503+
try {
504+
const globalConfigFileResource = createFsResource({
505+
rootPath: GLOBAL_CONFIG_FOLDER_PATH,
506+
path: appendPath(GLOBAL_CONFIG_FOLDER_PATH, GLOBAL_CONFIG_FILE_NAME),
507+
type: "file",
508+
});
508509

509-
const readResult = await parseFileRaw({
510-
resource: globalConfigFileResource,
511-
});
510+
const readResult = await parseFileRaw({
511+
resource: globalConfigFileResource,
512+
});
512513

513-
if (readResult.type === "error") {
514-
return readResult;
515-
}
514+
if (readResult.type === "error") {
515+
return readResult;
516+
}
516517

517-
const { content } = readResult;
518-
const parsedContent = JSON.parse(content);
519-
// @ts-ignore
520-
if (parsedContent.version !== CORE_CONFIG_FILE_VERSION) {
521-
const migratedConfig = await migrateGlobalConfig(parsedContent);
522-
const writeResult = await writeContent(
523-
globalConfigFileResource,
524-
migratedConfig,
525-
new GlobalConfigRecordFileType()
526-
);
527-
if (writeResult.type === "error") {
528-
return writeResult;
518+
const { content } = readResult;
519+
const parsedContent: Static<typeof GlobalConfig> = JSON.parse(content);
520+
521+
if (parsedContent.version !== CORE_CONFIG_FILE_VERSION) {
522+
const migratedConfig = await migrateGlobalConfig(parsedContent);
523+
const writeResult = await writeContent(
524+
globalConfigFileResource,
525+
migratedConfig,
526+
new GlobalConfigRecordFileType()
527+
);
528+
if (writeResult.type === "error") {
529+
return writeResult;
530+
}
531+
532+
return {
533+
type: "success",
534+
content: migratedConfig.workspaces,
535+
};
529536
}
530537

531538
return {
532539
type: "success",
533-
content: migratedConfig.workspaces,
540+
content: parsedContent.workspaces,
541+
};
542+
} catch (error: any) {
543+
return {
544+
type: "error",
545+
error: {
546+
message: error.message || "An unexpected error has occurred!",
547+
path: GLOBAL_CONFIG_FOLDER_PATH,
548+
fileType: FileTypeEnum.GLOBAL_CONFIG,
549+
},
534550
};
535551
}
536-
537-
// @ts-ignore
538-
return readResult.content.workspaces as FileSystemResult<
539-
Static<typeof GlobalConfig>["workspaces"]
540-
>;
541552
}
542553

543554
export function getParentFolderPath(fsResource: FsResource) {

0 commit comments

Comments
 (0)