Skip to content

Commit 50c1984

Browse files
authored
fix: fixed exception and added loggin when eim.json is missing (#1270)
1 parent 01b41c2 commit 50c1984

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.espressif.idf.core.tools;
22

3+
import java.io.File;
34
import java.io.FileReader;
45
import java.io.IOException;
56

67
import org.eclipse.core.runtime.Platform;
78

9+
import com.espressif.idf.core.logging.Logger;
810
import com.espressif.idf.core.tools.vo.EimJson;
911
import com.google.gson.Gson;
1012
import com.google.gson.GsonBuilder;
@@ -13,35 +15,43 @@ public class EimIdfConfiguratinParser
1315
{
1416
private EimJson eimJson;
1517
private Gson gson;
16-
18+
1719
public EimIdfConfiguratinParser()
1820
{
1921
gson = new GsonBuilder().setPrettyPrinting().enableComplexMapKeySerialization()
2022
.excludeFieldsWithoutExposeAnnotation().create();
2123
}
22-
24+
2325
private void load() throws IOException
2426
{
25-
try (FileReader fileReader = new FileReader(
26-
Platform.getOS().equals(Platform.OS_WIN32) ? EimConstants.EIM_WIN_PATH : EimConstants.EIM_POSIX_PATH))
27+
String path = Platform.getOS().equals(Platform.OS_WIN32) ? EimConstants.EIM_WIN_PATH
28+
: EimConstants.EIM_POSIX_PATH;
29+
30+
File file = new File(path);
31+
if (!file.exists())
32+
{
33+
Logger.log("EIM config file not found: " + path); //$NON-NLS-1$
34+
return;
35+
}
36+
37+
try (FileReader fileReader = new FileReader(file))
2738
{
2839
eimJson = gson.fromJson(fileReader, EimJson.class);
2940
}
3041
}
3142

32-
3343
public EimJson getEimJson(boolean reload) throws IOException
3444
{
3545
if (reload)
3646
{
3747
load();
3848
}
39-
49+
4050
if (eimJson == null)
4151
{
4252
load();
4353
}
44-
54+
4555
return eimJson;
4656
}
4757
}

0 commit comments

Comments
 (0)